Skip to content

Commit

Permalink
test: redirect url in local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
yoda-k committed Jun 3, 2021
1 parent 241ff24 commit e8638de
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cypress/integration/authentication.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
buildItemPath,
HOME_PATH,
ITEMS_PATH,
REDIRECT_PATH,
SHARED_ITEMS_PATH,
} from '../../src/config/paths';
import {
Expand All @@ -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', () => {
Expand All @@ -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);
});
});
Expand Down Expand Up @@ -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));
});
});
});
});
1 change: 1 addition & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 2 additions & 0 deletions cypress/support/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5287,6 +5287,11 @@ [email protected]:
dependencies:
mime "^2.5.0"

[email protected]:
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==

[email protected]:
version "6.2.1"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-6.2.1.tgz#27d5fbcf008c698c390fdb0c03441804176d06c4"
Expand Down

0 comments on commit e8638de

Please sign in to comment.