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.
73 lines
3.0 KiB
JavaScript
73 lines
3.0 KiB
JavaScript
const copyProperty = (to, from, property, ignoreNonConfigurable) => {
|
|
// `Function#length` should reflect the parameters of `to` not `from` since we keep its body.
|
|
// `Function#prototype` is non-writable and non-configurable so can never be modified.
|
|
if (property === 'length' || property === 'prototype') {
|
|
return;
|
|
}
|
|
|
|
// `Function#arguments` and `Function#caller` should not be copied. They were reported to be present in `Reflect.ownKeys` for some devices in React Native (#41), so we explicitly ignore them here.
|
|
if (property === 'arguments' || property === 'caller') {
|
|
return;
|
|
}
|
|
|
|
const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
|
|
const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
|
|
|
|
if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
|
|
return;
|
|
}
|
|
|
|
Object.defineProperty(to, property, fromDescriptor);
|
|
};
|
|
|
|
// `Object.defineProperty()` throws if the property exists, is not configurable and either:
|
|
// - one its descriptors is changed
|
|
// - it is non-writable and its value is changed
|
|
const canCopyProperty = function (toDescriptor, fromDescriptor) {
|
|
return toDescriptor === undefined || toDescriptor.configurable || (
|
|
toDescriptor.writable === fromDescriptor.writable
|
|
&& toDescriptor.enumerable === fromDescriptor.enumerable
|
|
&& toDescriptor.configurable === fromDescriptor.configurable
|
|
&& (toDescriptor.writable || toDescriptor.value === fromDescriptor.value)
|
|
);
|
|
};
|
|
|
|
const changePrototype = (to, from) => {
|
|
const fromPrototype = Object.getPrototypeOf(from);
|
|
if (fromPrototype === Object.getPrototypeOf(to)) {
|
|
return;
|
|
}
|
|
|
|
Object.setPrototypeOf(to, fromPrototype);
|
|
};
|
|
|
|
const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`;
|
|
|
|
const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString');
|
|
const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name');
|
|
|
|
// We call `from.toString()` early (not lazily) to ensure `from` can be garbage collected.
|
|
// We use `bind()` instead of a closure for the same reason.
|
|
// Calling `from.toString()` early also allows caching it in case `to.toString()` is called several times.
|
|
const changeToString = (to, from, name) => {
|
|
const withName = name === '' ? '' : `with ${name.trim()}() `;
|
|
const newToString = wrappedToString.bind(null, withName, from.toString());
|
|
// Ensure `to.toString.toString` is non-enumerable and has the same `same`
|
|
Object.defineProperty(newToString, 'name', toStringName);
|
|
const {writable, enumerable, configurable} = toStringDescriptor; // We destructue to avoid a potential `get` descriptor.
|
|
Object.defineProperty(to, 'toString', {value: newToString, writable, enumerable, configurable});
|
|
};
|
|
|
|
export default function mimicFunction(to, from, {ignoreNonConfigurable = false} = {}) {
|
|
const {name} = to;
|
|
|
|
for (const property of Reflect.ownKeys(from)) {
|
|
copyProperty(to, from, property, ignoreNonConfigurable);
|
|
}
|
|
|
|
changePrototype(to, from);
|
|
changeToString(to, from, name);
|
|
|
|
return to;
|
|
}
|