-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/11500 app lib version (#11673)
* implementing app-lib-version * adding todo * adding alert text * refactor to new file * refactoring canvas to separate files and adding tests * fix typecheck * fixing feedback from PR
- Loading branch information
WilliamThorenfeldt
authored
Nov 28, 2023
1 parent
5a9c9d4
commit 81111b8
Showing
37 changed files
with
630 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
frontend/app-development/hooks/queries/useAppLibVersionQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { getAppLibVersion } from 'app-shared/api/queries'; | ||
import { QueryKey } from 'app-shared/types/QueryKey'; | ||
|
||
/** | ||
* Query to get the app-lib version. | ||
* | ||
* @param org the organisation of the user | ||
* @param repo the repo the user is in | ||
* | ||
* @returns UseQueryResult with the version | ||
*/ | ||
export const useAppLibVersionQuery = (org: string, repo: string) => { | ||
return useQuery<{ version: string }>({ | ||
queryKey: [QueryKey.AppLibVersion, org, repo], | ||
queryFn: () => getAppLibVersion(org, repo), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 53 additions & 9 deletions
62
frontend/packages/process-editor/src/ProcessEditor.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,76 @@ | ||
import React from 'react'; | ||
import { render, screen, act } from '@testing-library/react'; | ||
import { ProcessEditor } from './ProcessEditor'; | ||
import { render, screen, act } from '@testing-library/react'; | ||
import { ProcessEditor, ProcessEditorProps } from './ProcessEditor'; | ||
import { textMock } from '../../../testing/mocks/i18nMock'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
const mockBPMNXML: string = `<?xml version="1.0" encoding="UTF-8"?></xml>`; | ||
|
||
const mockAppLibVersion8: string = '8.0.3'; | ||
const mockAppLibVersion7: string = '7.0.3'; | ||
|
||
const mockOnSave = jest.fn(); | ||
|
||
describe('ProcessEditor', () => { | ||
afterEach(jest.clearAllMocks); | ||
|
||
const defaultProps: ProcessEditorProps = { | ||
bpmnXml: mockBPMNXML, | ||
onSave: mockOnSave, | ||
appLibVersion: mockAppLibVersion8, | ||
}; | ||
|
||
it('should render loading while bpmnXml is undefined', () => { | ||
render(<ProcessEditor bpmnXml={undefined} onSave={() => {}} />); | ||
render(<ProcessEditor {...defaultProps} bpmnXml={undefined} />); | ||
expect(screen.getByTitle(textMock('process_editor.loading'))).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render "NoBpmnFoundAlert" when bpmnXml is null', () => { | ||
render(<ProcessEditor bpmnXml={null} onSave={() => {}} />); | ||
render(<ProcessEditor {...defaultProps} bpmnXml={null} />); | ||
expect( | ||
screen.getByRole('heading', { | ||
name: textMock('process_editor.fetch_bpmn_error_title'), | ||
level: 2, | ||
}) | ||
}), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render "canvas" when bpmnXml is provided and default render is view-mode', async () => { | ||
// eslint-disable-next-line testing-library/no-unnecessary-act | ||
await act(() => { | ||
render(<ProcessEditor bpmnXml={`<?xml version="1.0" encoding="UTF-8"?></xml>`} onSave={() => { } } />); | ||
}) | ||
await act(() => { | ||
render(<ProcessEditor {...defaultProps} />); | ||
}); | ||
|
||
expect( | ||
screen.getByRole('button', { name: textMock('process_editor.edit_mode') }) | ||
screen.getByRole('button', { name: textMock('process_editor.edit_mode') }), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not display the alert when the version is 8 or newer', async () => { | ||
const user = userEvent.setup(); | ||
render(<ProcessEditor {...defaultProps} />); | ||
|
||
// Fix to remove act error | ||
await act(() => user.tab()); | ||
|
||
const alertHeader = screen.queryByRole('heading', { | ||
name: textMock('process_editor.too_old_version_title'), | ||
level: 1, | ||
}); | ||
expect(alertHeader).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('displays the alert when the version is 7 or older', async () => { | ||
const user = userEvent.setup(); | ||
render(<ProcessEditor {...defaultProps} appLibVersion={mockAppLibVersion7} />); | ||
|
||
// Fix to remove act error | ||
await act(() => user.tab()); | ||
|
||
const alertHeader = screen.getByRole('heading', { | ||
name: textMock('process_editor.too_old_version_title'), | ||
level: 1, | ||
}); | ||
expect(alertHeader).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
frontend/packages/process-editor/src/components/Canvas/BPMNEditor/BPMNEditor.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.editorContainer { | ||
display: flex; | ||
flex: 1; | ||
border: 1px solid var(--fds-semantic-border-neutral-default); | ||
margin-inline: 18px; | ||
margin-bottom: 18px; | ||
} |
14 changes: 14 additions & 0 deletions
14
frontend/packages/process-editor/src/components/Canvas/BPMNEditor/BPMNEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { ReactNode } from 'react'; | ||
import classes from './BPMNEditor.module.css'; | ||
import { useBpmnEditor } from '../../../hooks/useBpmnEditor'; | ||
|
||
/** | ||
* @component | ||
* Displays the editor canvas in the ProcessEditor | ||
* | ||
* @returns {ReactNode} - The rendered component | ||
*/ | ||
export const BPMNEditor = (): ReactNode => { | ||
const { canvasRef } = useBpmnEditor(); | ||
return <div className={classes.editorContainer} ref={canvasRef}></div>; | ||
}; |
1 change: 1 addition & 0 deletions
1
frontend/packages/process-editor/src/components/Canvas/BPMNEditor/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { BPMNEditor } from './BPMNEditor'; |
14 changes: 14 additions & 0 deletions
14
frontend/packages/process-editor/src/components/Canvas/BPMNViewer/BPMNViewer.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.viewerWrapper { | ||
width: 100%; | ||
display: flex; | ||
gap: 1rem; | ||
} | ||
|
||
.canvasContainer { | ||
display: flex; | ||
gap: 1rem; | ||
width: 100%; | ||
border: 1px solid var(--fds-semantic-border-neutral-default); | ||
margin-inline: 18px; | ||
margin-bottom: 18px; | ||
} |
44 changes: 44 additions & 0 deletions
44
frontend/packages/process-editor/src/components/Canvas/BPMNViewer/BPMNViewer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import { render, screen, act } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { BPMNViewer, BPMNViewerProps } from './BPMNViewer'; | ||
import { textMock } from '../../../../../../testing/mocks/i18nMock'; | ||
|
||
const mockAppLibVersion8: string = '8.0.1'; | ||
const mockAppLibVersion7: string = '7.0.1'; | ||
|
||
const defaultProps: BPMNViewerProps = { | ||
appLibVersion: mockAppLibVersion8, | ||
}; | ||
|
||
describe('Viewer', () => { | ||
afterEach(jest.clearAllMocks); | ||
|
||
it('displays version alert when version is 7 or older', async () => { | ||
const user = userEvent.setup(); | ||
render(<BPMNViewer {...defaultProps} appLibVersion={mockAppLibVersion7} />); | ||
|
||
// Fix to remove act error | ||
await act(() => user.tab()); | ||
|
||
const alertTitle = screen.getByRole('heading', { | ||
name: textMock('process_editor.too_old_version_title'), | ||
level: 1, | ||
}); | ||
expect(alertTitle).toBeInTheDocument; | ||
}); | ||
|
||
it('hides version alert when version is 8 or newer', async () => { | ||
const user = userEvent.setup(); | ||
render(<BPMNViewer {...defaultProps} />); | ||
|
||
// Fix to remove act error | ||
await act(() => user.tab()); | ||
|
||
const alertTitle = screen.queryByRole('heading', { | ||
name: textMock('process_editor.too_old_version_title'), | ||
level: 1, | ||
}); | ||
expect(alertTitle).not.toBeInTheDocument; | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
frontend/packages/process-editor/src/components/Canvas/BPMNViewer/BPMNViewer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React, { ReactNode } from 'react'; | ||
import classes from './BPMNViewer.module.css'; | ||
import { useBpmnViewer } from '../../../hooks/useBpmnViewer'; | ||
import { VersionAlert } from './VersionAlert'; | ||
import { BPMNViewerErrorAlert } from './BPMNViewerErrorAlert'; | ||
import { supportsProcessEditor } from '../../../utils/processEditorUtils'; | ||
|
||
export type BPMNViewerProps = { | ||
appLibVersion: string; | ||
}; | ||
|
||
/** | ||
* @component | ||
* Displays the canvas area of the ProcessEditor | ||
* | ||
* @property {string}[appLibVersion] - The app-lib version the user has | ||
* | ||
* @returns {ReactNode} - The rendered component | ||
*/ | ||
export const BPMNViewer = ({ appLibVersion }: BPMNViewerProps): ReactNode => { | ||
const { canvasRef, bpmnViewerError } = useBpmnViewer(); | ||
|
||
const isEditAllowed: boolean = supportsProcessEditor(appLibVersion); | ||
|
||
return ( | ||
<> | ||
{bpmnViewerError !== undefined && <BPMNViewerErrorAlert bpmnViewerError={bpmnViewerError} />} | ||
<div className={classes.viewerWrapper}> | ||
<div className={classes.canvasContainer} ref={canvasRef}></div> | ||
{!isEditAllowed && <VersionAlert appLibVersion={appLibVersion} />} | ||
</div> | ||
</> | ||
); | ||
}; |
5 changes: 5 additions & 0 deletions
5
...tor/src/components/Canvas/BPMNViewer/BPMNViewerErrorAlert/BPMNViewerErrorAlert.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.alertContainer { | ||
padding: 18px; | ||
box-sizing: border-box; | ||
max-width: 780px; | ||
} |
57 changes: 57 additions & 0 deletions
57
...ditor/src/components/Canvas/BPMNViewer/BPMNViewerErrorAlert/BPMNViewerErrorAlert.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react'; | ||
import { render, screen, act } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { BPMNViewerErrorAlert } from './BPMNViewerErrorAlert'; | ||
import { textMock } from '../../../../../../../testing/mocks/i18nMock'; | ||
|
||
describe('Viewer', () => { | ||
afterEach(jest.clearAllMocks); | ||
|
||
it('displays correct error message when bpmnViewerError is "noDiagram"', async () => { | ||
const user = userEvent.setup(); | ||
render(<BPMNViewerErrorAlert bpmnViewerError='noDiagram' />); | ||
|
||
// Fix to remove act error | ||
await act(() => user.tab()); | ||
|
||
const heading = screen.getByRole('heading', { | ||
name: textMock('process_editor.not_found_diagram_heading'), | ||
}); | ||
const paragraph = screen.getByText(textMock('process_editor.not_found_diagram_error_message')); | ||
|
||
expect(heading).toBeInTheDocument(); | ||
expect(paragraph).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays correct error message when bpmnViewerError is "noProcess"', async () => { | ||
const user = userEvent.setup(); | ||
render(<BPMNViewerErrorAlert bpmnViewerError='noProcess' />); | ||
|
||
// Fix to remove act error | ||
await act(() => user.tab()); | ||
|
||
const heading = screen.getByRole('heading', { | ||
name: textMock('process_editor.not_found_process_heading'), | ||
}); | ||
const paragraph = screen.getByText(textMock('process_editor.not_found_process_error_message')); | ||
|
||
expect(heading).toBeInTheDocument(); | ||
expect(paragraph).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays correct error message when bpmnViewerError is "unknown"', async () => { | ||
const user = userEvent.setup(); | ||
render(<BPMNViewerErrorAlert bpmnViewerError='unknown' />); | ||
|
||
// Fix to remove act error | ||
await act(() => user.tab()); | ||
|
||
const heading = screen.getByRole('heading', { | ||
name: textMock('process_editor.unknown_heading_error_message'), | ||
}); | ||
const paragraph = screen.getByText(textMock('process_editor.unknown_paragraph_error_message')); | ||
|
||
expect(heading).toBeInTheDocument(); | ||
expect(paragraph).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.