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

[ACS-8961] Remove expandedSidenav from local storage upon logout #4242

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
21 changes: 19 additions & 2 deletions projects/aca-shared/src/lib/services/app.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
TranslationMock,
TranslationService,
UserPreferencesService,
NotificationService
NotificationService,
StorageService
} from '@alfresco/adf-core';
import { BehaviorSubject, Observable, of, Subject } from 'rxjs';
import { HttpClientModule } from '@angular/common/http';
Expand Down Expand Up @@ -64,6 +65,7 @@ describe('AppService', () => {
let sharedLinksApiService: SharedLinksApiService;
let contentApi: ContentApiService;
let preferencesService: UserPreferencesService;
let storageService: StorageService;
let appSettingsService: AppSettingsService;
let userProfileService: UserProfileService;
let notificationService: NotificationService;
Expand Down Expand Up @@ -113,7 +115,13 @@ describe('AppService', () => {
}
},
{ provide: TranslationService, useClass: TranslationMock },
{ provide: UserPreferencesService, useValue: { setStoragePrefix: () => null } }
{
provide: UserPreferencesService,
useValue: {
setStoragePrefix: () => null,
getPropertyKey: (property: string) => `prefix__${property}`
}
}
]
});

Expand All @@ -127,6 +135,7 @@ describe('AppService', () => {
spyOn(contentApi, 'getRepositoryInformation').and.returnValue(of({} as any));
service = TestBed.inject(AppService);
preferencesService = TestBed.inject(UserPreferencesService);
storageService = TestBed.inject(StorageService);
userProfileService = TestBed.inject(UserProfileService);
loadUserProfileSpy = spyOn(userProfileService, 'loadUserProfile').and.returnValue(Promise.resolve({} as any));
notificationService = TestBed.inject(NotificationService);
Expand Down Expand Up @@ -156,6 +165,14 @@ describe('AppService', () => {
await expect(resetToDefaults).toHaveBeenCalled();
});

it('should remove expandedSidenav item from local storage upon logout', async () => {
const key = preferencesService.getPropertyKey('expandedSidenav');
spyOn(storageService, 'removeItem');
auth.onLogout.next(true);

expect(storageService.removeItem).toHaveBeenCalledWith(key);
});

it('should raise notification on share link error', () => {
const showError = spyOn(notificationService, 'showError').and.stub();
spyOn(store, 'select').and.returnValue(of(''));
Expand Down
15 changes: 12 additions & 3 deletions projects/aca-shared/src/lib/services/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@
*/

import { inject, Injectable } from '@angular/core';
import { AppConfigService, AuthenticationService, NotificationService, PageTitleService, UserPreferencesService } from '@alfresco/adf-core';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import {
AuthenticationService,
AppConfigService,
PageTitleService,
UserPreferencesService,
NotificationService,
StorageService
} from '@alfresco/adf-core';
import { Observable, BehaviorSubject, Subject } from 'rxjs';
import {
AlfrescoApiService,
FileUploadErrorEvent,
Expand Down Expand Up @@ -92,7 +99,8 @@ export class AppService implements ShellAppService {
searchQueryBuilderService: SearchQueryBuilderService,
private acaMobileAppSwitcherService: AcaMobileAppSwitcherService,
private appSettingsService: AppSettingsService,
private userProfileService: UserProfileService
private readonly userProfileService: UserProfileService,
private readonly storage: StorageService
) {
this.ready = new BehaviorSubject(this.authenticationService.isLoggedIn() || this.withCredentials);
this.ready$ = this.ready.asObservable();
Expand All @@ -103,6 +111,7 @@ export class AppService implements ShellAppService {
});

this.authenticationService.onLogout.subscribe(() => {
this.storage.removeItem(this.preferencesService.getPropertyKey('expandedSidenav'));
searchQueryBuilderService.resetToDefaults();
acaMobileAppSwitcherService.clearSessionExpireTime();
acaMobileAppSwitcherService.closeDialog();
Expand Down
Loading