1- import * as React from 'react' ;
1+ import { profileFactory } from '@linode/utilities' ;
2+ import { waitFor } from '@testing-library/react' ;
3+ import React from 'react' ;
24
5+ import { http , HttpResponse , server } from 'src/mocks/testServer' ;
36import { renderWithTheme } from 'src/utilities/testHelpers' ;
47
58import { LinodeEntityDetailFooter } from './LinodeEntityDetailFooter' ;
@@ -13,40 +16,48 @@ const props = {
1316 linodeTags : [ 'test' , 'linode' ] ,
1417} ;
1518
16- const queryMocks = vi . hoisted ( ( ) => ( {
17- userPermissions : vi . fn ( ( ) => ( {
18- data : { update_account : false } ,
19- } ) ) ,
20- } ) ) ;
19+ describe ( 'LinodeEntityDetailFooter' , ( ) => {
20+ it ( 'should disable the "Add a tag" button by default' , async ( ) => {
21+ const { getByRole } = renderWithTheme (
22+ < LinodeEntityDetailFooter { ... props } />
23+ ) ;
2124
22- vi . mock ( 'src/features/IAM/hooks/usePermissions' , ( ) => ( {
23- usePermissions : queryMocks . userPermissions ,
24- } ) ) ;
25+ expect ( getByRole ( 'button' , { name : 'Add a tag' } ) ) . toBeDisabled ( ) ;
26+ } ) ;
27+
28+ it ( 'should enable the "Add a tag" button if the user is unrestricted (legacy grants)' , async ( ) => {
29+ server . use (
30+ http . get ( '*/v4*/profile' , ( ) =>
31+ HttpResponse . json ( profileFactory . build ( { restricted : false } ) )
32+ )
33+ ) ;
2534
26- describe ( 'LinodeEntityDetailFooter' , ( ) => {
27- it ( 'should disable "Add a tag" button if the user does not have update_account permission' , async ( ) => {
2835 const { getByRole } = renderWithTheme (
2936 < LinodeEntityDetailFooter { ...props } />
3037 ) ;
3138
32- const addTagBtn = getByRole ( 'button' , {
33- name : 'Add a tag' ,
39+ await waitFor ( ( ) => {
40+ expect ( getByRole ( 'button' , { name : 'Add a tag' } ) ) . toBeEnabled ( ) ;
3441 } ) ;
35- expect ( addTagBtn ) . toHaveAttribute ( 'aria-disabled' , 'true' ) ;
3642 } ) ;
3743
38- it ( 'should enable "Add a tag" button if the user has update_account permission' , async ( ) => {
39- queryMocks . userPermissions . mockReturnValue ( {
40- data : { update_account : true } ,
41- } ) ;
44+ it ( 'should enable the "Add a tag" button if the user is an account admin (IAM)' , async ( ) => {
45+ server . use (
46+ http . get ( '*/v4*/profile' , ( ) =>
47+ HttpResponse . json ( profileFactory . build ( { restricted : true } ) )
48+ ) ,
49+ http . get ( '*/v4*/iam/users/:username/permissions/account' , ( ) =>
50+ HttpResponse . json ( [ 'is_account_admin' ] )
51+ )
52+ ) ;
4253
4354 const { getByRole } = renderWithTheme (
44- < LinodeEntityDetailFooter { ...props } />
55+ < LinodeEntityDetailFooter { ...props } /> ,
56+ { flags : { iam : { enabled : true , beta : true } } }
4557 ) ;
4658
47- const addTagBtn = getByRole ( 'button' , {
48- name : 'Add a tag' ,
59+ await waitFor ( ( ) => {
60+ expect ( getByRole ( 'button' , { name : 'Add a tag' } ) ) . toBeEnabled ( ) ;
4961 } ) ;
50- expect ( addTagBtn ) . not . toHaveAttribute ( 'aria-disabled' , 'true' ) ;
5162 } ) ;
5263} ) ;
0 commit comments