From e8638de926f8011f50900bf4b746cae711955eb5 Mon Sep 17 00:00:00 2001 From: Abdallah Date: Thu, 3 Jun 2021 17:13:03 +0200 Subject: [PATCH] test: redirect url in local storage --- cypress/integration/authentication.spec.js | 45 ++++++++++++++++++++++ cypress/support/commands.js | 1 + cypress/support/constants.js | 2 + package.json | 1 + yarn.lock | 5 +++ 5 files changed, 54 insertions(+) diff --git a/cypress/integration/authentication.spec.js b/cypress/integration/authentication.spec.js index a41c8c9b2..6c4c16ebd 100644 --- a/cypress/integration/authentication.spec.js +++ b/cypress/integration/authentication.spec.js @@ -1,6 +1,8 @@ import { buildItemPath, HOME_PATH, + ITEMS_PATH, + REDIRECT_PATH, SHARED_ITEMS_PATH, } from '../../src/config/paths'; import { @@ -15,7 +17,9 @@ import { REQUEST_FAILURE_LOADING_TIME, PAGE_LOAD_WAITING_PAUSE, REDIRECTION_CONTENT, + REDIRECTION_TIME, } from '../support/constants'; +import { REDIRECT_URL_LOCAL_STORAGE_KEY } from '../../src/config/constants'; describe('Authentication', () => { describe('Signed Off > Redirect to sign in route', () => { @@ -25,11 +29,19 @@ describe('Authentication', () => { it('Home', () => { cy.visit(HOME_PATH); cy.wait(REQUEST_FAILURE_LOADING_TIME); + cy.getLocalStorage(REDIRECT_URL_LOCAL_STORAGE_KEY).should( + 'equal', + HOME_PATH, + ); cy.get('html').should('contain', REDIRECTION_CONTENT); }); it('Shared Items', () => { cy.visit(SHARED_ITEMS_PATH); cy.wait(REQUEST_FAILURE_LOADING_TIME); + cy.getLocalStorage(REDIRECT_URL_LOCAL_STORAGE_KEY).should( + 'equal', + SHARED_ITEMS_PATH, + ); cy.get('html').should('contain', REDIRECTION_CONTENT); }); }); @@ -73,5 +85,38 @@ describe('Authentication', () => { cy.get(`#${HEADER_USER_ID}`).should('contain', CURRENT_USER.name); }); }); + + describe('Redirect to URL in local storage', () => { + it('Home', () => { + cy.setLocalStorage(REDIRECT_URL_LOCAL_STORAGE_KEY, HOME_PATH); + cy.visit(REDIRECT_PATH); + cy.wait(REDIRECTION_TIME); + cy.url().should('include', HOME_PATH); + }); + + it('Items', () => { + cy.setLocalStorage(REDIRECT_URL_LOCAL_STORAGE_KEY, ITEMS_PATH); + cy.visit(REDIRECT_PATH); + cy.wait(REDIRECTION_TIME); + cy.url().should('include', ITEMS_PATH); + }); + + it('SharedItems', () => { + cy.setLocalStorage(REDIRECT_URL_LOCAL_STORAGE_KEY, SHARED_ITEMS_PATH); + cy.visit(REDIRECT_PATH); + cy.wait(REDIRECTION_TIME); + cy.url().should('include', SHARED_ITEMS_PATH); + }); + + it('Item', () => { + cy.setLocalStorage( + REDIRECT_URL_LOCAL_STORAGE_KEY, + buildItemPath(SAMPLE_ITEMS.items[0].id), + ); + cy.visit(REDIRECT_PATH); + cy.wait(REDIRECTION_TIME); + cy.url().should('include', buildItemPath(SAMPLE_ITEMS.items[0].id)); + }); + }); }); }); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index f30839f03..c4c6abf57 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -1,5 +1,6 @@ // eslint-disable-next-line import/no-extraneous-dependencies import 'cypress-file-upload'; +import 'cypress-localstorage-commands'; import { ITEM_LAYOUT_MODES } from '../../src/config/constants'; import { MODE_GRID_BUTTON_ID, diff --git a/cypress/support/constants.js b/cypress/support/constants.js index 300d693f8..c18606227 100644 --- a/cypress/support/constants.js +++ b/cypress/support/constants.js @@ -7,3 +7,5 @@ export const REQUEST_FAILURE_LOADING_TIME = 4000; export const REDIRECTION_CONTENT = 'hello'; export const REQUEST_FAILURE_TIME = 2500; + +export const REDIRECTION_TIME = 500; diff --git a/package.json b/package.json index fe3b1dd8a..917a22d54 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@uppy/xhr-upload": "1.7.0", "clsx": "1.1.1", "connected-react-router": "6.8.0", + "cypress-localstorage-commands": "1.4.5", "dexie": "3.0.3", "history": "5.0.0", "http-status-codes": "2.1.4", diff --git a/yarn.lock b/yarn.lock index 7727393dc..b1e93bd44 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5287,6 +5287,11 @@ cypress-file-upload@5.0.2: dependencies: mime "^2.5.0" +cypress-localstorage-commands@1.4.5: + version "1.4.5" + resolved "https://registry.yarnpkg.com/cypress-localstorage-commands/-/cypress-localstorage-commands-1.4.5.tgz#7e97f82c144314655ab7ecb4ce0e273c70d1e569" + integrity sha512-mr86nv74GvOE4zOFwoMrksFCykNSbRh57Pg7xUGpm2ax+wfHhqwBA56Sn5dhHV73gzz7C6B1kfNpMrjMH/hgyg== + cypress@6.2.1: version "6.2.1" resolved "https://registry.yarnpkg.com/cypress/-/cypress-6.2.1.tgz#27d5fbcf008c698c390fdb0c03441804176d06c4"