1
|
|
|
import {PollState} from '../../src/helpers/interfaces'; |
2
|
|
|
import PollCard from '../../src/cards/PollCard'; |
3
|
|
|
import {dummyPollState} from '../dummy'; |
4
|
|
|
// @ts-ignore: unreasonable error |
5
|
|
|
import voteCardJson from '../json/vote_card.json'; |
6
|
|
|
|
7
|
|
|
describe('PollCard', () => { |
8
|
|
|
it('should return a valid GoogleAppsCardV1Card object when create() is called', () => { |
9
|
|
|
const state: PollState = { |
10
|
|
|
topic: 'Test Topic', |
11
|
|
|
choices: ['Choice 1', 'Choice 2'], |
12
|
|
|
votes: {}, |
13
|
|
|
}; |
14
|
|
|
const pollCard = new PollCard(state); |
15
|
|
|
const result = pollCard.create(); |
16
|
|
|
expect(result).toBeDefined(); |
17
|
|
|
expect(result.sections).toBeDefined(); |
18
|
|
|
}); |
19
|
|
|
|
20
|
|
|
it('should add a header to the card when the topic is less than or equal to 40 characters', () => { |
21
|
|
|
const state: PollState = { |
22
|
|
|
topic: 'Test Topic', |
23
|
|
|
choices: ['Choice 1', 'Choice 2'], |
24
|
|
|
votes: {}, |
25
|
|
|
}; |
26
|
|
|
const pollCard = new PollCard(state).create(); |
27
|
|
|
expect(pollCard.header).toBeDefined(); |
28
|
|
|
}); |
29
|
|
|
|
30
|
|
|
it('should add a section header to the card when the topic is greater than 40 characters', () => { |
31
|
|
|
const state: PollState = { |
32
|
|
|
topic: 'This is a very long topic that exceeds the character limit', |
33
|
|
|
choices: ['Choice 1', 'Choice 2'], |
34
|
|
|
votes: {}, |
35
|
|
|
}; |
36
|
|
|
const pollCard = new PollCard(state).create(); |
37
|
|
|
expect(pollCard.sections![0]).toBeDefined(); |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
it('should not add an "Add Option" button when optionable is false', () => { |
41
|
|
|
const state: PollState = { |
42
|
|
|
topic: 'Test Topic', |
43
|
|
|
choices: ['Choice 1', 'Choice 2'], |
44
|
|
|
votes: {}, |
45
|
|
|
optionable: false, |
46
|
|
|
}; |
47
|
|
|
const pollCard = new PollCard(state).create(); |
48
|
|
|
expect(pollCard.sections!.find((section) => section.widgets?.[0]?.buttonList?.buttons?.[0]?.text === 'Add Option')). |
49
|
|
|
toBeUndefined(); |
50
|
|
|
}); |
51
|
|
|
|
52
|
|
|
it('should return a valid GoogleAppsCardV1Section object even when the votes array is undefined', () => { |
53
|
|
|
const state: PollState = { |
54
|
|
|
topic: 'Test Topic', |
55
|
|
|
choices: ['Choice 1', 'Choice 2'], |
56
|
|
|
}; |
57
|
|
|
const pollCard = new PollCard(state); |
58
|
|
|
const result = pollCard.choiceSection(0, 0); |
59
|
|
|
expect(result).toBeDefined(); |
60
|
|
|
expect(result.widgets).toBeDefined(); |
61
|
|
|
expect(result.widgets?.[0]?.decoratedText?.topLabel).toBeUndefined(); |
62
|
|
|
|
63
|
|
|
// create choice section with the creator name (when added from new option) |
64
|
|
|
const result2 = pollCard.choiceSection(1, 0, 'Ahmad'); |
65
|
|
|
expect(result2).toBeDefined(); |
66
|
|
|
expect(result2.widgets?.[0]?.decoratedText?.topLabel).toEqual('Added by Ahmad'); |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
it('build vote card with dummy state', () => { |
70
|
|
|
const pollCard = new PollCard(dummyPollState).createCardWithId(); |
71
|
|
|
expect(pollCard.card).toEqual(voteCardJson); |
72
|
|
|
}); |
73
|
|
|
}); |
74
|
|
|
|