2222
2323import axios from '@nextcloud/axios'
2424import { addCommands } from '@nextcloud/cypress'
25- import 'cypress-if'
2625import compareSnapshotCommand from 'cypress-visual-regression/dist/command.js'
2726
2827// eslint-disable-next-line no-unused-vars,n/no-extraneous-import
@@ -32,6 +31,7 @@ compareSnapshotCommand()
3231
3332const url = Cypress . config ( 'baseUrl' ) . replace ( / \/ i n d e x .p h p \/ ? $ / g, '' )
3433Cypress . env ( 'baseUrl' , url )
34+ const silent = { log : false }
3535
3636addCommands ( )
3737
@@ -40,44 +40,36 @@ addCommands()
4040// and also to determine paths, urls and the like.
4141let auth
4242Cypress . Commands . overwrite ( 'login' , ( login , user ) => {
43- cy . window ( ) . then ( ( win ) => {
43+ cy . window ( silent ) . then ( ( win ) => {
4444 win . location . href = 'about:blank'
4545 } )
4646 auth = { user : user . userId , password : user . password }
47+ cy . wrap ( null ) . as ( 'requesttoken' )
4748 login ( user )
4849} )
4950
5051Cypress . Commands . overwrite ( 'visit' , ( originalFn , url , options ) => {
5152 // Make sure that each visit call that triggers a page load will update the stored requesttoken
5253 return originalFn ( url , options ) . then ( ( result ) => {
53- cy . window ( )
54- . then ( ( win ) => cy . wrap ( win ?. OC ?. requestToken ) )
55- . as ( 'requesttoken' )
54+ cy . window ( silent )
55+ . then ( ( win ) => {
56+ cy . wrap ( win ?. OC ?. requestToken )
57+ . as ( 'requesttoken' )
58+ } )
5659 } )
5760} )
5861
5962Cypress . Commands . add ( 'getRequestToken' , ( ) => {
60- cy . get ( '@requesttoken' )
61- . if ( ( token ) => ! token )
62- . then ( ( ) => {
63- cy . window ( )
64- . then ( ( win ) => cy . wrap ( win ?. OC ?. requestToken ) )
65- . if ( ( token ) => ! ! token )
66- . then ( ( token ) => {
67- cy . log ( 'Request token from window' , token )
68- } )
63+ cy . then ( function ( ) {
64+ if ( this . requesttoken ) {
65+ return this . requesttoken
66+ } else {
67+ cy . log ( 'Fetching request token' )
68+ return cy . request ( '/csrftoken' )
69+ . its ( 'body.token' )
6970 . as ( 'requesttoken' )
70- . else ( )
71- . then ( ( token ) => {
72- cy . log ( 'Request token fetching' , token )
73- return cy . request ( '/csrftoken' )
74- . then ( ( { body } ) => {
75- return body . token
76- } )
77- } ) . as ( 'requesttoken' )
78- } )
79-
80- return cy . get ( '@requesttoken' )
71+ }
72+ } )
8173} )
8274
8375Cypress . Commands . add ( 'ocsRequest' , ( options ) => {
@@ -339,7 +331,7 @@ Cypress.Commands.add('getFileContent', (path) => {
339331} )
340332
341333Cypress . Commands . add ( 'propfindFolder' , ( path , depth = 0 ) => {
342- return cy . window ( )
334+ return cy . window ( silent )
343335 . then ( win => {
344336 const files = win . OC . Files
345337 const PROPERTY_WORKSPACE_FILE
@@ -490,7 +482,7 @@ Cypress.Commands.add('openWorkspace', (folder) => {
490482} )
491483
492484Cypress . Commands . add ( 'configureText' , ( key , value ) => {
493- return cy . window ( ) . then ( win => {
485+ return cy . window ( silent ) . then ( win => {
494486 return axios . post (
495487 `${ url } /index.php/apps/text/settings` ,
496488 { key, value } ,
0 commit comments