Files
flights_web/tests/e2e-angular/QUICK_REFERENCE.md
T
gnezim 375bcfb0fa Add e2e test suite from flights-front with Angular API mocks
Copies Playwright e2e tests (58 specs, 300+ tests) designed for cross-app
testing. Adapts API mocks to match real Aeroflot dictionary format (title
objects with multilingual keys), adds board/schedule/days endpoint mocks,
and provides Angular-specific Playwright config on port 4203.
2026-04-15 23:07:44 +03:00

4.8 KiB

E2E Test Utilities Quick Reference

Test Utilities (e2e/support/test-utilities.ts)

Data Generators

// Generate a single flight
generateFlight({
  direction: 'departure' | 'arrival',
  cityCode: 'MOW',
  status: 'scheduled' | 'boarding' | 'departed' | 'arrived' | 'delayed' | 'cancelled',
  date: '2026-04-06',
});

// Generate multiple flights
generateFlights(20, { direction: 'departure', cityCode: 'MOW' });

// Generate schedule entry
generateScheduleEntry({
  from: 'MOW',
  to: 'AER',
  dateFrom: '2026-04-06',
  dateTo: '2026-04-12',
  direct: true,
});

// Generate schedule entries
generateScheduleEntries(50);

// Generate destination
generateDestination({
  departureCity: 'MOW',
  arrivalCity: 'AER',
  flightCount: 45,
  dates: ['2026-04-06', '2026-04-07'],
});

// Generate destinations
generateDestinations(20);

Constants

CITIES; // 20 cities with codes
AIRPORTS; // 10+ airports
FLIGHT_NUMBERS; // 20 flight numbers
AIRLINE_CODES; // ['SU', 'FV']
AIRLINE_NAMES; // { SU: 'Aeroflot', FV: 'Rossiya' }
AIRCRAFT_TYPES; // 7 aircraft types
STATUS_TYPES; // 10 flight statuses

URL Helpers

buildRouteParam('MOW', '2026-04-06'); // 'MOW-20260406'
buildOnlineBoardPath('departure', 'MOW', '2026-04-06'); // '/onlineboard/departure/MOW-20260406'
buildSchedulePath(); // '/schedule'
buildFlightsMapPath(); // '/flights-map'
buildFlightDetailsPath('SU 1124', '2026-04-06'); // '/SU1124-20260406'

Search Helpers

searchFlightByNumber(page, 'SU 1124', '2026-04-06');
searchFlightByRoute(page, 'Moscow', 'Sochi', '2026-04-06');
searchFlightByDate(page, '2026-04-06');
openFlightDetails(page, 0);

Assertion Helpers

expectUrlToMatch(page, /pattern/);
expectElementToBeVisible(locator);
expectElementToBeHidden(locator);
expectElementToHaveText(locator, 'text');
expectElementToContainText(locator, 'text');
expectElementToHaveAttribute(locator, 'attr', 'value');
expectElementToHaveClass(locator, 'class');
expectElementToBeEnabled(locator);
expectElementToBeDisabled(locator);
expectElementToBeChecked(locator);
expectElementToBeUnchecked(locator);
expectElementToHaveValue(locator, 'value');
expectElementToHaveCount(locator, 5);
expectElementToBeFocused(locator);
expectElementNotToBeFocused(locator);

Date Helpers

getToday(); // '2026-04-06'
getTomorrow(); // '2026-04-07'
getYesterday(); // '2026-04-05'
getFutureDate(7); // '2026-04-13'
getPastDate(7); // '2026-03-30'
formatDateForUrl(date);
formatDateForDisplay(date, 'ru');

Error Generators

generateNotFoundError(); // 404
generateBadRequestError(); // 400
generateUnauthorizedError(); // 401
generateForbiddenError(); // 403
generateServerError(); // 500
generateTimeoutError(); // 504

Fixtures

cities.json

{
  "code": "MOW",
  "name": "Moscow",
  "nameRu": "Москва",
  "latitude": 55.7558,
  "longitude": 37.6173,
  "country": "Russia",
  "countryCode": "RU"
}

flights.json

{
  "flights": {
    "domestic": { ... },
    "international": { ... },
    "scheduled": { ... },
    "arrived": { ... },
    "delayed": { ... },
    "cancelled": { ... }
  }
}

routes.json

{
  "routes": {
    "moscow-sochi": {
      "departure": "MOW",
      "arrival": "AER",
      "duration": "2h 15m",
      "flights": [ ... ]
    }
  }
}

api-responses.json

Complete API response templates for all endpoints.

errors.json

Error response examples for all HTTP status codes.

Templates

8 template files in e2e/integration/templates/:

  1. online-board-arrival.template.ts - 40+ tests
  2. online-board-departure.template.ts - 40+ tests
  3. online-board-route.template.ts - 35+ tests
  4. online-board-flight.template.ts - 45+ tests
  5. schedule-search.template.ts - 30+ tests
  6. flight-details.template.ts - 40+ tests
  7. flights-map.template.ts - 30+ tests
  8. popular-requests.template.ts - 30+ tests

Total: 300+ tests

Usage Example

import { test, expect } from '@playwright/test';
import {
  generateFlight,
  generateFlights,
  getToday,
  searchFlightByNumber,
  verifyFlightCard,
} from '@e2e/support/test-utilities';

test('should display flight board', async ({ page }) => {
  const today = getToday();
  await page.goto(`/ru-ru/onlineboard/departure/MOW-${today.replace(/-/g, '')}`);
  await page.waitForLoadState('networkidle');

  const flight = generateFlight({ direction: 'departure', cityCode: 'MOW' });
  await searchFlightByNumber(page, flight.flightNumber);
  await verifyFlightCard(page, flight);
});

Running Tests

pnpm e2e                          # Run all tests
pnpm e2e -- tests/landing.spec.ts # Run specific test
pnpm e2e --headless               # Run headless
pnpm e2e --ui                     # Run with UI
pnpm e2e --trace on               # Run with trace