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.
96 lines
2.6 KiB
JavaScript
96 lines
2.6 KiB
JavaScript
import { createStore } from 'redux';
|
|
import rootReducer from './reducers';
|
|
|
|
/**
|
|
* Parses a JSON string from local storage and handles any errors.
|
|
*
|
|
* This function attempts to parse a JSON string provided in `localStorageItem`.
|
|
* If the parsing fails (typically due to corrupt or invalid JSON data),
|
|
* it logs the error, warns the user, and removes the corrupted item from
|
|
* local storage. If parsing is successful, it returns the parsed object.
|
|
* In the case of an error, it returns `false`.
|
|
*
|
|
* @param {string} localStorageItem - The JSON string to parse, typically retrieved from local storage.
|
|
* @returns {object|boolean} The parsed JSON object, or `false` if settings aren't set or parsing fails.
|
|
*/
|
|
function parseLocalStorage (localStorageItem) {
|
|
let data;
|
|
try {
|
|
data = JSON.parse(localStorageItem);
|
|
} catch (error) {
|
|
console.error(error);
|
|
console.warn('BackstopJS LocalStorage settings appear to be corrupted. Let me fix that for you.');
|
|
localStorage.removeItem('backstopjs');
|
|
data = false;
|
|
}
|
|
return data;
|
|
}
|
|
|
|
/**
|
|
* Retrieves the state from local storage, if available.
|
|
* @returns {object|boolean} The persisted state object or false if not available.
|
|
*/
|
|
const localState = localStorage.getItem('backstopjs');
|
|
const persistedState = localState
|
|
? parseLocalStorage(localState)
|
|
: false;
|
|
|
|
/**
|
|
* Default state for the Redux store.
|
|
*/
|
|
const defaultState = {
|
|
suiteInfo: {
|
|
testSuiteName: window.tests.testSuite,
|
|
idConfig: window.tests.id
|
|
},
|
|
tests: {
|
|
all: window.tests.tests,
|
|
filtered: window.tests.tests,
|
|
filterStatus: 'all'
|
|
},
|
|
scrubber: {
|
|
visible: false,
|
|
mode: 'scrub',
|
|
test: {}
|
|
},
|
|
layoutSettings: {
|
|
textInfo: false,
|
|
refImage: true,
|
|
testImage: true,
|
|
diffImage: true
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Merges persisted state with default state if available, otherwise uses default state.
|
|
*/
|
|
const state = persistedState
|
|
? {
|
|
...defaultState,
|
|
...persistedState
|
|
}
|
|
: defaultState;
|
|
|
|
/**
|
|
* Creates the Redux store with root reducer, initial state, and devtools extension.
|
|
* TODO: Consider using Redux Toolkit for more efficient and modern state management.
|
|
*/
|
|
const store = createStore(
|
|
rootReducer,
|
|
state,
|
|
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
|
|
);
|
|
|
|
/**
|
|
* Subscribes to store changes to persist layout settings in local storage.
|
|
*/
|
|
store.subscribe(function () {
|
|
const layoutSettings = store.getState().layoutSettings;
|
|
const localStateItems = JSON.stringify({
|
|
layoutSettings
|
|
});
|
|
localStorage.setItem('backstopjs', localStateItems);
|
|
});
|
|
|
|
export default store;
|