]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/trim.directive.spec.ts
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / directives / trim.directive.spec.ts
1 import { Component } from '@angular/core';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
4 import { By } from '@angular/platform-browser';
5
6 import { configureTestBed } from '../../../testing/unit-test-helper';
7 import { CdFormGroup } from '../forms/cd-form-group';
8 import { TrimDirective } from './trim.directive';
9
10 @Component({
11 template: `
12 <form [formGroup]="trimForm">
13 <input type="text" formControlName="trimInput" cdTrim />
14 </form>
15 `
16 })
17 export class TrimComponent {
18 trimForm: CdFormGroup;
19 constructor() {
20 this.trimForm = new CdFormGroup({
21 trimInput: new FormControl()
22 });
23 }
24 }
25
26 describe('TrimDirective', () => {
27 configureTestBed({
28 imports: [FormsModule, ReactiveFormsModule],
29 declarations: [TrimDirective, TrimComponent]
30 });
31
32 it('should create an instance', () => {
33 const directive = new TrimDirective(null);
34 expect(directive).toBeTruthy();
35 });
36
37 it('should trim', () => {
38 const fixture: ComponentFixture<TrimComponent> = TestBed.createComponent(TrimComponent);
39 const component: TrimComponent = fixture.componentInstance;
40 const inputElement: HTMLInputElement = fixture.debugElement.query(By.css('input'))
41 .nativeElement;
42 fixture.detectChanges();
43
44 inputElement.value = ' a b ';
45 inputElement.dispatchEvent(new Event('input'));
46 const expectedValue = 'a b';
47 expect(inputElement.value).toBe(expectedValue);
48 expect(component.trimForm.getValue('trimInput')).toBe(expectedValue);
49 });
50 });