summaryrefslogtreecommitdiff
path: root/cypress/support/commands.ts
diff options
context:
space:
mode:
authorGianni Ceccarelli <dakkar@thenautilus.net>2024-03-20 02:25:49 +0000
committerGitHub <noreply@github.com>2024-03-20 11:25:49 +0900
commitd7bb6c88d3e4878486fb1f4d1655379896a5d976 (patch)
tree452c5ea20578bc569050c54cfc1e747dc3cae100 /cypress/support/commands.ts
parentfix(frontend): shikiの言語・テーマの定義ファイルをCDN(esm.sh)... (diff)
downloadmisskey-d7bb6c88d3e4878486fb1f4d1655379896a5d976.tar.gz
misskey-d7bb6c88d3e4878486fb1f4d1655379896a5d976.tar.bz2
misskey-d7bb6c88d3e4878486fb1f4d1655379896a5d976.zip
Cypress typescript (#13591)
* convert Cypress tests to TypeScript this work was done by @lunaisnotaboy https://github.com/lunaisnotaboy for their fork https://github.com/cutiekey/cutiekey/pull/7 I just repacked their changes into a minimal set * fix call to `window` in cypress tests this error was spotted thanks to the TypeScript compiler: ``` support/commands.ts:33:12 - error TS2559: Type '(win: any) => void' has no properties in common with type 'Partial<Loggable & Timeoutable>'. 33 cy.window(win => { ~~~~~~~~ Found 1 error in support/commands.ts:33 ``` (again, @lunaisnotaboy did the actual work)
Diffstat (limited to 'cypress/support/commands.ts')
-rw-r--r--cypress/support/commands.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts
new file mode 100644
index 0000000000..c2d92e1663
--- /dev/null
+++ b/cypress/support/commands.ts
@@ -0,0 +1,60 @@
+// ***********************************************
+// This example commands.js shows you how to
+// create various custom commands and overwrite
+// existing commands.
+//
+// For more comprehensive examples of custom
+// commands please read more here:
+// https://on.cypress.io/custom-commands
+// ***********************************************
+//
+//
+// -- This is a parent command --
+// Cypress.Commands.add('login', (email, password) => { ... })
+//
+//
+// -- This is a child command --
+// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
+//
+//
+// -- This is a dual command --
+// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
+//
+//
+// -- This will overwrite an existing command --
+// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
+
+Cypress.Commands.add('visitHome', () => {
+ cy.visit('/');
+ cy.get('button', { timeout: 30000 }).should('be.visible');
+})
+
+Cypress.Commands.add('resetState', () => {
+ cy.window().then(win => {
+ win.indexedDB.deleteDatabase('keyval-store');
+ });
+ cy.request('POST', '/api/reset-db', {}).as('reset');
+ cy.get('@reset').its('status').should('equal', 204);
+ cy.reload(true);
+});
+
+Cypress.Commands.add('registerUser', (username, password, isAdmin = false) => {
+ const route = isAdmin ? '/api/admin/accounts/create' : '/api/signup';
+
+ cy.request('POST', route, {
+ username: username,
+ password: password,
+ }).its('body').as(username);
+});
+
+Cypress.Commands.add('login', (username, password) => {
+ cy.visitHome();
+
+ cy.intercept('POST', '/api/signin').as('signin');
+
+ cy.get('[data-cy-signin]').click();
+ cy.get('[data-cy-signin-username] input').type(username);
+ cy.get('[data-cy-signin-password] input').type(`${password}{enter}`);
+
+ cy.wait('@signin').as('signedIn');
+});