Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const memoizedTest = () => ({
- contextName, // Name of step & group of tests
- initialStateFn, // <- Fn that runs initial state tests of step
- interactionsFn, // <- Fn that runs behaviour and user interactions tests
- proceedFn, // <- Fn used to proceed to next step
- userCase, // Specific param to proceed to diferent ramifications of user cases
- }) => {
- // Initialize cached block
- localStorage.setObject(
- contextName,
- localStorage.getObject(contextName) || {},
- );
- // Use default if not an object, or a atribute key
- // generated like: ['key1:value1/key2:value2/key3:value3']
- const userCaseKey = typeof userCase !== 'object'
- ? (userCase || 'default')
- : Object.keys(userCase).map(key => `${key}:${userCase[key]}`).join('/');
- if (localStorage.getObject(contextName)[userCaseKey]) {
- // Finish this step without further testing
- proceedFn && context(`${contextName} - SKIPPING`, () => proceedFn(userCase));
- } else {
- const ucOrEmptyObj = userCase || {};
- context(contextName, () => {
- // Run all tests from step
- initialStateFn(ucOrEmptyObj);
- interactionsFn(ucOrEmptyObj);
- // And now, proceed to next step
- // unless it's the last step
- proceedFn && proceedFn(ucOrEmptyObj);
- });
- // Mark the tests as already run to avoid repeating
- localStorage.setObject(
- contextName,
- Object.assign(
- {},
- localStorage.getObject(contextName),
- { [userCaseKey]: true },
- ),
- );
- }
- };
- export const generateTest = memoizedTest();
Add Comment
Please, Sign In to add comment