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';
6 import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
7 import { ToastrModule } from 'ngx-toastr';
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';
15 describe('UserListComponent', () => {
16 let component: UserListComponent;
17 let fixture: ComponentFixture<UserListComponent>;
21 BrowserAnimationsModule,
23 ToastrModule.forRoot(),
26 HttpClientTestingModule
28 declarations: [UserListComponent, UserTabsComponent]
32 fixture = TestBed.createComponent(UserListComponent);
33 component = fixture.componentInstance;
36 it('should create', () => {
37 fixture.detectChanges();
38 expect(component).toBeTruthy();
41 it('should test all TableActions combinations', () => {
42 const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
43 const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
44 component.tableActions
47 expect(tableActions).toEqual({
48 'create,update,delete': {
49 actions: ['Create', 'Edit', 'Delete'],
50 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
53 actions: ['Create', 'Edit'],
54 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
57 actions: ['Create', 'Delete'],
58 primary: { multiple: 'Create', executing: 'Delete', single: 'Delete', no: 'Create' }
62 primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
65 actions: ['Edit', 'Delete'],
66 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
70 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
74 primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
78 primary: { multiple: '', executing: '', single: '', no: '' }
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);
87 expect(component.getRemainingDays(today + day * 2 - 1000)).toBe(1);
89 expect(component.getRemainingDays(today + day + 1000)).toBe(1);
91 expect(component.getRemainingDays(today + 1)).toBe(0);
93 expect(component.getRemainingDays(today - (day + 1))).toBe(0);
94 expect(component.getRemainingDays(null)).toBe(undefined);
95 expect(component.getRemainingDays(undefined)).toBe(undefined);