/
header-navigation.component.spec.ts
77 lines (69 loc) · 2.97 KB
/
header-navigation.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
import { instance, mock, when } from 'ts-mockito';
import { ShoppingFacade } from 'ish-core/facades/shopping.facade';
import { NavigationCategory } from 'ish-core/models/navigation-category/navigation-category.model';
import { SubCategoryNavigationComponent } from 'ish-shell/header/sub-category-navigation/sub-category-navigation.component';
import { LazyContentIncludeComponent } from 'ish-shell/shared/lazy-content-include/lazy-content-include.component';
import { HeaderNavigationComponent } from './header-navigation.component';
describe('Header Navigation Component', () => {
let component: HeaderNavigationComponent;
let fixture: ComponentFixture<HeaderNavigationComponent>;
let element: HTMLElement;
let shoppingFacade: ShoppingFacade;
beforeEach(async () => {
shoppingFacade = mock(ShoppingFacade);
await TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [
HeaderNavigationComponent,
MockComponent(FaIconComponent),
MockComponent(SubCategoryNavigationComponent),
MockComponent(LazyContentIncludeComponent),
],
providers: [{ provide: ShoppingFacade, useFactory: () => instance(shoppingFacade) }],
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(HeaderNavigationComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
const categories = [
{ uniqueId: 'A', name: 'CAT_A', url: '/cat/A', hasChildren: true },
{ uniqueId: 'B', name: 'CAT_B', url: '/cat/B' },
{ uniqueId: 'C', name: 'CAT_C', url: '/cat/C' },
] as NavigationCategory[];
when(shoppingFacade.navigationCategories$()).thenReturn(of(categories));
});
it('should be created', () => {
expect(component).toBeTruthy();
expect(element).toBeTruthy();
expect(() => fixture.detectChanges()).not.toThrow();
expect(element).toMatchInlineSnapshot(`
<ul class="navbar-nav main-navigation-list">
<li class="dropdown">
<a ng-reflect-router-link="/cat/A" data-testing-id="A-link" style="width: 100%" href="/cat/A">
CAT_A
</a>
</li>
<li class="dropdown">
<a ng-reflect-router-link="/cat/B" data-testing-id="B-link" style="width: 100%" href="/cat/B">
CAT_B
</a>
</li>
<li class="dropdown">
<a ng-reflect-router-link="/cat/C" data-testing-id="C-link" style="width: 100%" href="/cat/C">
CAT_C
</a>
</li>
<ish-lazy-content-include
includeid="include.header.navigation.pagelet2-Include"
ng-reflect-include-id="include.header.navigation.page"
></ish-lazy-content-include>
</ul>
`);
});
});