Files
flights_web_raw/node_modules/chromium-bidi/lib/cjs/cdp/CdpConnection.js
T
gnezim 60e2149072 Add comprehensive e2e test suites for Tasks 16-25
Tasks 16-20: Online Board Tests (Search/Filter, Tabs, Flight List, Details Modal, Time/Date)
- Task 16: Search & Filter tests (37 tests) - departure/arrival cities, passenger count, cabin class
- Task 17: Arrival/Departure Tabs tests (45 tests) - tab switching, flight display, sorting
- Task 18: Flight List View tests (50 tests) - display, sorting, filtering, pagination, loading states
- Task 19: Flight Details Modal tests (40 tests) - opening/closing, content display, actions
- Task 20: Time & Date Filter tests (43 tests) - date selection, time ranges, calendar navigation

Tasks 21-25: Flight Details Tests (Flight Info, Passengers, Seats, Services, Fares)
- Task 21: Flight Info Display tests (40 tests) - basic info, airports, route visualization, timeline
- Task 22: Passenger Info tests (50 tests) - passenger list, details, services, special requirements
- Task 23: Seat Selection tests (50 tests) - seat map, selection, categories, recommendations
- Task 24: Service Selection tests (25 tests) - baggage, meals, seats, summary
- Task 25: Fare Display tests (55 tests) - fare breakdown, comparisons, discounts, refunds

All tests follow AAA pattern and use data-testid selectors matching Angular version.
Total: 245 tests across 10 feature suites.
2026-04-05 19:25:03 +03:00

125 lines
4.8 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MapperCdpConnection = void 0;
const log_js_1 = require("../utils/log.js");
const CdpClient_js_1 = require("./CdpClient.js");
/**
* Represents a high-level CDP connection to the browser backend.
*
* Manages all CdpClients (each backed by a Session ID) instance for each active
* CDP session.
*/
class MapperCdpConnection {
static LOGGER_PREFIX_RECV = `${log_js_1.LogType.cdp}:RECV ◂`;
static LOGGER_PREFIX_SEND = `${log_js_1.LogType.cdp}:SEND ▸`;
#mainBrowserCdpClient;
#transport;
/** Map from session ID to CdpClient.
* `undefined` points to the main browser session. */
#sessionCdpClients = new Map();
#commandCallbacks = new Map();
#logger;
#nextId = 0;
constructor(transport, logger) {
this.#transport = transport;
this.#logger = logger;
this.#transport.setOnMessage(this.#onMessage);
// Create default Browser CDP Session.
this.#mainBrowserCdpClient = this.#createCdpClient(undefined);
}
/** Closes the connection to the browser. */
close() {
this.#transport.close();
for (const [, { reject, error }] of this.#commandCallbacks) {
reject(error);
}
this.#commandCallbacks.clear();
this.#sessionCdpClients.clear();
}
async createBrowserSession() {
const { sessionId } = await this.#mainBrowserCdpClient.sendCommand('Target.attachToBrowserTarget');
return this.#createCdpClient(sessionId);
}
/**
* Gets a CdpClient instance attached to the given session ID,
* or null if the session is not attached.
*/
getCdpClient(sessionId) {
const cdpClient = this.#sessionCdpClients.get(sessionId);
if (!cdpClient) {
throw new Error(`Unknown CDP session ID: ${sessionId}`);
}
return cdpClient;
}
sendCommand(method, params, sessionId) {
return new Promise((resolve, reject) => {
const id = this.#nextId++;
this.#commandCallbacks.set(id, {
resolve,
reject,
error: new CdpClient_js_1.CloseError(`${method} ${JSON.stringify(params)} ${sessionId ?? ''} call rejected because the connection has been closed.`),
});
const cdpMessage = { id, method, params };
if (sessionId) {
cdpMessage.sessionId = sessionId;
}
void this.#transport
.sendMessage(JSON.stringify(cdpMessage))
?.catch((error) => {
this.#logger?.(log_js_1.LogType.debugError, error);
this.#transport.close();
});
this.#logger?.(MapperCdpConnection.LOGGER_PREFIX_SEND, cdpMessage);
});
}
#onMessage = (json) => {
const message = JSON.parse(json);
this.#logger?.(MapperCdpConnection.LOGGER_PREFIX_RECV, message);
// Update client map if a session is attached
// Listen for these events on every session.
if (message.method === 'Target.attachedToTarget') {
const { sessionId } = message.params;
this.#createCdpClient(sessionId);
}
if (message.id !== undefined) {
// Handle command response.
const callbacks = this.#commandCallbacks.get(message.id);
this.#commandCallbacks.delete(message.id);
if (callbacks) {
if (message.result) {
callbacks.resolve(message.result);
}
else if (message.error) {
callbacks.reject(message.error);
}
}
}
else if (message.method) {
const client = this.#sessionCdpClients.get(message.sessionId ?? undefined);
client?.emit(message.method, message.params || {});
// Update client map if a session is detached
// But emit on that session
if (message.method === 'Target.detachedFromTarget') {
const { sessionId } = message.params;
const client = this.#sessionCdpClients.get(sessionId);
if (client) {
this.#sessionCdpClients.delete(sessionId);
client.removeAllListeners();
}
}
}
};
/**
* Creates a new CdpClient instance for the given session ID.
* @param sessionId either a string, or undefined for the main browser session.
* The main browser session is used only to create new browser sessions.
* @private
*/
#createCdpClient(sessionId) {
const cdpClient = new CdpClient_js_1.MapperCdpClient(this, sessionId);
this.#sessionCdpClients.set(sessionId, cdpClient);
return cdpClient;
}
}
exports.MapperCdpConnection = MapperCdpConnection;
//# sourceMappingURL=CdpConnection.js.map