Files
flights_web_raw/node_modules/enquirer/lib/prompts/select.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

140 lines
3.8 KiB
JavaScript

'use strict';
const ArrayPrompt = require('../types/array');
const utils = require('../utils');
class SelectPrompt extends ArrayPrompt {
constructor(options) {
super(options);
this.emptyError = this.options.emptyError || 'No items were selected';
}
async dispatch(s, key) {
if (this.multiple) {
return this[key.name] ? await this[key.name](s, key) : await super.dispatch(s, key);
}
this.alert();
}
separator() {
if (this.options.separator) return super.separator();
let sep = this.styles.muted(this.symbols.ellipsis);
return this.state.submitted ? super.separator() : sep;
}
pointer(choice, i) {
return (!this.multiple || this.options.pointer) ? super.pointer(choice, i) : '';
}
indicator(choice, i) {
return this.multiple ? super.indicator(choice, i) : '';
}
choiceMessage(choice, i) {
let message = this.resolve(choice.message, this.state, choice, i);
if (choice.role === 'heading' && !utils.hasColor(message)) {
message = this.styles.strong(message);
}
return this.resolve(message, this.state, choice, i);
}
choiceSeparator() {
return ':';
}
async renderChoice(choice, i) {
await this.onChoice(choice, i);
let focused = this.index === i;
let pointer = await this.pointer(choice, i);
let check = await this.indicator(choice, i) + (choice.pad || '');
let hint = await this.resolve(choice.hint, this.state, choice, i);
if (hint && !utils.hasColor(hint)) {
hint = this.styles.muted(hint);
}
let ind = this.indent(choice);
let msg = await this.choiceMessage(choice, i);
let line = () => [this.margin[3], ind + pointer + check, msg, this.margin[1], hint].filter(Boolean).join(' ');
if (choice.role === 'heading') {
return line();
}
if (choice.disabled) {
if (!utils.hasColor(msg)) {
msg = this.styles.disabled(msg);
}
return line();
}
if (focused) {
msg = this.styles.em(msg);
}
return line();
}
async renderChoices() {
if (this.state.loading === 'choices') {
return this.styles.warning('Loading choices');
}
if (this.state.submitted) return '';
let choices = this.visible.map(async(ch, i) => await this.renderChoice(ch, i));
let visible = await Promise.all(choices);
if (!visible.length) visible.push(this.styles.danger('No matching choices'));
let result = this.margin[0] + visible.join('\n');
let header;
if (this.options.choicesHeader) {
header = await this.resolve(this.options.choicesHeader, this.state);
}
return [header, result].filter(Boolean).join('\n');
}
format() {
if (!this.state.submitted || this.state.cancelled) return '';
if (Array.isArray(this.selected)) {
return this.selected.map(choice => this.styles.primary(choice.name)).join(', ');
}
return this.styles.primary(this.selected.name);
}
async render() {
let { submitted, size } = this.state;
let prompt = '';
let header = await this.header();
let prefix = await this.prefix();
let separator = await this.separator();
let message = await this.message();
if (this.options.promptLine !== false) {
prompt = [prefix, message, separator, ''].join(' ');
this.state.prompt = prompt;
}
let output = await this.format();
let help = (await this.error()) || (await this.hint());
let body = await this.renderChoices();
let footer = await this.footer();
if (output) prompt += output;
if (help && !prompt.includes(help)) prompt += ' ' + help;
if (submitted && !output && !body.trim() && this.multiple && this.emptyError != null) {
prompt += this.styles.danger(this.emptyError);
}
this.clear(size);
this.write([header, prompt, body, footer].filter(Boolean).join('\n'));
this.write(this.margin[2]);
this.restore();
}
}
module.exports = SelectPrompt;