Skip to content

Commit

Permalink
update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ntqdinh-axonivy committed Dec 9, 2024
1 parent 9e785cb commit 50c8758
Showing 1 changed file with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import { DESIGNER_SESSION_STORAGE_VARIABLE } from '../constants/common.constant'

describe('RoutingQueryParamService', () => {
let service: RoutingQueryParamService;
let cookieService: jasmine.SpyObj<CookieService>;
let eventsSubject: Subject<NavigationStart>;
let mockStorage: { [key: string]: string };

beforeEach(() => {
const cookieServiceSpy = jasmine.createSpyObj('CookieService', [
'get',
'set'
]);
eventsSubject = new Subject<NavigationStart>();
const routerSpy = jasmine.createSpyObj('Router', [], {
events: eventsSubject.asObservable()
Expand All @@ -23,14 +19,21 @@ describe('RoutingQueryParamService', () => {
TestBed.configureTestingModule({
providers: [
RoutingQueryParamService,
{ provide: CookieService, useValue: cookieServiceSpy },
{ provide: Router, useValue: routerSpy }
]
});
service = TestBed.inject(RoutingQueryParamService);
cookieService = TestBed.inject(
CookieService
) as jasmine.SpyObj<CookieService>;
mockStorage = {
'ivy-viewer': 'designer-market',
'ivy-version': '1.0'
};
spyOn(sessionStorage, 'getItem').and.callFake((key: string) => {
return mockStorage[key] || null;
});

spyOn(sessionStorage, 'setItem').and.callFake((key: string, value: string) => {
mockStorage[key] = value;
});
});

it('should be created', () => {
Expand All @@ -42,7 +45,7 @@ describe('RoutingQueryParamService', () => {
[DESIGNER_SESSION_STORAGE_VARIABLE.ivyVersionParamName]: '1.0'
};
service.checkSessionStorageForDesignerVersion(params);
expect(cookieService.set).toHaveBeenCalledWith(
expect(sessionStorage.setItem).toHaveBeenCalledWith(
DESIGNER_SESSION_STORAGE_VARIABLE.ivyVersionParamName,
'1.0'
);
Expand All @@ -55,29 +58,28 @@ describe('RoutingQueryParamService', () => {
DESIGNER_SESSION_STORAGE_VARIABLE.defaultDesignerViewer
};
service.checkSessionStorageForDesignerEnv(params);
expect(cookieService.set).toHaveBeenCalledWith(
expect(sessionStorage.setItem).toHaveBeenCalledWith(
DESIGNER_SESSION_STORAGE_VARIABLE.ivyViewerParamName,
DESIGNER_SESSION_STORAGE_VARIABLE.defaultDesignerViewer
);
expect(service.isDesignerViewer()).toBeTrue();
});

it('should get designer version from session storage if not set', () => {
cookieService.get.and.returnValue('1.0');
expect(service.getDesignerVersionFromSessionStorage()).toBe('1.0');
});

it('should set isDesigner to true if session storage matches default designer viewer', () => {
cookieService.get.and.returnValue(
DESIGNER_SESSION_STORAGE_VARIABLE.defaultDesignerViewer
);
// cookieService.get.and.returnValue(
// DESIGNER_SESSION_STORAGE_VARIABLE.defaultDesignerViewer
// );
expect(service.isDesignerViewer()).toBeTrue();
});

it('should listen to navigation start events', () => {
cookieService.get.and.returnValue(
DESIGNER_SESSION_STORAGE_VARIABLE.defaultDesignerViewer
);
// cookieService.get.and.returnValue(
// DESIGNER_SESSION_STORAGE_VARIABLE.defaultDesignerViewer
// );
eventsSubject.next(new NavigationStart(1, 'testUrl'));
expect(service.isDesignerViewer()).toBeTrue();
});
Expand Down

0 comments on commit 50c8758

Please sign in to comment.