generated from nimblehq/git-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#19] Add test for homepage test for existing or missing token
- Loading branch information
1 parent
e73941c
commit 0886516
Showing
2 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { setItem } from '../../../src/helpers/localStorage'; | ||
/* eslint-disable camelcase */ | ||
const mockTokenData = { | ||
access_token: 'test_access_token', | ||
refresh_token: 'test_refresh_token', | ||
token_type: 'Bearer', | ||
expires_in: 7200, | ||
created_at: 1677045997, | ||
}; | ||
|
||
const mockUserProfileData = { | ||
email: '[email protected]', | ||
name: 'TestName', | ||
avatar_url: 'https://secure.gravatar.com/avatar/6733d09432e89459dba795de8312ac2d', | ||
}; | ||
|
||
// TODO: Add re-fetching auth token and calling endpoint when | ||
describe('Home', () => { | ||
context('Authentication token', () => { | ||
it('with user tokens, displays home page and user header', () => { | ||
setItem('UserProfile', { auth: mockTokenData, user: mockUserProfileData }); | ||
|
||
cy.visit('/'); | ||
|
||
cy.location().should((location) => { | ||
expect(location.pathname).to.eq('/'); | ||
}); | ||
|
||
cy.findByTestId('app-main-heading').should('be.visible'); | ||
|
||
cy.findByText('Home Screen').should('exist'); | ||
cy.findByText('Home Screen').should('be.visible'); | ||
}); | ||
|
||
it('WITHOUT user tokens, redirects to the login page', () => { | ||
cy.visit('/'); | ||
|
||
cy.location().should((location) => { | ||
expect(location.pathname).to.eq('/login'); | ||
}); | ||
|
||
cy.findByTestId('app-main-heading').should('not.exist'); | ||
|
||
cy.findByText('Home Screen').should('not.exist'); | ||
}); | ||
}); | ||
}); |