Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren committed Apr 5, 2024
1 parent 925d4c2 commit a1652d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
25 changes: 1 addition & 24 deletions frontend/packages/process-editor/src/ProcessEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { RouterProvider, createMemoryRouter } from 'react-router-dom';
const mockBPMNXML: string = `<?xml version="1.0" encoding="UTF-8"?></xml>`;

const mockAppLibVersion8: string = '8.0.3';
const mockAppLibVersion7: string = '7.0.3';

const mockSaveBpmn = jest.fn();

Expand Down Expand Up @@ -41,7 +40,7 @@ describe('ProcessEditor', () => {
beforeEach(jest.clearAllMocks);
it('should render loading while bpmnXml is undefined', () => {
renderProcessEditor({ bpmnXml: undefined });
expect(screen.getByTitle(textMock('process_editor.loading'))).toBeInTheDocument();
expect(screen.getByText(textMock('process_editor.loading'))).toBeInTheDocument();
});

it('should render "NoBpmnFoundAlert" when bpmnXml is null', () => {
Expand All @@ -54,17 +53,6 @@ describe('ProcessEditor', () => {
).toBeInTheDocument();
});

it('should render "canvas" when bpmnXml is provided and default render is edit-mode', async () => {
// eslint-disable-next-line testing-library/no-unnecessary-act
await act(() => {
renderProcessEditor();
});

expect(
screen.getByRole('button', { name: textMock('process_editor.save') }),
).toBeInTheDocument();
});

it('does not display the information about too old version when the version is 8 or newer', async () => {
const user = userEvent.setup();
renderProcessEditor();
Expand All @@ -78,15 +66,4 @@ describe('ProcessEditor', () => {
});
expect(alertHeader).not.toBeInTheDocument();
});

it('displays the alert when the version is 7 or older', async () => {
const user = userEvent.setup();
renderProcessEditor({ appLibVersion: mockAppLibVersion7 });

// Fix to remove act error
await act(() => user.tab());

const tooOldText = screen.getByText(textMock('process_editor.too_old_version_title'));
expect(tooOldText).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Canvas } from './Canvas';
import { type BpmnContextProviderProps, useBpmnContext } from '../../contexts/BpmnContext';
import { BpmnContextProvider } from '../../contexts/BpmnContext';
import { RouterProvider, createMemoryRouter } from 'react-router-dom';
import { textMock } from '../../../../../testing/mocks/i18nMock';

jest.mock('../../contexts/BpmnContext', () => ({
...jest.requireActual('../../contexts/BpmnContext'),
Expand Down Expand Up @@ -58,4 +59,12 @@ describe('Canvas', () => {
renderCanvas({ appLibVersion: mockAppLibVersion8 });
screen.queryByTestId('bpmn-editor');
});
it('displays the alert when the version is 7 or older', async () => {
(useBpmnContext as jest.Mock).mockReturnValue({
...jest.requireActual('../../contexts/BpmnContext'),
});
renderCanvas({ appLibVersion: mockAppLibVersion7 });
const tooOldText = screen.getByText(textMock('process_editor.too_old_version_title'));
expect(tooOldText).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import classes from './Canvas.module.css';
import { useBpmnContext } from '../../contexts/BpmnContext';
import { BPMNViewer } from './BPMNViewer';
import { BPMNEditor } from './BPMNEditor';
import { VersionHelpText } from './VersionHelpText';

export const Canvas = (): React.ReactElement => {
const { isEditAllowed } = useBpmnContext();

return <div className={classes.wrapper}>{isEditAllowed ? <BPMNEditor /> : <BPMNViewer />}</div>;
return (
<>
{!isEditAllowed && <VersionHelpText />}
<div className={classes.wrapper}>{isEditAllowed ? <BPMNEditor /> : <BPMNViewer />}</div>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('EditTaskId', () => {
it('should not update id if new id is the same as the old id', async () => {
const user = userEvent.setup();
(useBpmnConfigPanelFormContext as jest.Mock).mockReturnValue({
metaDataFormRef: metaDataFormRefMock,
metaDataFormRef: { current: undefined },
});

render(<EditTaskId />);
Expand Down

0 comments on commit a1652d7

Please sign in to comment.