]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.spec.ts
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / auth / user-list / user-list.component.spec.ts
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4 import { RouterTestingModule } from '@angular/router/testing';
5
6 import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
7 import { ToastrModule } from 'ngx-toastr';
8
9 import { TableActionsComponent } from '~/app/shared/datatable/table-actions/table-actions.component';
10 import { SharedModule } from '~/app/shared/shared.module';
11 import { configureTestBed, PermissionHelper } from '~/testing/unit-test-helper';
12 import { UserTabsComponent } from '../user-tabs/user-tabs.component';
13 import { UserListComponent } from './user-list.component';
14
15 describe('UserListComponent', () => {
16 let component: UserListComponent;
17 let fixture: ComponentFixture<UserListComponent>;
18
19 configureTestBed({
20 imports: [
21 BrowserAnimationsModule,
22 SharedModule,
23 ToastrModule.forRoot(),
24 NgbNavModule,
25 RouterTestingModule,
26 HttpClientTestingModule
27 ],
28 declarations: [UserListComponent, UserTabsComponent]
29 });
30
31 beforeEach(() => {
32 fixture = TestBed.createComponent(UserListComponent);
33 component = fixture.componentInstance;
34 });
35
36 it('should create', () => {
37 fixture.detectChanges();
38 expect(component).toBeTruthy();
39 });
40
41 it('should test all TableActions combinations', () => {
42 const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
43 const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
44 component.tableActions
45 );
46
47 expect(tableActions).toEqual({
48 'create,update,delete': {
49 actions: ['Create', 'Edit', 'Delete'],
50 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
51 },
52 'create,update': {
53 actions: ['Create', 'Edit'],
54 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
55 },
56 'create,delete': {
57 actions: ['Create', 'Delete'],
58 primary: { multiple: 'Create', executing: 'Delete', single: 'Delete', no: 'Create' }
59 },
60 create: {
61 actions: ['Create'],
62 primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
63 },
64 'update,delete': {
65 actions: ['Edit', 'Delete'],
66 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
67 },
68 update: {
69 actions: ['Edit'],
70 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
71 },
72 delete: {
73 actions: ['Delete'],
74 primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
75 },
76 'no-permissions': {
77 actions: [],
78 primary: { multiple: '', executing: '', single: '', no: '' }
79 }
80 });
81 });
82 it('should calculate remaining days', () => {
83 const day = 60 * 60 * 24 * 1000;
84 let today = Date.now();
85 expect(component.getRemainingDays(today + day * 2 + 1000)).toBe(2);
86 today = Date.now();
87 expect(component.getRemainingDays(today + day * 2 - 1000)).toBe(1);
88 today = Date.now();
89 expect(component.getRemainingDays(today + day + 1000)).toBe(1);
90 today = Date.now();
91 expect(component.getRemainingDays(today + 1)).toBe(0);
92 today = Date.now();
93 expect(component.getRemainingDays(today - (day + 1))).toBe(0);
94 expect(component.getRemainingDays(null)).toBe(undefined);
95 expect(component.getRemainingDays(undefined)).toBe(undefined);
96 });
97 });