2021-08-12 10:05:07 +00:00
|
|
|
// ***********************************************
|
|
|
|
// 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) => { ... })
|
2022-05-31 08:57:01 +00:00
|
|
|
|
2023-03-01 06:32:53 +00:00
|
|
|
Cypress.Commands.add('visitHome', () => {
|
|
|
|
cy.visit('/');
|
|
|
|
cy.get('button', { timeout: 30000 }).should('be.visible');
|
|
|
|
})
|
|
|
|
|
2022-05-31 08:57:01 +00:00
|
|
|
Cypress.Commands.add('resetState', () => {
|
2024-04-13 23:08:26 +00:00
|
|
|
// iframe.contentWindow.indexedDB.deleteDatabase() がchromeのバグで使用できないため、indexedDBを無効化している。
|
|
|
|
// see https://github.com/misskey-dev/misskey/issues/13605#issuecomment-2053652123
|
|
|
|
/*
|
2024-03-20 02:25:49 +00:00
|
|
|
cy.window().then(win => {
|
2022-05-31 08:57:01 +00:00
|
|
|
win.indexedDB.deleteDatabase('keyval-store');
|
|
|
|
});
|
2024-04-13 23:08:26 +00:00
|
|
|
*/
|
2022-12-19 06:15:28 +00:00
|
|
|
cy.request('POST', '/api/reset-db', {}).as('reset');
|
2022-05-31 08:57:01 +00:00
|
|
|
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,
|
2024-10-12 02:52:42 +00:00
|
|
|
...(isAdmin ? { setupPassword: 'example_password_please_change_this_or_you_will_get_hacked' } : {}),
|
2022-05-31 08:57:01 +00:00
|
|
|
}).its('body').as(username);
|
|
|
|
});
|
|
|
|
|
|
|
|
Cypress.Commands.add('login', (username, password) => {
|
2023-03-01 06:32:53 +00:00
|
|
|
cy.visitHome();
|
2022-05-31 08:57:01 +00:00
|
|
|
|
2024-10-12 02:52:42 +00:00
|
|
|
cy.intercept('POST', '/api/signin-flow').as('signin');
|
2022-05-31 08:57:01 +00:00
|
|
|
|
|
|
|
cy.get('[data-cy-signin]').click();
|
2024-10-12 02:52:42 +00:00
|
|
|
cy.get('[data-cy-signin-page-input]').should('be.visible', { timeout: 1000 });
|
|
|
|
cy.get('[data-cy-signin-username] input').type(`${username}{enter}`);
|
|
|
|
cy.get('[data-cy-signin-page-password]').should('be.visible', { timeout: 10000 });
|
2022-05-31 08:57:01 +00:00
|
|
|
cy.get('[data-cy-signin-password] input').type(`${password}{enter}`);
|
|
|
|
|
|
|
|
cy.wait('@signin').as('signedIn');
|
|
|
|
});
|