Skip to content

Commit

Permalink
feat: address more cases of sign-out
Browse files Browse the repository at this point in the history
  • Loading branch information
rushtong committed Aug 30, 2024
1 parent a611c5f commit a2b07fa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cypress/component/Auth/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Storage} from '../../../src/libs/storage';

describe('Auth', function () {
// Intercept configuration calls
beforeEach(() => {
beforeEach(async () => {
cy.intercept({
method: 'GET',
url: '/config.json',
Expand All @@ -18,11 +18,11 @@ describe('Auth', function () {
'authorityEndpoint': 'authorityEndpoint',
'clientId': 'clientId'
});
await Auth.initialize();
});
it('Sign Out Clears the session when called', async function () {
cy.stub(Config, 'getGoogleClientId').returns('12345');
cy.stub(GoogleIS, 'revokeAccessToken');
await Auth.initialize();
Storage.setUserIsLogged(true);
expect(Storage.userIsLogged()).to.be.true;
await Auth.signOut();
Expand Down
26 changes: 22 additions & 4 deletions cypress/component/TermsOfService/tos_acceptance.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
/* eslint-disable no-undef */

import React from 'react';
import { mount } from 'cypress/react';
import {mount} from 'cypress/react';
import {Auth} from '../../../src/libs/auth/auth';
import TermsOfServiceAcceptance from '../../../src/pages/TermsOfServiceAcceptance';
import { ToS } from '../../../src/libs/ajax/ToS';
import {Storage} from '../../../src/libs/storage';
import {Navigation} from '../../../src/libs/utils';
import {OAuth2} from '../../../src/libs/ajax/OAuth2';
import {ToS} from '../../../src/libs/ajax/ToS';
import {Storage} from '../../../src/libs/storage';

const text = 'TOS Text';
const mocks = {
history: { push() {} }
history: {
push() {
}
}
};

describe('Terms of Service Acceptance Page', function () {
// Intercept configuration calls
beforeEach(async () => {
cy.intercept({
method: 'GET',
url: '/config.json',
hostname: 'localhost',
}, {'env': 'ci'});
cy.stub(OAuth2, 'getConfig').returns({
'authorityEndpoint': 'authorityEndpoint',
'clientId': 'clientId'
});
await Auth.initialize();
});
it('Standard text loads correctly and buttons work', function () {
cy.viewport(600, 300);
cy.stub(ToS, 'getDUOSText').returns(text);
Expand Down
16 changes: 8 additions & 8 deletions src/pages/TermsOfService.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import { useEffect, useState } from 'react';
import { Storage } from '../libs/storage';
import { TosService } from '../libs/tosService';
import {useEffect, useState} from 'react';
import {Auth} from '../libs/auth/auth';
import {Storage} from '../libs/storage';
import {TosService} from '../libs/tosService';
import SimpleButton from '../components/SimpleButton';

export default function TermsOfService(props) {
const [tosText, setTosText] = useState('');
const { history } = props;
const {history} = props;
const isLogged = Storage.userIsLogged();

useEffect(() => {
Expand All @@ -22,19 +23,18 @@ export default function TermsOfService(props) {
await TosService.rejectTos();

// log user out and send them back home.
await Storage.setUserIsLogged(false);
await Storage.clearStorage();
await Auth.signOut();
history.push('/');
};

return (
<div style={TosService.getBackgroundStyle()}>
<div style={TosService.getContainerStyle()}>
<h1 style={{ color: '#00609f', marginLeft: '25px' }}>DUOS Terms of Service</h1>
<h1 style={{color: '#00609f', marginLeft: '25px'}}>DUOS Terms of Service</h1>
<div style={TosService.getScrollableStyle()} className="markdown-body">
{tosText}
</div>
{isLogged && <div style={{ display: 'flex', justifyContent: 'right', paddingRight: '5rem' }}>
{isLogged && <div style={{display: 'flex', justifyContent: 'right', paddingRight: '5rem'}}>
<SimpleButton
keyProp="tos-accept"
label="Reject Terms of Service"
Expand Down
30 changes: 15 additions & 15 deletions src/pages/TermsOfServiceAcceptance.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import { useCallback, useEffect, useState } from 'react';
import { TosService } from '../libs/tosService';
import { Storage } from '../libs/storage';
import {useCallback, useEffect, useState} from 'react';
import {Auth} from '../libs/auth/auth';
import {TosService} from '../libs/tosService';
import {Storage} from '../libs/storage';
import SimpleButton from '../components/SimpleButton';
import { Theme } from '../libs/theme';
import {Theme} from '../libs/theme';

export default function TermsOfServiceAcceptance(props) {
const [tosText, setTosText] = useState('');
const { history } = props;
const {history} = props;

useEffect(() => {
const init = async () => {
Expand All @@ -30,8 +31,8 @@ export default function TermsOfServiceAcceptance(props) {
}, [history]);

const acceptButton = <SimpleButton
keyProp='tos-accept'
label='Accept Terms of Service'
keyProp="tos-accept"
label="Accept Terms of Service"
isRendered={true}
onClick={acceptToS}
baseColor={Theme.palette.secondary}
Expand All @@ -44,17 +45,16 @@ export default function TermsOfServiceAcceptance(props) {
/>;

const signOut = async () => {
await Storage.setUserIsLogged(false);
await Storage.clearStorage();
await Auth.signOut();
history.push('/');
};

const rejectButton = <SimpleButton
keyProp='tos-accept'
label='Reject Terms of Service'
keyProp="tos-accept"
label="Reject Terms of Service"
isRendered={true}
onClick={signOut}
baseColor='darkgray'
baseColor="darkgray"
hoverStyle={{
backgroundColor: '#d13b07',
color: 'white'
Expand All @@ -68,10 +68,10 @@ export default function TermsOfServiceAcceptance(props) {

return (
<div style={TosService.getBackgroundStyle()}>
<div style={TosService.getContainerStyle()} className='markdown-body'>
<h1 style={{ marginLeft: '25px' }}>DUOS Terms of Service</h1>
<div style={TosService.getContainerStyle()} className="markdown-body">
<h1 style={{marginLeft: '25px'}}>DUOS Terms of Service</h1>
<div style={TosService.getScrollableStyle()}>{tosText}</div>
<div style={{ marginTop: '.5rem', display: 'flex', alignItems: 'center', justifyContent: 'right' }}>
<div style={{marginTop: '.5rem', display: 'flex', alignItems: 'center', justifyContent: 'right'}}>
{rejectButton}
{acceptButton}
</div>
Expand Down

0 comments on commit a2b07fa

Please sign in to comment.