-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: dashboard storage service (#737)
Co-authored-by: yannick-aneo <[email protected]>
- Loading branch information
1 parent
094ba8e
commit 8ff7645
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/app/dashboard/services/dashboard-storage.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { TaskStatus } from '@aneoconsultingfr/armonik.api.angular'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { StorageService } from '@services/storage.service'; | ||
import { DashboardStorageService } from './dashboard-storage.service'; | ||
import { Line } from '../types'; | ||
|
||
describe('DashboardStorageService', () => { | ||
let service: DashboardStorageService; | ||
|
||
const mockStorageService = { | ||
setItem: jest.fn(), | ||
getItem: jest.fn() | ||
}; | ||
|
||
const lines: Line[] = [ | ||
{ | ||
name: 'line1', | ||
interval: 10, | ||
hideGroupsHeader: false, | ||
filters: [], | ||
taskStatusesGroups: [ | ||
{ name: 'Success', color: 'green', statuses: [TaskStatus.TASK_STATUS_COMPLETED, TaskStatus.TASK_STATUS_PROCESSED]}, | ||
{ name: 'Running', color: 'yellow', statuses: [TaskStatus.TASK_STATUS_CREATING, TaskStatus.TASK_STATUS_PROCESSING]}, | ||
{ name: 'Error', color: 'red', statuses: [TaskStatus.TASK_STATUS_CANCELLED, TaskStatus.TASK_STATUS_TIMEOUT]} | ||
], | ||
}, | ||
{ | ||
name: 'line2', | ||
interval: 20, | ||
hideGroupsHeader: true, | ||
filters: [], | ||
taskStatusesGroups: [ | ||
{ name: 'Success', color: 'green', statuses: [TaskStatus.TASK_STATUS_COMPLETED, TaskStatus.TASK_STATUS_PROCESSED]}, | ||
{ name: 'Running', color: 'yellow', statuses: [TaskStatus.TASK_STATUS_CREATING, TaskStatus.TASK_STATUS_PROCESSING]}, | ||
{ name: 'Unspecified', color: 'grey', statuses: [TaskStatus.TASK_STATUS_UNSPECIFIED, TaskStatus.TASK_STATUS_RETRIED]} | ||
], | ||
} | ||
]; | ||
|
||
beforeEach(() => { | ||
service = TestBed.configureTestingModule({ | ||
providers: [ | ||
DashboardStorageService, | ||
{ provide: StorageService, useValue: mockStorageService } | ||
] | ||
}).inject(DashboardStorageService); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('shoud save lines', () => { | ||
service.saveLines(lines); | ||
expect(mockStorageService.setItem).toHaveBeenCalledWith('dashboard-lines', lines); | ||
}); | ||
|
||
it('should restore lines', () => { | ||
mockStorageService.getItem.mockImplementationOnce(() => lines); | ||
expect(service.restoreLines()).toEqual(lines); | ||
}); | ||
|
||
it('should return null if there is no lines', () => { | ||
mockStorageService.getItem.mockImplementation(() => undefined); | ||
expect(service.restoreLines()).toEqual(null); | ||
}); | ||
|
||
it('should save splitted lines', () => { | ||
service.saveSplitLines(4); | ||
expect(mockStorageService.setItem).toHaveBeenCalledWith('dashboard-split-lines', 4); | ||
}); | ||
|
||
it('should restore splitted lines', () => { | ||
mockStorageService.getItem.mockImplementationOnce(() => 2); | ||
expect(service.restoreSplitLines()).toEqual(2); | ||
}); | ||
|
||
it('should return null if there is no lines', () => { | ||
mockStorageService.getItem.mockImplementation(() => undefined); | ||
expect(service.restoreSplitLines()).toEqual(null); | ||
}); | ||
}); |
8ff7645
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JUnit
Files coverage (88%)