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

Fix: user logout button not working #1017

Merged
merged 6 commits into from
Jan 11, 2023
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
11 changes: 9 additions & 2 deletions cypress/integration/users-login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("Users Login", () => {
});
});

it("visits login page and logs in with a functional account", () => {
it("visits login page and logs in with a functional account, then logout successfully", () => {
cy.visit("/");

cy.url().should("include", "/datasets");
Expand All @@ -74,6 +74,13 @@ describe("Users Login", () => {

cy.url().should("include", "/datasets");

cy.get(".user-button").should("contain.text", username);
cy.get(".user-button").should("contain.text", username).click();

cy.get("[data-cy=logout-button]").click();

cy.finishedLoading();

cy.url().should("include", "/login");
});

});
21 changes: 10 additions & 11 deletions src/app/_layout/app-header/app-header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@
<span>Settings</span>
</button>

<button mat-menu-item (click)="logout()">
<button mat-menu-item (click)="logout()" data-cy="logout-button">
<mat-icon> exit_to_app</mat-icon>
<span>Logout</span>
</button>
</mat-menu>

<mat-toolbar class="mat-elevation-z1" color="primary">
<a [routerLink]="['/datasets']">
<img class="logo" src="../../../assets/images/scicat-logo-white.png"/>
<img class="logo" src="../../../assets/images/scicat-logo-white.png" />
</a>
<a [routerLink]="['/datasets']">
<ng-template [ngIf]="facility === 'ESS'" [ngIfElse]="otherFacility">
<img class="logo" src="../../../assets/images/esslogo-white.png"/>
<img class="logo" src="../../../assets/images/esslogo-white.png" />
</ng-template>
<ng-template #otherFacility>
<img class="logo" src="../../../assets/images/site-logo.png"/>
<img class="logo" src="../../../assets/images/site-logo.png" />
</ng-template>
</a>
<a class="toplink" [routerLink]="['/datasets']">
Expand All @@ -89,7 +89,7 @@ <h6>
>
</h6>
</span>
<span *ngIf="(this.loggedIn$ | async) === false;else userButton">
<span *ngIf="(this.loggedIn$ | async) === false; else userButton">
<h6>
<a class="toplink" [routerLink]="['/login']" data-cy="login-button">
<mat-icon> account_circle </mat-icon>
Expand All @@ -111,17 +111,16 @@ <h6>
</button>
</span>

<mat-menu class="custom-menu" #cartMenu="matMenu">
<batch-card></batch-card>
</mat-menu>
<mat-menu class="custom-menu" #cartMenu="matMenu">
<batch-card></batch-card>
</mat-menu>

<span>
<span>
<button mat-button class="user-button" [matMenuTriggerFor]="userMenu">
<img class="user-image" src="{{ profileImage$ | async }}"/>
<img class="user-image" src="{{ profileImage$ | async }}" />
<div class="large-screen-text">{{ username$ | async }}</div>
</button>
</span>
</ng-template>

</mat-toolbar>
</div>
76 changes: 38 additions & 38 deletions src/app/_layout/app-header/app-header.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { MatToolbarModule } from "@angular/material/toolbar";
import { Store, StoreModule } from "@ngrx/store";
import { APP_CONFIG } from "app-config.module";
import { logoutAction } from "state-management/actions/user.actions";
import { MockStore } from "shared/MockStubs";
import { MockRouter, MockStore } from "shared/MockStubs";
import { MatIconModule } from "@angular/material/icon";
import { MatButtonModule } from "@angular/material/button";
import { provideMockStore } from "@ngrx/store/testing";
Expand All @@ -23,6 +23,7 @@ import {
selectThumbnailPhoto,
} from "state-management/selectors/user.selectors";
import { AppConfigService } from "app-config.service";
import { Router } from "@angular/router";

describe("AppHeaderComponent", () => {
let component: AppHeaderComponent;
Expand All @@ -35,45 +36,44 @@ describe("AppHeaderComponent", () => {
facility: "ESS",
});

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
schemas: [NO_ERRORS_SCHEMA],
declarations: [AppHeaderComponent],
imports: [
MatButtonModule,
MatIconModule,
MatMenuModule,
MatToolbarModule,
StoreModule.forRoot({}),
],
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
schemas: [NO_ERRORS_SCHEMA],
declarations: [AppHeaderComponent],
imports: [
MatButtonModule,
MatIconModule,
MatMenuModule,
MatToolbarModule,
StoreModule.forRoot({}),
],
providers: [
provideMockStore({
selectors: [
{
selector: selectCurrentUserName,
value: "ms-ad.User Name",
},
{
selector: selectThumbnailPhoto,
value: "assets/images/user.png",
},
{ selector: selectIsLoggedIn, value: true },
],
}),
],
});
TestBed.overrideComponent(AppHeaderComponent, {
set: {
providers: [
provideMockStore({
selectors: [
{
selector: selectCurrentUserName,
value: "ms-ad.User Name",
},
{
selector: selectThumbnailPhoto,
value: "assets/images/user.png",
},
{ selector: selectIsLoggedIn, value: true },
],
}),
{ provide: APP_CONFIG, useValue: { production: false } },
{ provide: AppConfigService, useValue: { getConfig } },
{ provide: Router, useClass: MockRouter },
],
});
TestBed.overrideComponent(AppHeaderComponent, {
set: {
providers: [
{ provide: APP_CONFIG, useValue: { production: false } },
{ provide: AppConfigService, useValue: { getConfig } },
],
},
});
TestBed.compileComponents();
})
);
},
});
TestBed.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(AppHeaderComponent);
Expand Down
4 changes: 4 additions & 0 deletions src/app/_layout/app-header/app-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "state-management/selectors/user.selectors";
import { selectDatasetsInBatchIndicator } from "state-management/selectors/datasets.selectors";
import { AppConfigService } from "app-config.service";
import { Router } from "@angular/router";

@Component({
selector: "app-app-header",
Expand All @@ -30,12 +31,15 @@ export class AppHeaderComponent implements OnInit {

constructor(
public appConfigService: AppConfigService,
private router: Router,
@Inject(APP_CONFIG) public appConfig: AppConfig,
private store: Store
) {}

logout(): void {
this.store.dispatch(logoutAction());

this.router.navigateByUrl("/login");
}

ngOnInit() {
Expand Down
4 changes: 1 addition & 3 deletions src/app/state-management/actions/user.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ export const updateUserSettingsFailedAction = createAction(
"[User] Update User Settings Failed"
);

export const fetchScicatTokenAction = createAction(
"[User] Fetch Scicat Token"
);
export const fetchScicatTokenAction = createAction("[User] Fetch Scicat Token");
export const fetchScicatTokenCompleteAction = createAction(
"[User] Fetch Scicat Token Complete",
props<{ token: AccessToken }>()
Expand Down
7 changes: 7 additions & 0 deletions src/app/state-management/reducers/user.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ const reducer = createReducer(
})
),

on(
fromActions.logoutAction,
(): UserState => ({
...initialUserState,
})
),

on(
fromActions.logoutCompleteAction,
(): UserState => ({
Expand Down
1 change: 1 addition & 0 deletions src/app/users/user-settings/user-settings.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mat-card {
width: 100%;
padding: 0.5em;
display: inline-block;
word-break: break-all;

.copy-button {
padding-left: 0.5em;
Expand Down