diff --git a/cypress/integration/Authentication/login.spec.ts b/cypress/integration/Authentication/login.spec.ts index be7b7d9..7e177c8 100644 --- a/cypress/integration/Authentication/login.spec.ts +++ b/cypress/integration/Authentication/login.spec.ts @@ -8,7 +8,7 @@ describe('User Authentication', () => { }); context('login with email and password', () => { - it('given correct credentials, redirects to the home page', () => { + it('given correct credentials, redirects to the home page, shows user header', () => { cy.intercept('POST', 'api/v1/oauth/token', { statusCode: 200, fixture: 'Authentication/valid-credentials.json', @@ -27,9 +27,11 @@ describe('User Authentication', () => { }); cy.findByTestId('app-main-heading').should('be.visible'); + + cy.findByTestId('header-avatar').should('have.attr', 'src', 'valid_avatar_url'); }); - it('given INCORRECT credentials, shows login error', () => { + it('given INCORRECT credentials, shows login error, does NOT show user header', () => { cy.intercept('POST', 'api/v1/oauth/token', { statusCode: 400, fixture: 'Authentication/invalid-credentials.json', @@ -52,6 +54,7 @@ describe('User Authentication', () => { }); cy.findByTestId('app-main-heading').should('not.exist'); + cy.findByTestId('header-avatar').should('not.exist'); }); it('given NO credentials entered, shows field validation errors', () => { diff --git a/cypress/integration/Surveys/home.spec.ts b/cypress/integration/Surveys/home.spec.ts new file mode 100644 index 0000000..d94d9f8 --- /dev/null +++ b/cypress/integration/Surveys/home.spec.ts @@ -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: 'testemail@gmail.com', + 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'); + }); + }); +});