| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // ***********************************************
- // 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('getByTestid', (selector, options?) => {
- return cy.get(`[data-testid=${selector}]`, options);
- });
- Cypress.Commands.add('login', (username, password) => {
- cy.session(username, () => {
- cy.visit('/page-to-return-after-login');
- cy.getByTestid('tiUsernameForLogin').type(username);
- cy.getByTestid('tiPasswordForLogin').type(password);
- cy.intercept('POST', '/_api/v3/login').as('login');
- cy.getByTestid('btnSubmitForLogin').click();
- cy.wait('@login')
- });
- });
- /**
- * use only for the pages which use component with skeleton
- */
- Cypress.Commands.add('waitUntilSkeletonDisappear', () => {
- cy.get('.grw-skeleton').should('exist');
- cy.get('.grw-skeleton').should('not.exist');
- });
- Cypress.Commands.add('waitUntilSpinnerDisappear', () => {
- cy.get('.fa-spinner').should('exist');
- cy.get('.fa-spinner').should('not.exist');
- });
- let isSidebarCollapsed: boolean | undefined;
- Cypress.Commands.add('collapseSidebar', (isCollapsed, force=false) => {
- if (!force && isSidebarCollapsed === isCollapsed) {
- return;
- }
- const isGrowiPage = Cypress.$('div.growi').length > 0;
- if (!isGrowiPage) {
- cy.visit('/page-to-toggle-sidebar-collapsed');
- }
- cy.getByTestid('grw-contextual-navigation-sub').then(($contents) => {
- const isCurrentCollapsed = $contents.hasClass('d-none');
- // toggle when the current state and isCoolapsed is not match
- if (isCurrentCollapsed !== isCollapsed) {
- cy.getByTestid("grw-navigation-resize-button").click({force: true});
- // wait until saving UserUISettings
- // eslint-disable-next-line cypress/no-unnecessary-waiting
- cy.wait(1500);
- }
- });
- isSidebarCollapsed = isCollapsed;
- });
|