-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: migrate family menu * fix: remove unused import * feat: migrate main view component * fix: solve sonar issue
- Loading branch information
1 parent
f180ba8
commit beba2ee
Showing
6 changed files
with
97 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
type PageTitleBlockTypes = { | ||
titleLg1: string; | ||
titleLg1?: string; | ||
titleLg2?: string; | ||
secondLang?: boolean; | ||
}; | ||
|
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,8 @@ | ||
import { ValidationState } from '../../components'; | ||
|
||
export type Family = { | ||
id: string; | ||
prefLabelLg1?: string; | ||
prefLabelLg2?: string; | ||
validationState: ValidationState; | ||
}; |
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
31 changes: 31 additions & 0 deletions
31
src/packages/modules-operations/families/visualization/menu.spec.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,31 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { Menu } from './menu'; | ||
import { RBACMock } from '../../../tests-utils/rbac'; | ||
import { ADMIN } from '../../../auth/roles'; | ||
import { Family } from '../../../model/operations/family'; | ||
|
||
describe('Family Home Page Menu', () => { | ||
it('an admin can update and publish a family', () => { | ||
render( | ||
<RBACMock roles={[ADMIN]}> | ||
<Menu family={{} as Family} publish={jest.fn()} /> | ||
</RBACMock> | ||
); | ||
|
||
screen.getByText('Update'); | ||
screen.getByText('Publish'); | ||
screen.getByText('Back'); | ||
}); | ||
|
||
it('a user without Admin cannot create or publish a family', () => { | ||
render( | ||
<RBACMock roles={[]}> | ||
<Menu family={{} as Family} publish={jest.fn()} /> | ||
</RBACMock> | ||
); | ||
|
||
expect(screen.queryByText('Update')).toBeNull(); | ||
expect(screen.queryByText('Publish')).toBeNull(); | ||
screen.getByText('Back'); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
src/packages/modules-operations/families/visualization/menu.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,43 @@ | ||
import { Family } from '../../../model/operations/family'; | ||
import { ActionToolbar, Button, ReturnButton } from '@inseefr/wilco'; | ||
import Auth from '../../../auth/components/auth'; | ||
import { ADMIN } from '../../../auth/roles'; | ||
import { ValidationButton } from '../../../components'; | ||
import D from '../../../deprecated-locales/build-dictionary'; | ||
import { containUnsupportedStyles } from '../../../utils/html-utils'; | ||
import { useGoBack } from '../../../utils/hooks/useGoBack'; | ||
|
||
type MenuTypes = { | ||
family: Family; | ||
publish: () => void; | ||
}; | ||
|
||
export const Menu = ({ family, publish }: Readonly<MenuTypes>) => { | ||
const goBack = useGoBack(); | ||
|
||
/* | ||
* The publication button should be enabled only if RICH_TEXT value do not | ||
* have unsupported styles like STRIKETHROUGH, color or background color | ||
*/ | ||
const publicationDisabled = containUnsupportedStyles(family); | ||
|
||
return ( | ||
<ActionToolbar> | ||
<ReturnButton action={() => goBack('/operations/families')} /> | ||
|
||
<Auth roles={[ADMIN]}> | ||
<ValidationButton | ||
object={family} | ||
callback={publish} | ||
disabled={publicationDisabled} | ||
/> | ||
</Auth> | ||
<Auth roles={[ADMIN]}> | ||
<Button | ||
action={`/operations/family/${family.id}/modify`} | ||
label={D.btnUpdate} | ||
/> | ||
</Auth> | ||
</ActionToolbar> | ||
); | ||
}; |