@@ -37,6 +37,9 @@ beforeEach(() => {
3737 mockAuthenticatedLoginState ( ) ;
3838} ) ;
3939
40+ const registrationCheckboxName =
41+ 'Tapahtumalle luodaan Linked Events -ilmoittautuminen' ;
42+
4043type InitialValues = {
4144 [ EVENT_FIELDS . EVENT_INFO_LANGUAGES ] : string [ ] ;
4245 [ EVENT_FIELDS . HAS_PRICE ] : boolean ;
@@ -58,17 +61,19 @@ const defaultMocks = [mockedFreePriceGroupsResponse, mockedUserResponse];
5861const renderPriceSection = ( {
5962 initialValues,
6063 mocks = defaultMocks ,
64+ isAdminUser = true ,
6165} : {
6266 initialValues ?: Partial < InitialValues > ;
6367 mocks ?: MockedResponse [ ] ;
68+ isAdminUser ?: boolean ;
6469} = { } ) =>
6570 render (
6671 < Formik
6772 initialValues = { { ...defaultInitialValues , ...initialValues } }
6873 onSubmit = { vi . fn ( ) }
6974 validationSchema = { publicEventSchema }
7075 >
71- < PriceSection isEditingAllowed = { true } />
76+ < PriceSection isEditingAllowed = { true } isAdminUser = { isAdminUser } />
7277 </ Formik > ,
7378 { mocks }
7479 ) ;
@@ -120,7 +125,7 @@ const getElement = (
120125 } ) ;
121126 case 'isRegistrationPlannedCheckbox' :
122127 return screen . getByRole ( 'checkbox' , {
123- name : 'Tapahtumalle luodaan Linked Events -ilmoittautuminen' ,
128+ name : registrationCheckboxName ,
124129 } ) ;
125130 case 'priceGroupSelectButton' :
126131 return screen . getByRole ( 'button' , { name : / A s i a k a s r y h m ä / } ) ;
@@ -255,3 +260,18 @@ test('should add and remove price group', async () => {
255260 1
256261 ) ;
257262} ) ;
263+
264+ test ( 'should not show registration checkbox to non admin user' , async ( ) => {
265+ const user = userEvent . setup ( ) ;
266+ renderPriceSection ( {
267+ isAdminUser : false ,
268+ } ) ;
269+
270+ await user . click ( getElement ( 'hasPriceCheckbox' ) ) ;
271+
272+ expect (
273+ screen . queryByRole ( 'checkbox' , {
274+ name : registrationCheckboxName ,
275+ } )
276+ ) . not . toBeInTheDocument ( ) ;
277+ } ) ;
0 commit comments