1 import { Component, DebugElement, Input } from '@angular/core';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { By } from '@angular/platform-browser';
5 import { configureTestBed } from '../../../testing/unit-test-helper';
6 import { Permission } from '../models/permissions';
7 import { AuthStorageService } from '../services/auth-storage.service';
8 import { FormInputDisableDirective } from './form-input-disable.directive';
9 import { FormScopeDirective } from './form-scope.directive';
13 <form cdFormScope="osd">
14 <input type="checkbox" />
18 export class FormDisableComponent {}
20 class MockFormScopeDirective {
21 @Input() cdFormScope = 'osd';
24 describe('FormInputDisableDirective', () => {
25 let fakePermissions: Permission;
26 let authStorageService: AuthStorageService;
27 let directive: FormInputDisableDirective;
28 let fixture: ComponentFixture<FormDisableComponent>;
29 let inputElement: DebugElement;
31 declarations: [FormScopeDirective, FormInputDisableDirective, FormDisableComponent]
35 directive = new FormInputDisableDirective(
36 new MockFormScopeDirective(),
37 new AuthStorageService(),
47 authStorageService = TestBed.get(AuthStorageService);
48 spyOn(authStorageService, 'getPermissions').and.callFake(() => ({
52 fixture = TestBed.createComponent(FormDisableComponent);
53 inputElement = fixture.debugElement.query(By.css('input'));
60 it('should create an instance', () => {
61 expect(directive).toBeTruthy();
64 it('should disable the input if update permission is false', () => {
65 fixture.detectChanges();
66 expect(inputElement.nativeElement.disabled).toBeTruthy();
69 it('should not disable the input if update permission is true', () => {
70 fakePermissions.update = true;
71 fakePermissions.read = false;
72 fixture.detectChanges();
73 expect(inputElement.nativeElement.disabled).toBeFalsy();