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.
114 lines
4.2 KiB
JavaScript
114 lines
4.2 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.useTranslation = useTranslation;
|
|
var _react = require("react");
|
|
var _context = require("./context.js");
|
|
var _utils = require("./utils.js");
|
|
const usePrevious = (value, ignore) => {
|
|
const ref = (0, _react.useRef)();
|
|
(0, _react.useEffect)(() => {
|
|
ref.current = ignore ? ref.current : value;
|
|
}, [value, ignore]);
|
|
return ref.current;
|
|
};
|
|
function useTranslation(ns) {
|
|
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
const {
|
|
i18n: i18nFromProps
|
|
} = props;
|
|
const {
|
|
i18n: i18nFromContext,
|
|
defaultNS: defaultNSFromContext
|
|
} = (0, _react.useContext)(_context.I18nContext) || {};
|
|
const i18n = i18nFromProps || i18nFromContext || (0, _context.getI18n)();
|
|
if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new _context.ReportNamespaces();
|
|
if (!i18n) {
|
|
(0, _utils.warnOnce)('You will need to pass in an i18next instance by using initReactI18next');
|
|
const notReadyT = (k, optsOrDefaultValue) => {
|
|
if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
|
|
if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
|
|
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
};
|
|
const retNotReady = [notReadyT, {}, false];
|
|
retNotReady.t = notReadyT;
|
|
retNotReady.i18n = {};
|
|
retNotReady.ready = false;
|
|
return retNotReady;
|
|
}
|
|
if (i18n.options.react && i18n.options.react.wait !== undefined) (0, _utils.warnOnce)('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
|
|
const i18nOptions = {
|
|
...(0, _context.getDefaults)(),
|
|
...i18n.options.react,
|
|
...props
|
|
};
|
|
const {
|
|
useSuspense,
|
|
keyPrefix
|
|
} = i18nOptions;
|
|
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => (0, _utils.hasLoadedNamespace)(n, i18n, i18nOptions));
|
|
function getT() {
|
|
return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
}
|
|
const [t, setT] = (0, _react.useState)(getT);
|
|
let joinedNS = namespaces.join();
|
|
if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
|
|
const previousJoinedNS = usePrevious(joinedNS);
|
|
const isMounted = (0, _react.useRef)(true);
|
|
(0, _react.useEffect)(() => {
|
|
const {
|
|
bindI18n,
|
|
bindI18nStore
|
|
} = i18nOptions;
|
|
isMounted.current = true;
|
|
if (!ready && !useSuspense) {
|
|
if (props.lng) {
|
|
(0, _utils.loadLanguages)(i18n, props.lng, namespaces, () => {
|
|
if (isMounted.current) setT(getT);
|
|
});
|
|
} else {
|
|
(0, _utils.loadNamespaces)(i18n, namespaces, () => {
|
|
if (isMounted.current) setT(getT);
|
|
});
|
|
}
|
|
}
|
|
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
setT(getT);
|
|
}
|
|
function boundReset() {
|
|
if (isMounted.current) setT(getT);
|
|
}
|
|
if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
|
|
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
|
|
return () => {
|
|
isMounted.current = false;
|
|
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
|
|
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
|
|
};
|
|
}, [i18n, joinedNS]);
|
|
const isInitial = (0, _react.useRef)(true);
|
|
(0, _react.useEffect)(() => {
|
|
if (isMounted.current && !isInitial.current) {
|
|
setT(getT);
|
|
}
|
|
isInitial.current = false;
|
|
}, [i18n, keyPrefix]);
|
|
const ret = [t, i18n, ready];
|
|
ret.t = t;
|
|
ret.i18n = i18n;
|
|
ret.ready = ready;
|
|
if (ready) return ret;
|
|
if (!ready && !useSuspense) return ret;
|
|
throw new Promise(resolve => {
|
|
if (props.lng) {
|
|
(0, _utils.loadLanguages)(i18n, props.lng, namespaces, () => resolve());
|
|
} else {
|
|
(0, _utils.loadNamespaces)(i18n, namespaces, () => resolve());
|
|
}
|
|
});
|
|
} |