2022-12-22 17:18:34 +01:00
|
|
|
import { InvoicesSettingsPanel } from '../../../../app/frontend/src/javascript/components/invoices/invoices-settings-panel';
|
|
|
|
import { render, fireEvent, waitFor, screen } from '@testing-library/react';
|
|
|
|
import '@testing-library/jest-dom';
|
2022-12-23 15:52:10 +01:00
|
|
|
import { uiRouter } from '../../__lib__/ui-router';
|
2022-12-22 17:18:34 +01:00
|
|
|
|
|
|
|
describe('InvoicesSettingsPanel', () => {
|
|
|
|
const onError = jest.fn();
|
|
|
|
const onSuccess = jest.fn();
|
|
|
|
|
|
|
|
test('render InvoicesSettingsPanel', async () => {
|
2022-12-23 15:52:10 +01:00
|
|
|
render(<InvoicesSettingsPanel onError={onError} onSuccess={onSuccess} uiRouter={uiRouter} />);
|
2022-12-22 17:18:34 +01:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.getByLabelText(/app.admin.invoices_settings_panel.disable_invoices_zero_label/)).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
expect(screen.getAllByLabelText(/app.admin.invoices_settings_panel.prefix/)).toHaveLength(2);
|
|
|
|
expect(screen.getByRole('heading', { name: /app.admin.invoices_settings_panel.filename/ })).toBeInTheDocument();
|
|
|
|
expect(screen.getByRole('heading', { name: /app.admin.invoices_settings_panel.schedule_filename/ })).toBeInTheDocument();
|
|
|
|
expect(screen.getByRole('button', { name: /app.admin.invoices_settings_panel.save/ })).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('update filename example', async () => {
|
2022-12-23 15:52:10 +01:00
|
|
|
render(<InvoicesSettingsPanel onError={onError} onSuccess={onSuccess} uiRouter={uiRouter} />);
|
2022-12-22 17:18:34 +01:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.getAllByLabelText(/app.admin.invoices_settings_panel.prefix/)).toHaveLength(2);
|
|
|
|
});
|
|
|
|
fireEvent.change(screen.getByLabelText(/app.admin.invoices_settings_panel.prefix/, { selector: 'input#invoice_prefix' }), { target: { value: 'Test Example' } });
|
|
|
|
expect(screen.getByRole('heading', { name: /app.admin.invoices_settings_panel.filename/ }).parentNode.querySelector('.example > .content'))
|
|
|
|
.toHaveTextContent(/^Test Example/);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('update schedule filename example', async () => {
|
2022-12-23 15:52:10 +01:00
|
|
|
render(<InvoicesSettingsPanel onError={onError} onSuccess={onSuccess} uiRouter={uiRouter} />);
|
2022-12-22 17:18:34 +01:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.getAllByLabelText(/app.admin.invoices_settings_panel.prefix/)).toHaveLength(2);
|
|
|
|
});
|
|
|
|
fireEvent.change(screen.getByLabelText(/app.admin.invoices_settings_panel.prefix/, { selector: 'input#payment_schedule_prefix' }), { target: { value: 'Schedule Test' } });
|
|
|
|
expect(screen.getByRole('heading', { name: /app.admin.invoices_settings_panel.schedule_filename/ }).parentNode.querySelector('.example > .content'))
|
|
|
|
.toHaveTextContent(/^Schedule Test/);
|
|
|
|
});
|
|
|
|
});
|