From d228f200a10d0bfde5433481c17a6bee43c9cb49 Mon Sep 17 00:00:00 2001 From: Faust1 Date: Wed, 5 Jun 2024 09:27:22 +0200 Subject: [PATCH] test: profile page --- src/app/profile/index.component.spec.ts | 73 +++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/app/profile/index.component.spec.ts diff --git a/src/app/profile/index.component.spec.ts b/src/app/profile/index.component.spec.ts new file mode 100644 index 000000000..f9b3957ee --- /dev/null +++ b/src/app/profile/index.component.spec.ts @@ -0,0 +1,73 @@ +import { User } from '@aneoconsultingfr/armonik.api.angular'; +import { TestBed } from '@angular/core/testing'; +import { IconsService } from '@services/icons.service'; +import { ShareUrlService } from '@services/share-url.service'; +import { UserService } from '@services/user.service'; +import { IndexComponent } from './index.component'; +import { PermissionGroup } from './types'; + +describe('IndexComponent', () => { + let component: IndexComponent; + + const returnedUrl = 'some-url'; + const mockShareUrlService = { + generateSharableURL: jest.fn(() => returnedUrl), + }; + + const user: User.AsObject = { + username: 'ArmoniK', + permissions: ['Sessions:list', 'Sessions:get', 'Sessions:cancel', 'Tasks:list'], + roles: ['Operator', 'User'] + }; + + const mockUserService = { + user: user + }; + + beforeEach(() => { + component = TestBed.configureTestingModule({ + providers: [ + IndexComponent, + { provide: ShareUrlService, useValue: mockShareUrlService }, + { provide: UserService, useValue: mockUserService }, + IconsService + ] + }).inject(IndexComponent); + component.ngOnInit(); + }); + + it('should create', () => { + expect(component).toBeDefined(); + }); + + describe('Initialisation', () => { + it('should init the sharableUrl', () => { + expect(component.sharableURL).toBe(returnedUrl); + }); + }); + + it('should allows to get user', () => { + expect(component.user).toBe(user); + }); + + it('should get Icons', () => { + expect(component.getIcon('profile')).toEqual('account_circle'); + }); + + it('should group permissions', () => { + expect(component.groupedPermissions()).toEqual([ + { + name: 'sessions', + permissions: [ + 'list', 'get', 'cancel' + ] + }, + { + name: 'tasks', + permissions: [ + 'list' + ] + } + ]); + }); +}); \ No newline at end of file