@@ -160,9 +160,7 @@ const expectNoDraftRows = () => {
160160
161161const openTopLevelDraftRow = async ( ) => {
162162 const addButton = await screen . findByLabelText ( 'Create Tag' ) ;
163- await act ( async ( ) => {
164- fireEvent . click ( addButton ) ;
165- } ) ;
163+ fireEvent . click ( addButton ) ;
166164 const creatingRow = await screen . findByTestId ( 'creating-top-row' ) ;
167165 const input = creatingRow . querySelector ( 'input' ) ;
168166 expect ( input ) . toBeInTheDocument ( ) ;
@@ -172,18 +170,14 @@ const openTopLevelDraftRow = async () => {
172170const openActionsMenuForTag = ( tagName , actionButtonName = / a c t i o n s / i) => {
173171 if ( ! screen . queryAllByText ( tagName ) ?. length ) {
174172 // expand all
175- const expandButton = screen . queryAllByText ( 'Expand All' ) ?. [ 0 ] ;
176- act ( ( ) => {
177- if ( expandButton ) {
178- fireEvent . click ( expandButton ) ;
179- }
180- } ) ;
173+ const expandButton = screen . queryByRole ( 'button' , { name : 'Expand All' } ) ;
174+ if ( expandButton ) {
175+ fireEvent . click ( expandButton ) ;
176+ }
181177 }
182178 const row = screen . getByText ( tagName ) . closest ( 'tr' ) ;
183179 const actionsButton = within ( row ) . getByRole ( 'button' , { name : actionButtonName } ) ;
184- act ( ( ) => {
185- fireEvent . click ( actionsButton ) ;
186- } ) ;
180+ fireEvent . click ( actionsButton ) ;
187181 return row ;
188182} ;
189183
@@ -203,8 +197,8 @@ const openSubtagDraftRow = async ({
203197
204198const openRenameDraftRow = async ( tagName = 'root tag 1' ) => {
205199 openActionsMenuForTag ( tagName ) ;
206- fireEvent . click ( screen . getByText ( 'Rename' ) ) ;
207- const input = screen . getByRole ( 'textbox' ) ;
200+ fireEvent . click ( screen . getByRole ( 'button' , { name : / R e n a m e / i } ) ) ;
201+ const input = screen . getByRole ( 'textbox' , { name : / t y p e t a g n a m e / i } ) ;
208202 const row = input . closest ( 'tr' ) ;
209203 expect ( row ) . toBeInTheDocument ( ) ;
210204 const saveButton = within ( row ) . getByText ( 'Save' ) ;
@@ -305,7 +299,7 @@ describe('<TagListTable />', () => {
305299 await waitForRootTag ( ) ;
306300
307301 openActionsMenuForTag ( 'root tag 1' ) ;
308- expect ( screen . getByText ( ' Add Subtag') ) . toBeDisabled ( ) ;
302+ expect ( screen . getByRole ( 'button' , { name : ' Add Subtag' } ) ) . toHaveAttribute ( 'aria-disabled' , 'true' ) ;
309303 expect ( screen . getByLabelText ( 'Create Tag' ) ) . toBeDisabled ( ) ;
310304 } ) ;
311305
@@ -332,7 +326,7 @@ describe('<TagListTable />', () => {
332326 const { creatingRow, input } = await openTopLevelDraftRow ( ) ;
333327
334328 fireEvent . change ( input , { target : { value : 'a new tag' } } ) ;
335- const saveButton = within ( creatingRow ) . getByText ( ' Save') ;
329+ const saveButton = within ( creatingRow ) . getByRole ( 'button' , { name : ' Save' } ) ;
336330 fireEvent . click ( saveButton ) ;
337331 await waitFor ( ( ) => {
338332 expect ( axiosMock . history . post . length ) . toBe ( 1 ) ;
@@ -381,7 +375,7 @@ describe('<TagListTable />', () => {
381375 const { creatingRow, input } = await openTopLevelDraftRow ( ) ;
382376
383377 fireEvent . change ( input , { target : { value : 'a new tag' } } ) ;
384- const saveButton = within ( creatingRow ) . getByText ( ' Save') ;
378+ const saveButton = within ( creatingRow ) . getByRole ( 'button' , { name : ' Save' } ) ;
385379 fireEvent . click ( saveButton ) ;
386380 const spinner = await screen . findByRole ( 'status' ) ;
387381 expect ( spinner . textContent ) . toEqual ( 'Saving...' ) ;
@@ -398,7 +392,7 @@ describe('<TagListTable />', () => {
398392 const { creatingRow, input } = await openTopLevelDraftRow ( ) ;
399393
400394 fireEvent . change ( input , { target : { value : 'a new tag' } } ) ;
401- const saveButton = within ( creatingRow ) . getByText ( ' Save') ;
395+ const saveButton = within ( creatingRow ) . getByRole ( 'button' , { name : ' Save' } ) ;
402396 fireEvent . click ( saveButton ) ;
403397 let newTag ;
404398 await waitFor ( ( ) => {
@@ -425,7 +419,7 @@ describe('<TagListTable />', () => {
425419 const { creatingRow, input } = await openTopLevelDraftRow ( ) ;
426420
427421 fireEvent . change ( input , { target : { value : 'a new tag' } } ) ;
428- const saveButton = within ( creatingRow ) . getByText ( ' Save') ;
422+ const saveButton = within ( creatingRow ) . getByRole ( 'button' , { name : ' Save' } ) ;
429423 fireEvent . click ( saveButton ) ;
430424 const toast = await screen . findByText ( 'Tag "a new tag" created successfully' ) ;
431425 expect ( toast ) . toBeInTheDocument ( ) ;
@@ -442,7 +436,7 @@ describe('<TagListTable />', () => {
442436 const { creatingRow, input } = await openTopLevelDraftRow ( ) ;
443437
444438 fireEvent . change ( input , { target : { value : 'xyz tag' } } ) ;
445- const saveButton = within ( creatingRow ) . getByText ( ' Save') ;
439+ const saveButton = within ( creatingRow ) . getByRole ( 'button' , { name : ' Save' } ) ;
446440 fireEvent . click ( saveButton ) ;
447441 // no input row should be in the document
448442 await waitFor ( ( ) => {
@@ -464,7 +458,7 @@ describe('<TagListTable />', () => {
464458 const { creatingRow, input } = await openTopLevelDraftRow ( ) ;
465459
466460 fireEvent . change ( input , { target : { value : 'xyz tag' } } ) ;
467- const saveButton = within ( creatingRow ) . getByText ( ' Save') ;
461+ const saveButton = within ( creatingRow ) . getByRole ( 'button' , { name : ' Save' } ) ;
468462 fireEvent . click ( saveButton ) ;
469463 const temporaryRow = await screen . findByText ( 'xyz tag' ) ;
470464 // temporaryRow should be at the top of the table, that is, the first row after the header
@@ -506,7 +500,7 @@ describe('<TagListTable />', () => {
506500 expect ( input ) . toBeInTheDocument ( ) ;
507501
508502 fireEvent . change ( input , { target : { value : 'Tag A' } } ) ;
509- let saveButton = within ( creatingRow ) . getByText ( ' Save') ;
503+ let saveButton = within ( creatingRow ) . getByRole ( 'button' , { name : ' Save' } ) ;
510504 fireEvent . click ( saveButton ) ;
511505 const tagA = await screen . findByText ( 'Tag A' ) ;
512506 expect ( tagA ) . toBeInTheDocument ( ) ;
@@ -518,7 +512,7 @@ describe('<TagListTable />', () => {
518512 expect ( input ) . toBeInTheDocument ( ) ;
519513
520514 fireEvent . change ( input , { target : { value : 'Tag B' } } ) ;
521- saveButton = within ( creatingRow ) . getByText ( ' Save') ;
515+ saveButton = within ( creatingRow ) . getByRole ( 'button' , { name : ' Save' } ) ;
522516 fireEvent . click ( saveButton ) ;
523517 const tagB = await screen . findByText ( 'Tag B' ) ;
524518 expect ( tagB ) . toBeInTheDocument ( ) ;
@@ -539,7 +533,7 @@ describe('<TagListTable />', () => {
539533 const draftRow = await screen . findAllByRole ( 'row' ) ;
540534 const input = draftRow [ 1 ] . querySelector ( 'input' ) ;
541535 expect ( input ) . toBeInTheDocument ( ) ;
542- const saveButton = within ( draftRow [ 1 ] ) . getByText ( ' Save') ;
536+ const saveButton = within ( draftRow [ 1 ] ) . getByRole ( 'button' , { name : ' Save' } ) ;
543537 expect ( saveButton ) . toBeDisabled ( ) ;
544538 fireEvent . change ( input , { target : { value : 'a new tag' } } ) ;
545539 expect ( saveButton ) . not . toBeDisabled ( ) ;
@@ -551,7 +545,7 @@ describe('<TagListTable />', () => {
551545 const draftRow = await screen . findAllByRole ( 'row' ) ;
552546 const input = draftRow [ 1 ] . querySelector ( 'input' ) ;
553547 expect ( input ) . toBeInTheDocument ( ) ;
554- const saveButton = within ( draftRow [ 1 ] ) . getByText ( ' Save') ;
548+ const saveButton = within ( draftRow [ 1 ] ) . getByRole ( 'button' , { name : ' Save' } ) ;
555549 expect ( saveButton ) . toBeDisabled ( ) ;
556550 fireEvent . change ( input , { target : { value : ' ' } } ) ;
557551 expect ( saveButton ) . toBeDisabled ( ) ;
@@ -571,7 +565,7 @@ describe('<TagListTable />', () => {
571565 fireEvent . click ( await screen . findByLabelText ( 'Create Tag' ) ) ;
572566 const draftRow = await screen . findAllByRole ( 'row' ) ;
573567 const input = draftRow [ 1 ] . querySelector ( 'input' ) ;
574- const saveButton = within ( draftRow [ 1 ] ) . getByText ( ' Save') ;
568+ const saveButton = within ( draftRow [ 1 ] ) . getByRole ( 'button' , { name : ' Save' } ) ;
575569
576570 fireEvent . change ( input , { target : { value : ' Tag A ' } } ) ;
577571 fireEvent . click ( saveButton ) ;
@@ -586,11 +580,9 @@ describe('<TagListTable />', () => {
586580 fireEvent . click ( await screen . findByLabelText ( 'Create Tag' ) ) ;
587581 const draftRow = await screen . findAllByRole ( 'row' ) ;
588582 const input = draftRow [ 1 ] . querySelector ( 'input' ) ;
589- const saveButton = within ( draftRow [ 1 ] ) . getByText ( ' Save') ;
583+ const saveButton = within ( draftRow [ 1 ] ) . getByRole ( 'button' , { name : ' Save' } ) ;
590584
591- await act ( async ( ) => {
592- fireEvent . change ( input , { target : { value : 'invalid;tag' } } ) ;
593- } ) ;
585+ fireEvent . change ( input , { target : { value : 'invalid;tag' } } ) ;
594586
595587 expect ( saveButton ) . toBeDisabled ( ) ;
596588 expect ( screen . getByText ( / i n v a l i d c h a r a c t e r / i) ) . toBeInTheDocument ( ) ;
@@ -602,7 +594,7 @@ describe('<TagListTable />', () => {
602594 fireEvent . click ( await screen . findByLabelText ( 'Create Tag' ) ) ;
603595 const draftRow = await screen . findAllByRole ( 'row' ) ;
604596 const input = draftRow [ 1 ] . querySelector ( 'input' ) ;
605- const saveButton = within ( draftRow [ 1 ] ) . getByText ( ' Save') ;
597+ const saveButton = within ( draftRow [ 1 ] ) . getByRole ( 'button' , { name : ' Save' } ) ;
606598
607599 fireEvent . change ( input , { target : { value : 'root tag 1' } } ) ;
608600 fireEvent . click ( saveButton ) ;
@@ -618,7 +610,7 @@ describe('<TagListTable />', () => {
618610 fireEvent . click ( await screen . findByLabelText ( 'Create Tag' ) ) ;
619611 const draftRow = await screen . findAllByRole ( 'row' ) ;
620612 const input = draftRow [ 1 ] . querySelector ( 'input' ) ;
621- const saveButton = within ( draftRow [ 1 ] ) . getByText ( ' Save') ;
613+ const saveButton = within ( draftRow [ 1 ] ) . getByRole ( 'button' , { name : ' Save' } ) ;
622614
623615 fireEvent . change ( input , { target : { value : 'will fail' } } ) ;
624616 fireEvent . click ( saveButton ) ;
@@ -660,7 +652,7 @@ describe('<TagListTable />', () => {
660652 expect ( screen . queryAllByText ( 'Add Subtag' ) . length ) . toBe ( 0 ) ;
661653 // user clicks on row actions for root tag 1
662654 openActionsMenuForTag ( 'root tag 1' ) ;
663- expect ( screen . getByText ( ' Add Subtag') ) . toBeInTheDocument ( ) ;
655+ expect ( screen . getByRole ( 'button' , { name : ' Add Subtag' } ) ) . toBeInTheDocument ( ) ;
664656 } ) ;
665657
666658 it ( 'should render an inline add-subtag row with input, placeholder, and action buttons' , async ( ) => {
@@ -672,14 +664,14 @@ describe('<TagListTable />', () => {
672664 const draftRowIndex = rows . findIndex ( tableRow => tableRow . querySelector ( 'input' ) ) ;
673665 expect ( draftRowIndex ) . toBe ( parentRowIndex + 1 ) ;
674666 expect ( draftRows [ 0 ] . querySelector ( 'input' ) ) . toBeInTheDocument ( ) ;
675- expect ( within ( draftRows [ 0 ] ) . getByText ( ' Cancel') ) . toBeInTheDocument ( ) ;
676- expect ( within ( draftRows [ 0 ] ) . getByText ( ' Save') ) . toBeInTheDocument ( ) ;
667+ expect ( within ( draftRows [ 0 ] ) . getByRole ( 'button' , { name : ' Cancel' } ) ) . toBeInTheDocument ( ) ;
668+ expect ( within ( draftRows [ 0 ] ) . getByRole ( 'button' , { name : ' Save' } ) ) . toBeInTheDocument ( ) ;
677669 } ) ;
678670
679671 it ( 'should remove add-subtag row and avoid create request when cancelled' , async ( ) => {
680672 const { draftRow, input } = await openSubtagDraftRow ( { tagName : 'root tag 1' } ) ;
681673 fireEvent . change ( input , { target : { value : 'new subtag' } } ) ;
682- fireEvent . click ( within ( draftRow ) . getByText ( ' Cancel') ) ;
674+ fireEvent . click ( within ( draftRow ) . getByRole ( 'button' , { name : ' Cancel' } ) ) ;
683675
684676 await waitFor ( ( ) => {
685677 expect ( axiosMock . history . post . length ) . toBe ( 0 ) ;
@@ -701,38 +693,36 @@ describe('<TagListTable />', () => {
701693
702694 it ( 'should disable Save and show required-name inline error for empty sub-tag input' , async ( ) => {
703695 openActionsMenuForTag ( 'root tag 1' ) ;
704- fireEvent . click ( screen . getByText ( ' Add Subtag') ) ;
696+ fireEvent . click ( screen . getByRole ( 'button' , { name : ' Add Subtag' } ) ) ;
705697 const rows = await screen . findAllByRole ( 'row' ) ;
706698 const draftRow = rows . find ( tableRow => tableRow . querySelector ( 'input' ) ) ;
707- const saveButton = within ( draftRow ) . getByText ( ' Save') ;
699+ const saveButton = within ( draftRow ) . getByRole ( 'button' , { name : ' Save' } ) ;
708700 const input = draftRow . querySelector ( 'input' ) ;
709- act ( ( ) => {
710- fireEvent . change ( input , { target : { value : ' ' } } ) ;
711- } ) ;
701+ fireEvent . change ( input , { target : { value : ' ' } } ) ;
712702
713703 expect ( saveButton ) . toBeDisabled ( ) ;
714704 expect ( within ( draftRow ) . getByText ( / N a m e i s r e q u i r e d / i) ) . toBeInTheDocument ( ) ;
715705 } ) ;
716706
717707 it ( 'should keep Save disabled for whitespace-only sub-tag input' , async ( ) => {
718708 openActionsMenuForTag ( 'root tag 1' ) ;
719- fireEvent . click ( screen . getByText ( ' Add Subtag') ) ;
709+ fireEvent . click ( screen . getByRole ( 'button' , { name : ' Add Subtag' } ) ) ;
720710 const rows = await screen . findAllByRole ( 'row' ) ;
721711 const draftRow = rows . find ( tableRow => tableRow . querySelector ( 'input' ) ) ;
722712 const input = draftRow . querySelector ( 'input' ) ;
723- const saveButton = within ( draftRow ) . getByText ( ' Save') ;
713+ const saveButton = within ( draftRow ) . getByRole ( 'button' , { name : ' Save' } ) ;
724714
725715 fireEvent . change ( input , { target : { value : ' ' } } ) ;
726716 expect ( saveButton ) . toBeDisabled ( ) ;
727717 } ) ;
728718
729719 it ( 'should disable Save and show invalid-character error for sub-tag input' , async ( ) => {
730720 openActionsMenuForTag ( 'root tag 1' ) ;
731- fireEvent . click ( screen . getByText ( ' Add Subtag') ) ;
721+ fireEvent . click ( screen . getByRole ( 'button' , { name : ' Add Subtag' } ) ) ;
732722 const rows = await screen . findAllByRole ( 'row' ) ;
733723 const draftRow = rows . find ( row => row . querySelector ( 'input' ) ) ;
734724 const input = draftRow . querySelector ( 'input' ) ;
735- const saveButton = within ( draftRow ) . getByText ( ' Save') ;
725+ const saveButton = within ( draftRow ) . getByRole ( 'button' , { name : ' Save' } ) ;
736726
737727 fireEvent . change ( input , { target : { value : 'invalid;name' } } ) ;
738728 expect ( saveButton ) . toBeDisabled ( ) ;
@@ -745,12 +735,12 @@ describe('<TagListTable />', () => {
745735 } ) ;
746736
747737 openActionsMenuForTag ( 'root tag 1' ) ;
748- fireEvent . click ( screen . getByText ( ' Add Subtag') ) ;
738+ fireEvent . click ( screen . getByRole ( 'button' , { name : ' Add Subtag' } ) ) ;
749739 const rows = await screen . findAllByRole ( 'row' ) ;
750740 const draftRow = rows . find ( row => row . querySelector ( 'input' ) ) ;
751741 const input = draftRow . querySelector ( 'input' ) ;
752742 fireEvent . change ( input , { target : { value : 'subtag fail' } } ) ;
753- fireEvent . click ( within ( draftRow ) . getByText ( ' Save') ) ;
743+ fireEvent . click ( within ( draftRow ) . getByRole ( 'button' , { name : ' Save' } ) ) ;
754744
755745 await waitFor ( ( ) => {
756746 expect ( getDraftRows ( ) . length ) . toBe ( 1 ) ;
@@ -779,9 +769,7 @@ describe('<TagListTable />', () => {
779769 const { input } = await openRenameDraftRow ( 'root tag 1' ) ;
780770
781771 fireEvent . change ( input , { target : { value : 'will fail' } } ) ;
782- act ( ( ) => {
783- fireEvent . keyDown ( input , { key : 'Enter' , code : 'Enter' } ) ;
784- } ) ;
772+ fireEvent . keyDown ( input , { key : 'Enter' , code : 'Enter' } ) ;
785773
786774 let draftRow ;
787775 await waitFor ( ( ) => {
@@ -830,8 +818,8 @@ describe('<TagListTable />', () => {
830818 await waitForRootTag ( ) ;
831819
832820 openActionsMenuForTag ( tagName ) ;
833- expect ( screen . getByText ( 'Rename' ) ) . toBeInTheDocument ( ) ;
834- expect ( screen . getByText ( 'Rename' ) ) . toBeDisabled ( ) ;
821+ expect ( screen . getByRole ( 'button' , { name : / R e n a m e / i } ) ) . toBeInTheDocument ( ) ;
822+ expect ( screen . getByRole ( 'button' , { name : / R e n a m e / i } ) ) . toHaveAttribute ( 'aria-disabled' , 'true' ) ;
835823 } ) ;
836824 it ( 'should disable tag edit buttons if tag includes `can_edit: false`' , async ( ) => {
837825 axiosMock . reset ( ) ;
@@ -842,22 +830,22 @@ describe('<TagListTable />', () => {
842830 await waitForRootTag ( ) ;
843831
844832 openActionsMenuForTag ( tagName ) ;
845- expect ( screen . getByText ( 'Rename' ) ) . toBeInTheDocument ( ) ;
846- expect ( screen . getByText ( 'Rename' ) ) . toBeDisabled ( ) ;
833+ expect ( screen . getByRole ( 'button' , { name : / R e n a m e / i } ) ) . toBeInTheDocument ( ) ;
834+ expect ( screen . getByRole ( 'button' , { name : / R e n a m e / i } ) ) . toHaveAttribute ( 'aria-disabled' , 'true' ) ;
847835 } ) ;
848836
849837 it ( 'should show tag actions menu' , async ( ) => {
850838 openActionsMenuForTag ( tagName ) ;
851839 expect ( screen . getByText ( 'Add Subtag' ) ) . toBeInTheDocument ( ) ;
852- expect ( screen . getByText ( 'Rename' ) ) . toBeInTheDocument ( ) ;
840+ expect ( screen . getByRole ( 'button' , { name : / R e n a m e / i } ) ) . toBeInTheDocument ( ) ;
853841 } ) ;
854842 it ( 'should show editable input and action buttons when Rename is selected from actions menu' , async ( ) => {
855843 const { row } = await openRenameDraftRow ( tagName ) ;
856844 expect ( within ( row ) . getByRole ( 'textbox' ) ) . toBeInTheDocument ( ) ;
857845 // expect the input to be pre-filled with the current tag name
858846 expect ( within ( row ) . getByRole ( 'textbox' ) . value ) . toEqual ( tagName ) ;
859- expect ( within ( row ) . getByText ( 'Save' ) ) . toBeInTheDocument ( ) ;
860- expect ( within ( row ) . getByText ( 'Cancel' ) ) . toBeInTheDocument ( ) ;
847+ expect ( within ( row ) . getByRole ( 'button' , { name : / S a v e / i } ) ) . toBeInTheDocument ( ) ;
848+ expect ( within ( row ) . getByRole ( 'button' , { name : / C a n c e l / i } ) ) . toBeInTheDocument ( ) ;
861849 } ) ;
862850 it ( 'should disable Save button until the tag name is changed' , async ( ) => {
863851 const { input, saveButton } = await openRenameDraftRow ( tagName ) ;
@@ -871,9 +859,7 @@ describe('<TagListTable />', () => {
871859 const { input } = await openRenameDraftRow ( tagName ) ;
872860
873861 fireEvent . change ( input , { target : { value : `${ tagName } updated` } } ) ;
874- act ( ( ) => {
875- fireEvent . keyDown ( input , { key : 'Enter' , code : 'Enter' } ) ;
876- } ) ;
862+ fireEvent . keyDown ( input , { key : 'Enter' , code : 'Enter' } ) ;
877863
878864 await waitFor ( ( ) => {
879865 expect ( axiosMock . history . patch . length ) . toBe ( 1 ) ;
@@ -989,8 +975,8 @@ describe('<TagListTable />', () => {
989975 const grandchildTagRow = screen . getByText ( 'the grandchild tag' ) . closest ( 'tr' ) ;
990976 expect ( within ( grandchildTagRow ) . queryByRole ( 'button' , { name : / a c t i o n s / i } ) ) . toBeInTheDocument ( ) ;
991977 openActionsMenuForTag ( 'the grandchild tag' ) ;
992- expect ( within ( grandchildTagRow ) . getByText ( 'Rename' ) ) . toBeInTheDocument ( ) ;
993- expect ( within ( grandchildTagRow ) . getByText ( 'Add Subtag' ) ) . toBeDisabled ( ) ;
978+ expect ( within ( grandchildTagRow ) . getByRole ( 'button' , { name : / R e n a m e / i } ) ) . toBeInTheDocument ( ) ;
979+ expect ( within ( grandchildTagRow ) . getByText ( 'Add Subtag' ) ) . toHaveAttribute ( 'aria-disabled' , 'true' ) ;
994980 } ) ;
995981 } ) ;
996982} ) ;
0 commit comments