60e2149072
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.
110 lines
2.2 KiB
JavaScript
110 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
const BooleanPrompt = require('../types/boolean');
|
|
|
|
class TogglePrompt extends BooleanPrompt {
|
|
async initialize() {
|
|
await super.initialize();
|
|
this.value = this.initial = this.resolve(this.options.initial);
|
|
this.disabled = this.options.disabled || 'no';
|
|
this.enabled = this.options.enabled || 'yes';
|
|
await this.render();
|
|
}
|
|
|
|
reset() {
|
|
this.value = this.initial;
|
|
this.render();
|
|
}
|
|
|
|
delete() {
|
|
this.alert();
|
|
}
|
|
|
|
toggle() {
|
|
this.value = !this.value;
|
|
this.render();
|
|
}
|
|
|
|
enable() {
|
|
if (this.value === true) return this.alert();
|
|
this.value = true;
|
|
this.render();
|
|
}
|
|
disable() {
|
|
if (this.value === false) return this.alert();
|
|
this.value = false;
|
|
this.render();
|
|
}
|
|
|
|
up() {
|
|
this.toggle();
|
|
}
|
|
down() {
|
|
this.toggle();
|
|
}
|
|
right() {
|
|
this.toggle();
|
|
}
|
|
left() {
|
|
this.toggle();
|
|
}
|
|
next() {
|
|
this.toggle();
|
|
}
|
|
prev() {
|
|
this.toggle();
|
|
}
|
|
|
|
dispatch(ch = '', key) {
|
|
switch (ch.toLowerCase()) {
|
|
case ' ':
|
|
return this.toggle();
|
|
case '1':
|
|
case 'y':
|
|
case 't':
|
|
return this.enable();
|
|
case '0':
|
|
case 'n':
|
|
case 'f':
|
|
return this.disable();
|
|
default: {
|
|
return this.alert();
|
|
}
|
|
}
|
|
}
|
|
|
|
format() {
|
|
let active = str => this.styles.primary.underline(str);
|
|
let value = [
|
|
this.value ? this.disabled : active(this.disabled),
|
|
this.value ? active(this.enabled) : this.enabled
|
|
];
|
|
return value.join(this.styles.muted(' / '));
|
|
}
|
|
|
|
async render() {
|
|
let { size } = this.state;
|
|
|
|
let header = await this.header();
|
|
let prefix = await this.prefix();
|
|
let separator = await this.separator();
|
|
let message = await this.message();
|
|
|
|
let output = await this.format();
|
|
let help = (await this.error()) || (await this.hint());
|
|
let footer = await this.footer();
|
|
|
|
let prompt = [prefix, message, separator, output].join(' ');
|
|
this.state.prompt = prompt;
|
|
|
|
if (help && !prompt.includes(help)) prompt += ' ' + help;
|
|
|
|
this.clear(size);
|
|
this.write([header, prompt, footer].filter(Boolean).join('\n'));
|
|
this.write(this.margin[2]);
|
|
this.restore();
|
|
}
|
|
}
|
|
|
|
module.exports = TogglePrompt;
|