]> 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
LP 2061136 follow-up: ng lint --fix
[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() ariaLabel?: string;
17     @Input() applyOrgId(id: number) {}
18 }
19
20 describe('Component: OrgFamilySelect', () => {
21     let component: OrgFamilySelectComponent;
22     let fixture: ComponentFixture<OrgFamilySelectComponent>;
23     let includeAncestors: DebugElement;
24     let includeDescendants: DebugElement;
25     let orgServiceStub: Partial<OrgService>;
26     let cookieServiceStub: Partial<CookieService>;
27
28     beforeEach(() => {
29         // stub of OrgService for testing
30         // with a super simple org structure:
31         // 1 is the root note, with no children
32         orgServiceStub = {
33             root: () => {
34                 return {
35                     a: [],
36                     classname: 'aou',
37                     _isfieldmapper: true,
38                     id: () => 1};
39             },
40             get: (ouId: number) => {
41                 return {
42                     a: [],
43                     classname: 'aou',
44                     _isfieldmapper: true,
45                     children: () => Array() };
46             }
47         };
48         cookieServiceStub = {};
49         TestBed.configureTestingModule({
50             imports: [
51                 ReactiveFormsModule,
52             ], providers: [
53                 { provide: CookieService, useValue: cookieServiceStub },
54                 { provide: OrgService, useValue: orgServiceStub},
55             ], declarations: [
56                 OrgFamilySelectComponent,
57                 MockOrgSelectComponent,
58             ]});
59         fixture = TestBed.createComponent(OrgFamilySelectComponent);
60         component = fixture.componentInstance;
61         component.domId = 'family-test';
62         component.selectedOrgId = 1;
63         fixture.detectChanges();
64     });
65
66
67     it('provides includeAncestors checkbox by default', () => {
68         includeAncestors = fixture.debugElement.query(By.css('#family-test-include-ancestors'));
69         expect(includeAncestors.nativeElement).toBeTruthy();
70     });
71
72     it('provides includeDescendants checkbox by default', () => {
73         includeDescendants = fixture.debugElement.query(By.css('#family-test-include-descendants'));
74         expect(includeDescendants.nativeElement).toBeTruthy();
75     });
76
77     it('allows user to turn off includeAncestors checkbox', () => {
78         component.hideAncestorSelector = true;
79         fixture.detectChanges();
80         includeAncestors = fixture.debugElement.query(By.css('#family-test-include-ancestors'));
81         expect(includeAncestors).toBeNull();
82     });
83
84     it('allows user to turn off includeDescendants checkbox', () => {
85         component.hideDescendantSelector = true;
86         fixture.detectChanges();
87         includeDescendants = fixture.debugElement.query(By.css('#family-test-include-descendants'));
88         expect(includeDescendants).toBeNull();
89     });
90
91     it('disables includeAncestors checkbox when root OU is chosen', () => {
92         fixture.detectChanges();
93         includeAncestors = fixture.debugElement.query(By.css('#family-test-include-ancestors'));
94         expect(includeAncestors.nativeElement.disabled).toBe(true);
95     });
96
97     it('disables includeAncestors checkbox when OU has no children', () => {
98         fixture.detectChanges();
99         includeDescendants = fixture.debugElement.query(By.css('#family-test-include-descendants'));
100         expect(includeDescendants.nativeElement.disabled).toBe(true);
101     });
102
103 });
104