]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/sparkline/sparkline.component.spec.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / components / sparkline / sparkline.component.spec.ts
1 import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3
4 import { configureTestBed } from '../../../../testing/unit-test-helper';
5 import { DimlessBinaryPipe } from '../../pipes/dimless-binary.pipe';
6 import { FormatterService } from '../../services/formatter.service';
7 import { SparklineComponent } from './sparkline.component';
8
9 describe('SparklineComponent', () => {
10 let component: SparklineComponent;
11 let fixture: ComponentFixture<SparklineComponent>;
12
13 configureTestBed({
14 declarations: [SparklineComponent],
15 schemas: [NO_ERRORS_SCHEMA],
16 imports: [],
17 providers: [DimlessBinaryPipe, FormatterService]
18 });
19
20 beforeEach(() => {
21 fixture = TestBed.createComponent(SparklineComponent);
22 component = fixture.componentInstance;
23 fixture.detectChanges();
24 });
25
26 it('should create', () => {
27 expect(component).toBeTruthy();
28 expect(component.options.tooltips.custom).toBeDefined();
29 });
30
31 it('should update', () => {
32 expect(component.datasets).toEqual([{ data: [] }]);
33 expect(component.labels.length).toBe(0);
34
35 component.data = [11, 22, 33];
36 component.ngOnChanges({ data: new SimpleChange(null, component.data, false) });
37
38 expect(component.datasets).toEqual([{ data: [11, 22, 33] }]);
39 expect(component.labels.length).toBe(3);
40 });
41
42 it('should not transform the label, if not isBinary', () => {
43 component.isBinary = false;
44 const result = component.options.tooltips.callbacks.label({ yLabel: 1024 });
45 expect(result).toBe(1024);
46 });
47
48 it('should transform the label, if isBinary', () => {
49 component.isBinary = true;
50 const result = component.options.tooltips.callbacks.label({ yLabel: 1024 });
51 expect(result).toBe('1 KiB');
52 });
53 });