-
Notifications
You must be signed in to change notification settings - Fork 1
/
voting-card.component.spec.ts
71 lines (59 loc) · 2.06 KB
/
voting-card.component.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
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { VotingCardComponent } from './voting-card.component';
describe('VotingCardComponent', () => {
let component: VotingCardComponent;
let fixture: ComponentFixture<VotingCardComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule
],
declarations: [
VotingCardComponent
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(VotingCardComponent);
component = fixture.componentInstance;
component.cardData = {
id: 1,
name: 'Mark',
image: 'url',
description: 'Lorem ipsu',
timeArea: 'Bussiness',
timeJob: '1 month ago',
votesUp: 7,
votesDown: 3
};
fixture.detectChanges();
spyOn(component.voteAction, 'emit').and.callThrough();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should vote with default selected value', () => {
component.voteNow();
expect(component.voteAction.emit).toHaveBeenCalledWith({
cardData: component.cardData,
typeVote: 'votesUp'
});
});
it('should vote with new selected value', () => {
component.votingForm.controls.vote.setValue(false);
component.voteNow();
expect(component.voteAction.emit).toHaveBeenCalledWith({
cardData: component.cardData,
typeVote: 'votesDown'
});
});
it('should get total votes from given cardData', () => {
expect(component.getTotalVotes()).toEqual(10);
});
it('should get percentage of votes depending on entry data', () => {
expect(component.getWidth(3)).toEqual('30%');
expect(component.getWidth(5)).toEqual('50%');
expect(component.getWidth(1)).toEqual('10%');
});
});