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 very simple org structure:
40 get: (ouId: number) => {
45 children: () => Array(2 - ouId) };
48 cookieServiceStub = {};
49 TestBed.configureTestingModule({
53 { provide: CookieService, useValue: cookieServiceStub },
54 { provide: OrgService, useValue: orgServiceStub},
56 OrgFamilySelectComponent,
57 MockOrgSelectComponent,
59 fixture = TestBed.createComponent(OrgFamilySelectComponent);
60 component = fixture.componentInstance;
61 component.domId = 'family-test';
62 fixture.detectChanges();
66 it('provides includeAncestors checkbox by default', () => {
67 fixture.whenStable().then(() => {
68 includeAncestors = fixture.debugElement.query(By.css('#family-test-include-ancestors'));
69 expect(includeAncestors.nativeElement).toBeTruthy();
73 it('provides includeDescendants checkbox by default', () => {
74 fixture.whenStable().then(() => {
75 includeDescendants = fixture.debugElement.query(By.css('#family-test-include-descendants'));
76 expect(includeDescendants.nativeElement).toBeTruthy();
80 it('allows user to turn off includeAncestors checkbox', () => {
81 fixture.whenStable().then(() => {
82 component.hideAncestorSelector = true;
83 fixture.detectChanges();
84 includeAncestors = fixture.debugElement.query(By.css('#family-test-include-ancestors'));
85 expect(includeAncestors).toBeNull();
89 it('allows user to turn off includeDescendants checkbox', () => {
90 fixture.whenStable().then(() => {
91 component.hideDescendantSelector = true;
92 fixture.detectChanges();
93 includeDescendants = fixture.debugElement.query(By.css('#family-test-include-descendants'));
94 expect(includeDescendants).toBeNull();
98 it('disables includeAncestors checkbox when root OU is chosen', () => {
99 fixture.whenStable().then(() => {
100 component.selectedOrgId = 1;
101 fixture.detectChanges();
102 includeAncestors = fixture.debugElement.query(By.css('#family-test-include-ancestors'));
103 expect(includeAncestors.nativeElement.disabled).toBe(true);