aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/directives/clickOutside/clickOutside.directive.spec.ts
blob: 8edfb8733fe409be1e38500e57329e29a4849c06 (plain)
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
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {Component, DebugElement} from "@angular/core";
import {By} from "@angular/platform-browser";
import {ClickOutsideDirective} from "./clickOutside.directive";

@Component({
  template:
      `<div id="innerDiv" [clickOutside] [classElements]="['outsideDivShouldNotTrigger']"></div>
       <div class="outsideDivShouldTrigger"></div>
       <div class="outsideDivShouldNotTrigger"></div>`
})
class TestHoverFocusComponent {
}


describe('Click outside Directive', () => {
  let component: TestHoverFocusComponent;
  let fixture: ComponentFixture<TestHoverFocusComponent>;
  let directiveInstance : ClickOutsideDirective;
  let outsideDivShouldNotTrigger: DebugElement;
  let outsideDivShouldTrigger: DebugElement;
  let innerDiv: DebugElement;

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [TestHoverFocusComponent, ClickOutsideDirective]
    });
    fixture = TestBed.createComponent(TestHoverFocusComponent);
    component = fixture.componentInstance;
    outsideDivShouldNotTrigger = fixture.debugElement.query(By.css('.outsideDivShouldNotTrigger'));
    outsideDivShouldTrigger = fixture.debugElement.query(By.css('.outsideDivShouldTrigger'));
    innerDiv = fixture.debugElement.query(By.css('#innerDiv'));
    directiveInstance = innerDiv.injector.get(ClickOutsideDirective);
  });

  test('directive should be defined', () => {
    expect(directiveInstance).toBeDefined();
  });

  test(`should have list of class's`, () => {
    fixture.detectChanges();
    expect(directiveInstance.classElements).toEqual(['outsideDivShouldNotTrigger']);
  });

  test('should not trigger output on click outside', () => {
    fixture.detectChanges();
    spyOn(directiveInstance.clickOutsideTrigger, 'next');
    outsideDivShouldNotTrigger.nativeElement.click();
    expect(directiveInstance.clickOutsideTrigger.next).toHaveBeenCalledTimes(0);
  });

});