@@ -12,25 +12,35 @@ const updatedTagName = 'bar'
1212
1313describe ( 'Create system tags' , ( ) => {
1414 before ( ( ) => {
15+ // delete any existing tags
16+ cy . runOccCommand ( 'tag:list --output=json' ) . then ( ( output ) => {
17+ Object . keys ( JSON . parse ( output . stdout ) ) . forEach ( ( id ) => {
18+ cy . runOccCommand ( `tag:delete ${ id } ` )
19+ } )
20+ } )
21+
22+ // login as admin and go to admin settings
1523 cy . login ( admin )
1624 cy . visit ( '/settings/admin' )
1725 } )
1826
1927 it ( 'Can create a tag' , ( ) => {
28+ cy . intercept ( 'POST' , '/remote.php/dav/systemtags' ) . as ( 'createTag' )
2029 cy . get ( 'input#system-tag-name' ) . should ( 'exist' ) . and ( 'have.value' , '' )
2130 cy . get ( 'input#system-tag-name' ) . type ( tagName )
2231 cy . get ( 'input#system-tag-name' ) . should ( 'have.value' , tagName )
2332 // submit the form
2433 cy . get ( 'input#system-tag-name' ) . type ( '{enter}' )
2534
35+ // wait for the tag to be created
36+ cy . wait ( '@createTag' ) . its ( 'response.statusCode' ) . should ( 'eq' , 201 )
37+
2638 // see that the created tag is in the list
2739 cy . get ( 'input#system-tags-input' ) . focus ( )
2840 cy . get ( 'input#system-tags-input' ) . invoke ( 'attr' , 'aria-controls' ) . then ( ( id ) => {
29- cy . get ( `ul#${ id } ` ) . within ( ( ) => {
30- cy . contains ( 'li' , tagName ) . should ( 'exist' )
31- // ensure only one tag exists
32- cy . get ( 'li' ) . should ( 'have.length' , 1 )
33- } )
41+ cy . get ( `ul#${ id } li span[title="${ tagName } "]` )
42+ . should ( 'exist' )
43+ . should ( 'have.length' , 1 )
3444 } )
3545 } )
3646} )
@@ -42,12 +52,9 @@ describe('Update system tags', { testIsolation: false }, () => {
4252 } )
4353
4454 it ( 'select the tag' , ( ) => {
45- // select the tag to edit
4655 cy . get ( 'input#system-tags-input' ) . focus ( )
4756 cy . get ( 'input#system-tags-input' ) . invoke ( 'attr' , 'aria-controls' ) . then ( ( id ) => {
48- cy . get ( `ul#${ id } ` ) . within ( ( ) => {
49- cy . contains ( 'li' , tagName ) . should ( 'exist' ) . click ( )
50- } )
57+ cy . get ( `ul#${ id } li span[title="${ tagName } "]` ) . should ( 'exist' ) . click ( )
5158 } )
5259 // see that the tag name matches the selected tag
5360 cy . get ( 'input#system-tag-name' ) . should ( 'exist' ) . and ( 'have.value' , tagName )
@@ -57,28 +64,27 @@ describe('Update system tags', { testIsolation: false }, () => {
5764 } )
5865
5966 it ( 'update the tag name and level' , ( ) => {
67+ cy . intercept ( 'PROPPATCH' , '/remote.php/dav/systemtags/*' ) . as ( 'updateTag' )
6068 cy . get ( 'input#system-tag-name' ) . clear ( )
6169 cy . get ( 'input#system-tag-name' ) . type ( updatedTagName )
6270 cy . get ( 'input#system-tag-name' ) . should ( 'have.value' , updatedTagName )
6371 // select the new tag level
6472 cy . get ( 'input#system-tag-level' ) . focus ( )
6573 cy . get ( 'input#system-tag-level' ) . invoke ( 'attr' , 'aria-controls' ) . then ( ( id ) => {
66- cy . get ( `ul#${ id } ` ) . within ( ( ) => {
67- cy . contains ( 'li' , 'Invisible' ) . should ( 'exist' ) . click ( )
68- } )
74+ cy . get ( `ul#${ id } li span[title="Invisible"]` ) . should ( 'exist' ) . click ( )
6975 } )
7076 // submit the form
7177 cy . get ( 'input#system-tag-name' ) . type ( '{enter}' )
78+ // wait for the tag to be updated
79+ cy . wait ( '@updateTag' ) . its ( 'response.statusCode' ) . should ( 'eq' , 207 )
7280 } )
7381
7482 it ( 'see the tag was successfully updated' , ( ) => {
7583 cy . get ( 'input#system-tags-input' ) . focus ( )
7684 cy . get ( 'input#system-tags-input' ) . invoke ( 'attr' , 'aria-controls' ) . then ( ( id ) => {
77- cy . get ( `ul#${ id } ` ) . within ( ( ) => {
78- cy . contains ( 'li' , `${ updatedTagName } (invisible)` ) . should ( 'exist' )
79- // ensure only one tag exists
80- cy . get ( 'li' ) . should ( 'have.length' , 1 )
81- } )
85+ cy . get ( `ul#${ id } li span[title="${ updatedTagName } (invisible)"]` )
86+ . should ( 'exist' )
87+ . should ( 'have.length' , 1 )
8288 } )
8389 } )
8490} )
@@ -93,9 +99,7 @@ describe('Delete system tags', { testIsolation: false }, () => {
9399 // select the tag to edit
94100 cy . get ( 'input#system-tags-input' ) . focus ( )
95101 cy . get ( 'input#system-tags-input' ) . invoke ( 'attr' , 'aria-controls' ) . then ( ( id ) => {
96- cy . get ( `ul#${ id } ` ) . within ( ( ) => {
97- cy . contains ( 'li' , `${ updatedTagName } (invisible)` ) . should ( 'exist' ) . click ( )
98- } )
102+ cy . get ( `ul#${ id } li span[title="${ updatedTagName } (invisible)"]` ) . should ( 'exist' ) . click ( )
99103 } )
100104 // see that the tag name matches the selected tag
101105 cy . get ( 'input#system-tag-name' ) . should ( 'exist' ) . and ( 'have.value' , updatedTagName )
@@ -105,17 +109,18 @@ describe('Delete system tags', { testIsolation: false }, () => {
105109 } )
106110
107111 it ( 'can delete the tag' , ( ) => {
112+ cy . intercept ( 'DELETE' , '/remote.php/dav/systemtags/*' ) . as ( 'deleteTag' )
108113 cy . get ( '.system-tag-form__row' ) . within ( ( ) => {
109114 cy . contains ( 'button' , 'Delete' ) . should ( 'be.enabled' ) . click ( )
110115 } )
116+ // wait for the tag to be deleted
117+ cy . wait ( '@deleteTag' ) . its ( 'response.statusCode' ) . should ( 'eq' , 204 )
111118 } )
112119
113120 it ( 'see that the deleted tag is not present' , ( ) => {
114121 cy . get ( 'input#system-tags-input' ) . focus ( )
115122 cy . get ( 'input#system-tags-input' ) . invoke ( 'attr' , 'aria-controls' ) . then ( ( id ) => {
116- cy . get ( `ul#${ id } ` ) . within ( ( ) => {
117- cy . contains ( 'li' , updatedTagName ) . should ( 'not.exist' )
118- } )
123+ cy . get ( `ul#${ id } li span[title="${ updatedTagName } "]` ) . should ( 'not.exist' )
119124 } )
120125 } )
121126} )
0 commit comments