]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/breadcrumbs/breadcrumbs.component.spec.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / navigation / breadcrumbs / breadcrumbs.component.spec.ts
CommitLineData
11fdf7f2
TL
1import { CommonModule } from '@angular/common';
2import { Component } from '@angular/core';
3import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
4import { Router, Routes } from '@angular/router';
5import { RouterTestingModule } from '@angular/router/testing';
6
f67539c2
TL
7import { PerformanceCounterBreadcrumbsResolver } from '~/app/app-routing.module';
8import { configureTestBed } from '~/testing/unit-test-helper';
11fdf7f2
TL
9import { BreadcrumbsComponent } from './breadcrumbs.component';
10
11describe('BreadcrumbsComponent', () => {
12 let component: BreadcrumbsComponent;
13 let fixture: ComponentFixture<BreadcrumbsComponent>;
14 let router: Router;
15
16 @Component({ selector: 'cd-fake', template: '' })
17 class FakeComponent {}
18
19 const routes: Routes = [
20 {
21 path: 'hosts',
22 component: FakeComponent,
23 data: { breadcrumbs: 'Cluster/Hosts' }
24 },
25 {
26 path: 'perf_counters',
27 component: FakeComponent,
28 data: {
29 breadcrumbs: PerformanceCounterBreadcrumbsResolver
30 }
31 },
32 {
33 path: 'block',
34 data: { breadcrumbs: true, text: 'Block', path: null },
35 children: [
36 {
37 path: 'rbd',
38 data: { breadcrumbs: 'Images' },
39 children: [
40 { path: '', component: FakeComponent },
41 { path: 'add', component: FakeComponent, data: { breadcrumbs: 'Add' } }
42 ]
43 }
44 ]
45 }
46 ];
47
48 configureTestBed({
49 declarations: [BreadcrumbsComponent, FakeComponent],
50 imports: [CommonModule, RouterTestingModule.withRoutes(routes)],
51 providers: [PerformanceCounterBreadcrumbsResolver]
52 });
53
54 beforeEach(() => {
55 fixture = TestBed.createComponent(BreadcrumbsComponent);
f67539c2 56 router = TestBed.inject(Router);
11fdf7f2
TL
57 component = fixture.componentInstance;
58 fixture.detectChanges();
59 expect(component.crumbs).toEqual([]);
60 });
61
62 it('should create', () => {
63 expect(component).toBeTruthy();
64 expect(component.subscription).toBeDefined();
65 });
66
67 it('should run postProcess and split the breadcrumbs when navigating to hosts', fakeAsync(() => {
68 fixture.ngZone.run(() => {
69 router.navigateByUrl('/hosts');
70 });
71 tick();
72 expect(component.crumbs).toEqual([
73 { path: null, text: 'Cluster' },
74 { path: '/hosts', text: 'Hosts' }
75 ]);
76 }));
77
78 it('should display empty breadcrumb when navigating to perf_counters from unknown path', fakeAsync(() => {
79 fixture.ngZone.run(() => {
80 router.navigateByUrl('/perf_counters');
81 });
82 tick();
83 expect(component.crumbs).toEqual([
84 { path: null, text: 'Cluster' },
85 { path: null, text: '' },
86 { path: '', text: 'Performance Counters' }
87 ]);
88 }));
89
90 it('should display Monitor breadcrumb when navigating to perf_counters from Monitors', fakeAsync(() => {
91 fixture.ngZone.run(() => {
92 router.navigate(['/perf_counters'], { queryParams: { fromLink: '/monitor' } });
93 });
94 tick();
95 expect(component.crumbs).toEqual([
96 { path: null, text: 'Cluster' },
97 { path: '/monitor', text: 'Monitors' },
98 { path: '', text: 'Performance Counters' }
99 ]);
100 }));
101
102 it('should display Hosts breadcrumb when navigating to perf_counters from Hosts', fakeAsync(() => {
103 fixture.ngZone.run(() => {
104 router.navigate(['/perf_counters'], { queryParams: { fromLink: '/hosts' } });
105 });
106 tick();
107 expect(component.crumbs).toEqual([
108 { path: null, text: 'Cluster' },
109 { path: '/hosts', text: 'Hosts' },
110 { path: '', text: 'Performance Counters' }
111 ]);
112 }));
113
114 it('should show all 3 breadcrumbs when navigating to RBD Add', fakeAsync(() => {
115 fixture.ngZone.run(() => {
116 router.navigateByUrl('/block/rbd/add');
117 });
118 tick();
119 expect(component.crumbs).toEqual([
120 { path: null, text: 'Block' },
121 { path: '/block/rbd', text: 'Images' },
122 { path: '/block/rbd/add', text: 'Add' }
123 ]);
124 }));
125
126 it('should unsubscribe on ngOnDestroy', () => {
127 expect(component.subscription.closed).toBeFalsy();
128 component.ngOnDestroy();
129 expect(component.subscription.closed).toBeTruthy();
130 });
131});