diff --git a/e2e/cypress.config.ts b/e2e/cypress.config.ts new file mode 100644 index 000000000..a01facfd6 --- /dev/null +++ b/e2e/cypress.config.ts @@ -0,0 +1,22 @@ +import { defineConfig } from 'cypress' + +export default defineConfig({ + e2e: { + baseUrl: 'http://localhost:3000', + supportFile: 'cypress/support/index.ts', + specPattern: 'cypress/integration/**/*.cy.ts', + viewportWidth: 1440, + viewportHeight: 900, + video: false, + screenshotOnRunFailure: true, + requestTimeout: 10000, + responseTimeout: 10000, + defaultCommandTimeout: 10000, + }, + component: { + devServer: { + framework: 'react', + bundler: 'vite', + }, + }, +}) diff --git a/e2e/cypress/support/commands.ts b/e2e/cypress/support/commands.ts new file mode 100644 index 000000000..22b27be59 --- /dev/null +++ b/e2e/cypress/support/commands.ts @@ -0,0 +1,24 @@ +/// + +Cypress.Commands.add('getByTestId', (id: string, timeout = 8000) => { + return cy.get(`[data-testid="${id}"]`, { timeout }) +}) + +Cypress.Commands.add('forbidGeolocation', () => { + cy.window().then(win => { + cy.stub(win.navigator.geolocation, 'getCurrentPosition').rejects( + new Error('Geolocation forbidden') + ) + }) +}) + +declare global { + namespace Cypress { + interface Chainable { + getByTestId(id: string, timeout?: number): Chainable> + forbidGeolocation(): Chainable + } + } +} + +export {} diff --git a/e2e/cypress/support/index.ts b/e2e/cypress/support/index.ts new file mode 100644 index 000000000..b6ed48891 --- /dev/null +++ b/e2e/cypress/support/index.ts @@ -0,0 +1,15 @@ +import './commands' + +beforeEach(() => { + // Clear localStorage before each test + cy.window().then(win => { + win.localStorage.clear() + }) +}) + +afterEach(() => { + // Clean up after each test + cy.window().then(win => { + win.localStorage.clear() + }) +}) diff --git a/e2e/package.json b/e2e/package.json new file mode 100644 index 000000000..6f4ffb519 --- /dev/null +++ b/e2e/package.json @@ -0,0 +1,18 @@ +{ + "name": "@aeroflot-flights/e2e", + "version": "1.0.0", + "private": true, + "scripts": { + "cypress:open": "cypress open", + "cypress:run": "cypress run", + "backstop:reference": "backstop reference --config=backstop/backstop-angular.json", + "backstop:test": "backstop test --config=backstop/backstop-react.json", + "validate": "bash ../scripts/full-validation.sh" + }, + "devDependencies": { + "cypress": "^13.6.0", + "backstopjs": "^6.3.0", + "@cypress/schematic": "^2.5.0", + "typescript": "^5.3.0" + } +} diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json new file mode 100644 index 000000000..0ddfa72f2 --- /dev/null +++ b/e2e/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ES2020", + "lib": ["ES2020", "DOM"], + "module": "ESNext", + "moduleResolution": "node", + "strict": true, + "resolveJsonModule": true, + "types": ["cypress", "node"] + }, + "include": ["cypress/**/*.ts", "cypress/**/*.tsx"] +}