wisemapping-frontend/packages/editor/cypress/support/commands.ts

78 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-01-15 09:10:27 +01:00
/* eslint-disable @typescript-eslint/no-namespace */
2023-01-15 08:04:33 +01:00
/// <reference types="cypress" />
import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';
2023-01-15 09:10:27 +01:00
declare global {
namespace Cypress {
interface Chainable {
waitForLoad(): void;
waitEditorLoaded(): void;
imageSnaphots(): void;
focusTopicByText(value: string): void;
focusTopicById(id: number): void;
onMouseOverToolbarButton(value: 'Topic Style' | 'Font Style'): void;
onClickToolbarButton(value: 'Add Relationship' | 'Add Icon'): void;
triggerUndo(): void;
triggerRedo(): void;
}
}
}
// make matchImageSnapshot() call the real implementation only if CYPRESS_imageSnaphots is set
// otherwise it calls a noop
if (Cypress.env('imageSnaphots')) {
addMatchImageSnapshotCommand({
failureThreshold: 0.001,
failureThresholdType: 'percent',
});
} else {
Cypress.Commands.add(
'matchImageSnapshot',
{
prevSubject: ['optional', 'element', 'window', 'document'],
},
() => Promise.resolve(),
);
}
2023-01-15 08:04:33 +01:00
Cypress.Commands.add('waitEditorLoaded', () => {
// Wait editor ...
cy.get('svg > path').should('be.visible');
cy.get('[aria-label="vortex-loading"]', { timeout: 120000 }).should('not.exist');
cy.clearLocalStorage('welcome-xml');
// Wait for font ...
cy.document().its('fonts.status').should('equal', 'loaded');
});
Cypress.Commands.add('waitForLoad', () => {
cy.document().its('fonts.status').should('equal', 'loaded');
});
// Mindmap commands ...
2023-01-15 09:10:27 +01:00
Cypress.Commands.add('focusTopicById', (id: number) => {
2023-01-15 08:04:33 +01:00
cy.get(`[test-id=${id}]`).click();
});
2023-01-15 09:10:27 +01:00
Cypress.Commands.add('focusTopicByText', (text: string) => {
2023-01-15 08:04:33 +01:00
cy.contains(text).click({ force: true });
});
2023-01-15 09:10:27 +01:00
Cypress.Commands.add('onMouseOverToolbarButton', (button: 'Topic Style' | 'Font Style') => {
cy.get(`[aria-label="${button}"]`).first().trigger('mouseover');
});
Cypress.Commands.add('onClickToolbarButton', (button: 'Add Relationship' | 'Add Icon') => {
cy.get(`[aria-label="${button}"]`).click({ multiple: true, force: true });
});
Cypress.Commands.add('triggerUndo', () => {
cy.get('[aria-label^="Undo ').eq(1).click();
});
Cypress.Commands.add('triggerRedo', () => {
cy.get('[aria-label^="Redo ').eq(1).click();
});