Skip to content

Commit

Permalink
[ACS-8961] Remove expandedSidenav from local storage upon logout (#4242)
Browse files Browse the repository at this point in the history
* [ACS-8961] Remove expandedSidenav from local storage on logout

* [ACS-8961] fix sonarcloud issue
  • Loading branch information
nikita-web-ua authored Dec 20, 2024
1 parent 66f7013 commit d6f859d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
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

0 comments on commit d6f859d

Please sign in to comment.