105 lines
3.4 KiB
TypeScript
105 lines
3.4 KiB
TypeScript
/// <reference types="." />
|
|
|
|
/**
|
|
* Custom Cypress commands for Aeroflot Flights Web testing
|
|
*/
|
|
|
|
Cypress.Commands.add('getByTestId', (id: string, timeout = 8000) => {
|
|
return cy.get(`[data-testid="${id}"]`, { timeout });
|
|
});
|
|
|
|
Cypress.Commands.add('mockGeolocation', ({ latitude, longitude }) => {
|
|
cy.on('window:before:load', (window) => {
|
|
const callback = (cb) => {
|
|
return cb({ coords: { latitude, longitude } });
|
|
};
|
|
|
|
cy.stub(window.navigator.geolocation, 'getCurrentPosition').callsFake(callback);
|
|
|
|
cy.stub(window.navigator.geolocation, 'watchPosition').callsFake(callback);
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('forbidGeolocation', () => {
|
|
cy.on('window:before:load', (window) => {
|
|
const callback = (_, error) => {
|
|
return error({});
|
|
};
|
|
|
|
cy.stub(window.navigator.geolocation, 'getCurrentPosition').callsFake(callback);
|
|
|
|
cy.stub(window.navigator.geolocation, 'watchPosition').callsFake(callback);
|
|
});
|
|
});
|
|
|
|
// Select arrival city by name
|
|
Cypress.Commands.add('selectArrivalCity', (cityName: string) => {
|
|
cy.getByTestId('city-autocomplete-input-arrival').clear().type(cityName);
|
|
cy.getByTestId('city-dropdown-option').contains(cityName).click();
|
|
});
|
|
|
|
// Select departure city by name
|
|
Cypress.Commands.add('selectDepartureCity', (cityName: string) => {
|
|
cy.getByTestId('city-autocomplete-input-departure').clear().type(cityName);
|
|
cy.getByTestId('city-dropdown-option').contains(cityName).click();
|
|
});
|
|
|
|
// Set arrival date using date picker
|
|
Cypress.Commands.add('setArrivalDate', (date: string) => {
|
|
cy.getByTestId('arrival-date-input').clear().type(date).type('{enter}');
|
|
});
|
|
|
|
// Set departure date using date picker
|
|
Cypress.Commands.add('setDepartureDate', (date: string) => {
|
|
cy.getByTestId('departure-date-input').clear().type(date).type('{enter}');
|
|
});
|
|
|
|
// Click search button
|
|
Cypress.Commands.add('clickSearchButton', () => {
|
|
cy.getByTestId('search-button').click();
|
|
});
|
|
|
|
// Get all flight results
|
|
Cypress.Commands.add('getFlightResults', () => {
|
|
return cy.getByTestId('flight-result');
|
|
});
|
|
|
|
// Get first flight result
|
|
Cypress.Commands.add('getFirstFlightResult', () => {
|
|
return cy.getByTestId('flight-result').first();
|
|
});
|
|
|
|
// Assert validation error is displayed
|
|
Cypress.Commands.add('shouldShowValidationError', (message: string) => {
|
|
cy.getByTestId('validation-error').should('contain', message);
|
|
});
|
|
|
|
// Select language by code
|
|
Cypress.Commands.add('selectLanguage', (langCode: string) => {
|
|
cy.getByTestId('language-selector').click();
|
|
cy.getByTestId(`language-option-${langCode}`).click();
|
|
});
|
|
|
|
// Get current language
|
|
Cypress.Commands.add('getCurrentLanguage', () => {
|
|
return cy.getByTestId('language-selector').invoke('text');
|
|
});
|
|
|
|
// Swipe right (for mobile navigation)
|
|
Cypress.Commands.add('swipeRight', { prevSubject: 'element' }, (subject) => {
|
|
cy.wrap(subject)
|
|
.trigger('touchstart', { which: 1, pageX: 0, pageY: 0 })
|
|
.trigger('touchmove', { which: 1, pageX: 100, pageY: 0 })
|
|
.trigger('touchend', { which: 1, pageX: 100, pageY: 0 });
|
|
return cy.wrap(subject);
|
|
});
|
|
|
|
// Swipe left (for mobile navigation)
|
|
Cypress.Commands.add('swipeLeft', { prevSubject: 'element' }, (subject) => {
|
|
cy.wrap(subject)
|
|
.trigger('touchstart', { which: 1, pageX: 100, pageY: 0 })
|
|
.trigger('touchmove', { which: 1, pageX: 0, pageY: 0 })
|
|
.trigger('touchend', { which: 1, pageX: 0, pageY: 0 });
|
|
return cy.wrap(subject);
|
|
});
|