]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/trim.directive.spec.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / directives / trim.directive.spec.ts
CommitLineData
92f5a8d4
TL
1import { Component } from '@angular/core';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
3import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
4import { By } from '@angular/platform-browser';
5
f67539c2 6import { configureTestBed } from '~/testing/unit-test-helper';
92f5a8d4
TL
7import { CdFormGroup } from '../forms/cd-form-group';
8import { TrimDirective } from './trim.directive';
9
10@Component({
11 template: `
12 <form [formGroup]="trimForm">
13 <input type="text" formControlName="trimInput" cdTrim />
14 </form>
15 `
16})
17export class TrimComponent {
18 trimForm: CdFormGroup;
19 constructor() {
20 this.trimForm = new CdFormGroup({
21 trimInput: new FormControl()
22 });
23 }
24}
25
26describe('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});