Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1061 - have menu open by default no matter if you're logged in or not #1065

Merged
merged 3 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions cypress/integration/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ describe('Login', () => {
it('should login given correct credentials', () => {
cy.visit('/login');
cy.contains('Sign in').should('be.visible');
cy.get('button[aria-label="Open navigation menu"]').should('exist');

cy.contains('Username*').parent().find('input').type('username');
cy.contains('Password*').parent().find('input').type('password');
Expand All @@ -114,7 +113,6 @@ describe('Login', () => {
it('should login given username with leading or trailing whitespace', () => {
cy.visit('/login');
cy.contains('Sign in').should('be.visible');
cy.get('button[aria-label="Open navigation menu"]').should('exist');

cy.contains('Username*').parent().find('input').type(' username ');
cy.contains('Password*').parent().find('input').type('password');
Expand All @@ -136,7 +134,6 @@ describe('Login', () => {
it('should remain logged in following page refresh or redirect', () => {
cy.visit('/login');
cy.contains('Sign in').should('be.visible');
cy.get('button[aria-label="Open navigation menu"]').should('exist');

cy.contains('Username*').parent().find('input').type(' username');
cy.contains('Password*').parent().find('input').type('password');
Expand Down Expand Up @@ -326,33 +323,34 @@ describe('Login', () => {
});
});

it('should show the sidebar and yet still show the Sign in button', () => {
it('should allow access to plugins and yet still show the Sign in button', () => {
verifyResponse = verifySuccess;
loginResponse = loginSuccess;
cy.visit('/');
cy.visit('/plugin1');

cy.get('button[aria-label="Close navigation menu"]').should('be.visible');
cy.get('#demo_plugin').contains('Demo Plugin').should('be.visible');
cy.contains('Sign in').should('be.visible');

// test that token verification also works with autologin
cy.reload();
cy.get('button[aria-label="Close navigation menu"]').should('be.visible');
cy.get('#demo_plugin').contains('Demo Plugin').should('be.visible');
cy.contains('Sign in').should('be.visible');

// test that autologin works after token validation + refresh fail
verifyResponse = failure;
cy.intercept('POST', '/refresh', { statusCode: 403 });
cy.reload();
cy.get('button[aria-label="Close navigation menu"]').should('be.visible');
cy.get('#demo_plugin').contains('Demo Plugin').should('be.visible');
cy.contains('Sign in').should('be.visible');
});

it('should not display as logged in if autologin requests fail', () => {
it('should not be logged in if autologin requests fail', () => {
loginResponse = failure;
verifyResponse = verifySuccess;

cy.contains('Sign in').should('be.visible');
cy.get('button[aria-label="Open navigation menu"]').should('exist');
cy.visit('/plugin1');
cy.get('#demo_plugin').should('not.exist');
cy.contains('h1', 'Sign in').should('be.visible');

// test that autologin fails after token validation + refresh fail
verifyResponse = failure;
Expand All @@ -361,8 +359,8 @@ describe('Login', () => {
$window.localStorage.setItem('scigateway:token', 'invalidtoken')
);
cy.reload();
cy.contains('Sign in').should('be.visible');
cy.get('button[aria-label="Open navigation menu"]').should('exist');
cy.get('#demo_plugin').should('not.exist');
cy.contains('h1', 'Sign in').should('be.visible');
});

it('should be able to directly view a plugin route without signing in', () => {
Expand Down
8 changes: 4 additions & 4 deletions cypress/integration/scigateway_frontend_spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ describe('Scigateway', () => {

cy.url().should('eq', 'http://127.0.0.1:3000/');

cy.get('button[aria-label="Open navigation menu"]').should('exist');
cy.get('button[aria-label="Close navigation menu"]').should('exist');
cy.get('button[aria-label="Help page"]').click();
cy.get('button[aria-label="Open navigation menu"]').should('exist');
cy.get('button[aria-label="Open navigation menu"]').click();
cy.get('button[aria-label="Close navigation menu"]').should('exist');
cy.get('button[aria-label="Close navigation menu"]').click();
cy.get('button[aria-label="Open navigation menu"]').should('exist');
cy.get('button[aria-label="Home page"]').click();
cy.get('button[aria-label="Close navigation menu"]').should('exist');
cy.get('button[aria-label="Open navigation menu"]').should('exist');
});
});
11 changes: 4 additions & 7 deletions src/mainAppBar/mainAppBar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,13 @@ const MainAppBar = (props: CombinedMainAppBarProps): React.ReactElement => {
}
}, [props.plugins, location, props.loading, props.singlePluginLogo]);

// have menu open by default after page loads
React.useEffect(() => {
if (
!props.loading &&
props.loggedIn &&
!props.drawerOpen &&
props.pathname !== '/login'
)
if (!props.loading && !props.drawerOpen) {
props.toggleDrawer();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.loading, props.loggedIn]);
}, [props.loading]);

return (
<div className={props.classes.root}>
Expand Down
1 change: 0 additions & 1 deletion src/state/reducers/scigateway.reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ export function handleTokenExpiration(state: ScigatewayState): ScigatewayState {
state.authorisation.provider.logOut();
return {
...state,
drawerOpen: false,
authorisation: {
...resetAuth(state.authorisation),
signedOutDueToTokenInvalidation: true,
Expand Down