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';
10 selector: 'eg-org-select',
13 class MockOrgSelectComponent {
14 @Input() domId: string;
15 @Input() limitPerms: string;
16 @Input() initialOrgId: number;
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>;
28 // stub of OrgService for testing
29 // with a super simple org structure:
30 // 1 is the root note, with no children
39 get: (ouId: number) => {
44 children: () => Array() };
47 cookieServiceStub = {};
48 TestBed.configureTestingModule({
52 { provide: CookieService, useValue: cookieServiceStub },
53 { provide: OrgService, useValue: orgServiceStub},
55 OrgFamilySelectComponent,
56 MockOrgSelectComponent,
58 fixture = TestBed.createComponent(OrgFamilySelectComponent);
59 component = fixture.componentInstance;
60 component.domId = 'family-test';
61 component.selectedOrgId = 1;
62 fixture.detectChanges();
66 it('provides includeAncestors checkbox by default', () => {
67 includeAncestors = fixture.debugElement.query(By.css('#family-test-include-ancestors'));
68 expect(includeAncestors.nativeElement).toBeTruthy();
71 it('provides includeDescendants checkbox by default', () => {
72 includeDescendants = fixture.debugElement.query(By.css('#family-test-include-descendants'));
73 expect(includeDescendants.nativeElement).toBeTruthy();
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();
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();
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);
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);