Guest User

Untitled

a guest
Nov 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. const memoizedTest = () => ({
  2. contextName, // Name of step & group of tests
  3. initialStateFn, // <- Fn that runs initial state tests of step
  4. interactionsFn, // <- Fn that runs behaviour and user interactions tests
  5. proceedFn, // <- Fn used to proceed to next step
  6. userCase, // Specific param to proceed to diferent ramifications of user cases
  7. }) => {
  8. // Initialize cached block
  9. localStorage.setObject(
  10. contextName,
  11. localStorage.getObject(contextName) || {},
  12. );
  13. // Use default if not an object, or a atribute key
  14. // generated like: ['key1:value1/key2:value2/key3:value3']
  15. const userCaseKey = typeof userCase !== 'object'
  16. ? (userCase || 'default')
  17. : Object.keys(userCase).map(key => `${key}:${userCase[key]}`).join('/');
  18.  
  19. if (localStorage.getObject(contextName)[userCaseKey]) {
  20. // Finish this step without further testing
  21. proceedFn && context(`${contextName} - SKIPPING`, () => proceedFn(userCase));
  22. } else {
  23. const ucOrEmptyObj = userCase || {};
  24. context(contextName, () => {
  25. // Run all tests from step
  26. initialStateFn(ucOrEmptyObj);
  27. interactionsFn(ucOrEmptyObj);
  28. // And now, proceed to next step
  29. // unless it's the last step
  30. proceedFn && proceedFn(ucOrEmptyObj);
  31. });
  32. // Mark the tests as already run to avoid repeating
  33. localStorage.setObject(
  34. contextName,
  35. Object.assign(
  36. {},
  37. localStorage.getObject(contextName),
  38. { [userCaseKey]: true },
  39. ),
  40. );
  41. }
  42. };
  43.  
  44.  
  45. export const generateTest = memoizedTest();
Add Comment
Please, Sign In to add comment