]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/org-family-select/org-family-select.component.spec.ts
LP1830973 Angular 8 org family test spec repair
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / share / org-family-select / org-family-select.component.spec.ts
1 import {ComponentFixture, TestBed} from '@angular/core/testing';
2 import {Component, DebugElement, Input} from '@angular/core';
3 import {By} from '@angular/platform-browser';
4 import {OrgFamilySelectComponent} from './org-family-select.component';
5 import {ReactiveFormsModule} from '@angular/forms';
6 import {CookieService} from 'ngx-cookie';
7 import {OrgService} from '@eg/core/org.service';
8
9 @Component({
10     selector: 'eg-org-select',
11     template: ''
12 })
13 class MockOrgSelectComponent {
14     @Input() domId: string;
15     @Input() limitPerms: string;
16     @Input() initialOrgId: number;
17 }
18
19 describe('Component: OrgFamilySelect', () => {
20     let component: OrgFamilySelectComponent;
21     let fixture: ComponentFixture<OrgFamilySelectComponent>;
22     let includeAncestors: DebugElement;
23     let includeDescendants: DebugElement;
24     let orgServiceStub: Partial<OrgService>;
25     let cookieServiceStub: Partial<CookieService>;
26
27     beforeEach(() => {
28         // stub of OrgService for testing
29         // with a super simple org structure:
30         // 1 is the root note, with no children
31         orgServiceStub = {
32             root: () => {
33                 return {
34                     a: [],
35                     classname: 'aou',
36                     _isfieldmapper: true,
37                     id: () => 1};
38             },
39             get: (ouId: number) => {
40                 return {
41                     a: [],
42                     classname: 'aou',
43                     _isfieldmapper: true,
44                     children: () => Array() };
45             }
46         };
47         cookieServiceStub = {};
48         TestBed.configureTestingModule({
49             imports: [
50                 ReactiveFormsModule,
51             ], providers: [
52                 { provide: CookieService, useValue: cookieServiceStub },
53                 { provide: OrgService, useValue: orgServiceStub},
54             ], declarations: [
55                 OrgFamilySelectComponent,
56                 MockOrgSelectComponent,
57         ]});
58         fixture = TestBed.createComponent(OrgFamilySelectComponent);
59         component = fixture.componentInstance;
60         component.domId = 'family-test';
61         component.selectedOrgId = 1;
62         fixture.detectChanges();
63     });
64
65
66     it('provides includeAncestors checkbox by default', () => {
67         includeAncestors = fixture.debugElement.query(By.css('#family-test-include-ancestors'));
68         expect(includeAncestors.nativeElement).toBeTruthy();
69     });
70
71     it('provides includeDescendants checkbox by default', () => {
72         includeDescendants = fixture.debugElement.query(By.css('#family-test-include-descendants'));
73         expect(includeDescendants.nativeElement).toBeTruthy();
74     });
75
76     it('allows user to turn off includeAncestors checkbox', () => {
77         component.hideAncestorSelector = true;
78         fixture.detectChanges();
79         includeAncestors = fixture.debugElement.query(By.css('#family-test-include-ancestors'));
80         expect(includeAncestors).toBeNull();
81     });
82
83     it('allows user to turn off includeDescendants checkbox', () => {
84         component.hideDescendantSelector = true;
85         fixture.detectChanges();
86         includeDescendants = fixture.debugElement.query(By.css('#family-test-include-descendants'));
87         expect(includeDescendants).toBeNull();
88     });
89
90     it('disables includeAncestors checkbox when root OU is chosen', () => {
91         fixture.detectChanges();
92         includeAncestors = fixture.debugElement.query(By.css('#family-test-include-ancestors'));
93         expect(includeAncestors.nativeElement.disabled).toBe(true);
94     });
95
96     it('disables includeAncestors checkbox when OU has no children', () => {
97         fixture.detectChanges();
98         includeDescendants = fixture.debugElement.query(By.css('#family-test-include-descendants'));
99         expect(includeDescendants.nativeElement.disabled).toBe(true);
100     });
101
102 });
103