Newer
Older
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { CommonModule } from "@angular/common"
import { ComponentFixture, TestBed } from "@angular/core/testing"
import { NoopAnimationsModule } from "@angular/platform-browser/animations"
import { MockStore, provideMockStore } from "@ngrx/store/testing"
import { ComponentsModule } from "src/components"
import { viewerStateSelectTemplateWithId, viewerStateToggleLayer } from "src/services/state/viewerState.store.helper"
import { AngularMaterialModule } from "src/sharedModules"
import { QuickTourModule } from "src/ui/quickTour"
import { GetGroupedParcPipe } from "../pipes/getGroupedParc.pipe"
import { GetIndividualParcPipe } from "../pipes/getIndividualParc.pipe"
import { GetNonbaseParcPipe } from "../pipes/getNonBaseParc.pipe"
import { AtlasLayerSelector } from "./atlasLayerSelector.component"
describe("> atlasLayerSelector.component.ts", () => {
describe("> AtlasLayerSelector", () => {
let fixture: ComponentFixture<AtlasLayerSelector>
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
CommonModule,
AngularMaterialModule,
NoopAnimationsModule,
QuickTourModule,
ComponentsModule,
],
declarations: [
AtlasLayerSelector,
GetIndividualParcPipe,
GetNonbaseParcPipe,
GetGroupedParcPipe,
],
providers: [
provideMockStore()
]
}).compileComponents()
})
it("> can be init", () => {
fixture = TestBed.createComponent(AtlasLayerSelector)
expect(fixture).toBeTruthy()
})
describe("> methods", () => {
beforeEach(() => {
fixture = TestBed.createComponent(AtlasLayerSelector)
})
describe("> selectParcellationWithName", () => {
let tmplSupportParcPipeTransform: jasmine.Spy
let storeDispatchSpy: jasmine.Spy
const dummySelectedTmpl = {
"this": "obj"
}
const dummyParc = {
"foo": "bar",
"availableIn": [{
"baz": "yoo"
}]
}
beforeEach(() => {
tmplSupportParcPipeTransform = spyOn(fixture.componentInstance['currTmplSupportParcPipe'], 'transform')
const store = TestBed.inject(MockStore)
storeDispatchSpy = spyOn(store, 'dispatch')
fixture.componentInstance['selectedTemplate'] = dummySelectedTmpl
})
afterEach(() => {
if (tmplSupportParcPipeTransform) {
tmplSupportParcPipeTransform.calls.reset()
}
})
it("> calls pipe.transform", () => {
tmplSupportParcPipeTransform.and.returnValue(true)
fixture.componentInstance.selectParcellationWithName(dummyParc)
expect(tmplSupportParcPipeTransform).toHaveBeenCalledWith(dummySelectedTmpl, dummyParc)
expect(storeDispatchSpy).toHaveBeenCalledTimes(1)
})
const tmplChgReqParam = [true, false]
for (const tmplChgReq of tmplChgReqParam) {
describe(`> tmplChgReq: ${tmplChgReq}`, () => {
it("> expect the correct type of method to be called", () => {
tmplSupportParcPipeTransform.and.returnValue(!tmplChgReq)
fixture.componentInstance.selectParcellationWithName(dummyParc)
const allArgs = storeDispatchSpy.calls.allArgs()
expect(allArgs.length).toEqual(1)
expect(allArgs[0].length).toEqual(1)
const action = allArgs[0][0]
const expectedAction = tmplChgReq
? viewerStateSelectTemplateWithId
: viewerStateToggleLayer
expect(action.type).toEqual(expectedAction.type)
})
})
}
})
})
})
})