mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(test) AdvancedAccountingForm
This commit is contained in:
parent
0287665653
commit
84dfcf38c7
@ -6,7 +6,7 @@ import planCategories from '../__fixtures__/plan_categories';
|
||||
import { partners } from '../__fixtures__/users';
|
||||
import { settings } from '../__fixtures__/settings';
|
||||
|
||||
const server = setupServer(
|
||||
export const server = setupServer(
|
||||
rest.get('/api/groups', (req, res, ctx) => {
|
||||
return res(ctx.json(groups));
|
||||
}),
|
||||
@ -30,11 +30,13 @@ const server = setupServer(
|
||||
/* eslint-enable camelcase */
|
||||
}),
|
||||
rest.get('/api/settings/:name', (req, res, ctx) => {
|
||||
return res(ctx.json(settings.find(s => s.name === req.params.name)));
|
||||
const setting = settings.find(s => s.name === req.params.name);
|
||||
return res(ctx.json({ setting }));
|
||||
}),
|
||||
rest.get('/api/settings', (req, res, ctx) => {
|
||||
const { names } = req.params;
|
||||
return res(ctx.json(settings.filter(name => names.replace(/[[\]']/g, '').split(',').includes(name))));
|
||||
const foundSettings = settings.filter(name => names.replace(/[[\]']/g, '').split(',').includes(name));
|
||||
return res(ctx.json(foundSettings));
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -0,0 +1,42 @@
|
||||
import React from 'react';
|
||||
import { AdvancedAccountingForm } from 'components/accounting/advanced-accounting-form';
|
||||
import { render, waitFor, screen } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
import { server as apiServer } from '../../__setup__/server';
|
||||
|
||||
describe('AdvancedAccountingForm', () => {
|
||||
const register = jest.fn();
|
||||
const onError = jest.fn();
|
||||
|
||||
test('render AdvancedAccountingForm', async () => {
|
||||
render(<AdvancedAccountingForm register={register} onError={onError} />);
|
||||
await waitFor(() => screen.getByRole('heading', { name: /app.admin.advanced_accounting_form.title/ }));
|
||||
// advanced accounting is enabled in fixtures
|
||||
expect(screen.getByLabelText(/app.admin.advanced_accounting_form.code/)).toBeInTheDocument();
|
||||
expect(screen.getByLabelText(/app.admin.advanced_accounting_form.analytical_section/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('render AdvancedAccountingForm when disabled', async () => {
|
||||
// set up a custom API answer for this test
|
||||
apiServer.close();
|
||||
const server = setupServer(
|
||||
rest.get('/api/settings/advanced_accounting', (req, res, ctx) => {
|
||||
return res(ctx.json({ setting: { name: 'advanced_accounting', value: 'false' } }));
|
||||
})
|
||||
);
|
||||
server.listen();
|
||||
|
||||
// run the test
|
||||
render(<AdvancedAccountingForm register={register} onError={onError} />);
|
||||
await waitFor(() => document.querySelector('.advanced-accounting-form'));
|
||||
// advanced accounting is enabled in fixtures
|
||||
expect(screen.queryByLabelText(/app.admin.advanced_accounting_form.code/)).toBeNull();
|
||||
expect(screen.queryByLabelText(/app.admin.advanced_accounting_form.analytical_section/)).toBeNull();
|
||||
|
||||
// remove the custom API
|
||||
server.resetHandlers();
|
||||
server.close();
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user