-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathng-custom-title.spec.ts
96 lines (79 loc) · 2.62 KB
/
ng-custom-title.spec.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { NgCustomTitleComponent } from './ng-custom-title.component';
describe('Component: NgCustomTitleComponent', () => {
let component: NgCustomTitleComponent;
let fixture: ComponentFixture<NgCustomTitleComponent>;
const $event = {
keyCode: 13, // RETURN
target: {
value: 'Wesley Safadão!',
selectionEnd: 15
},
preventDefault: () => true
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [FormsModule, CommonModule],
declarations: [NgCustomTitleComponent],
providers: [ ]
})
.compileComponents();
fixture = TestBed.createComponent(NgCustomTitleComponent);
component = fixture.componentInstance;
component.textareaField = {
nativeElement: {
focus : () => {}
}
};
});
describe('#startEdition', () => {
it('should go to edition mode', () => {
component.startEdition();
expect(component.isEditing).toBe(true);
});
it('should save the `titleBackup`', () => {
expect(component.titleBackup).toBe(undefined);
component.title = 'bafo';
component.startEdition();
expect(component.titleBackup).toBe('bafo');
});
});
describe('#keyActions', () => {
it('should allow saving the changes when `return` key is pressed and there is a valid title', () => {
component.title = 'Wesley Safadão!';
component.keyActions($event);
expect(component.isInvalid).toBe(false);
});
it('should not allow saving the changes when `return` key is pressed and the title is empty', () => {
component.title = '';
component.keyActions($event);
expect(component.isInvalid).toBe(true);
});
});
describe('#doneEdition', () => {
describe('valid', () => {
beforeEach(() => {
component.title = 'Wesley Safadão!';
});
it('should set the `isInvalid` flag', () => {
component.doneEdition();
expect(component.isInvalid).toBe(false);
});
it('should emit the change of the title', fakeAsync(() => {
spyOn(component.change, 'emit');
component.doneEdition();
tick(100);
expect(component.change.emit).toHaveBeenCalledWith('Wesley Safadão!');
}));
});
describe('invalid', () => {
it('should set the `isInvalid` flag as true for empty titles', () => {
component.title = '';
component.doneEdition();
expect(component.isInvalid).toBe(true);
});
});
});
});