2022-10-11 13:29:23 +00:00
|
|
|
import 'cypress-wait-until';
|
|
|
|
//
|
|
|
|
//namespace Cypress {
|
|
|
|
// interface Chainable {
|
|
|
|
// /**
|
|
|
|
// * Custom command that authenticates a user.
|
|
|
|
// *
|
|
|
|
// * @example cy.consolelogin('hodor', 'hodor1234')
|
|
|
|
// */
|
|
|
|
// consolelogin(username: string, password: string): void
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//Cypress.Commands.add('consolelogin', { prevSubject: false }, (username: string, password: string) => {
|
|
|
|
//
|
|
|
|
// window.sessionStorage.removeItem("zitadel:access_token")
|
|
|
|
// cy.visit(Cypress.config('baseUrl')/ui/console).then(() => {
|
|
|
|
// // fill the fields and push button
|
|
|
|
// cy.get('#loginName').type(username, { log: false })
|
|
|
|
// cy.get('#submit-button').click()
|
|
|
|
// cy.get('#password').type(password, { log: false })
|
|
|
|
// cy.get('#submit-button').click()
|
|
|
|
// cy.location('pathname', {timeout: 5 * 1000}).should('eq', '/');
|
|
|
|
// })
|
|
|
|
//})
|
|
|
|
//
|
|
|
|
|
|
|
|
interface ShouldNotExistOptions {
|
2023-01-04 13:38:27 +00:00
|
|
|
selector: string;
|
|
|
|
timeout?: {
|
|
|
|
errMessage: string;
|
|
|
|
ms: number;
|
|
|
|
};
|
2022-10-11 13:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
declare global {
|
|
|
|
namespace Cypress {
|
2022-04-28 10:35:02 +00:00
|
|
|
interface Chainable {
|
2022-10-11 13:29:23 +00:00
|
|
|
/**
|
|
|
|
* Custom command that asserts on clipboard text.
|
|
|
|
*
|
|
|
|
* @example cy.clipboardMatches('hodor', 'hodor1234')
|
|
|
|
*/
|
|
|
|
clipboardMatches(pattern: RegExp | string): Cypress.Chainable<null>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom command that waits until the selector finds zero elements.
|
|
|
|
*/
|
2023-01-04 13:38:27 +00:00
|
|
|
shouldNotExist(options: ShouldNotExistOptions): Cypress.Chainable<null>;
|
|
|
|
/**
|
|
|
|
* Custom command that asserts success is printed after a change.
|
|
|
|
*/
|
|
|
|
shouldConfirmSuccess(): Cypress.Chainable<null>;
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|
2022-10-11 13:29:23 +00:00
|
|
|
}
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 13:29:23 +00:00
|
|
|
Cypress.Commands.add('clipboardMatches', { prevSubject: false }, (pattern: RegExp | string) => {
|
|
|
|
/* doesn't work reliably
|
|
|
|
return cy.window()
|
|
|
|
.then(win => {
|
|
|
|
win.focus()
|
|
|
|
return cy.waitUntil(() => win.navigator.clipboard.readText()
|
|
|
|
.then(clipboadText => {
|
|
|
|
win.focus()
|
|
|
|
const matches = typeof pattern === "string"
|
|
|
|
? clipboadText.includes(pattern)
|
|
|
|
: pattern.test(clipboadText)
|
|
|
|
if (!matches) {
|
|
|
|
cy.log(`text in clipboard ${clipboadText} doesn't match the pattern ${pattern}, yet`)
|
|
|
|
}
|
|
|
|
return matches
|
|
|
|
})
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.then(() => null)
|
|
|
|
*/
|
|
|
|
});
|
2022-04-28 10:35:02 +00:00
|
|
|
|
2023-01-04 13:38:27 +00:00
|
|
|
Cypress.Commands.add('shouldNotExist', { prevSubject: false }, (options: ShouldNotExistOptions) => {
|
|
|
|
if (!options.timeout) {
|
|
|
|
const elements = Cypress.$(options.selector);
|
|
|
|
expect(elements.text()).to.be.empty;
|
|
|
|
expect(elements.length).to.equal(0);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return cy
|
|
|
|
.waitUntil(
|
|
|
|
() => {
|
|
|
|
const elements = Cypress.$(options.selector);
|
|
|
|
if (!elements.length) {
|
|
|
|
return cy.wrap(true);
|
|
|
|
}
|
|
|
|
return cy.log(`elements with selector ${options.selector} and text ${elements.text()} exist`).wrap(false);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timeout: options.timeout.ms,
|
|
|
|
errorMsg: options.timeout.errMessage,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.then(() => null);
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('shouldConfirmSuccess', { prevSubject: false }, () => {
|
|
|
|
cy.get('.data-e2e-message');
|
|
|
|
cy.shouldNotExist({ selector: '.data-e2e-failure' });
|
|
|
|
cy.get('.data-e2e-success');
|
2022-10-11 13:29:23 +00:00
|
|
|
});
|