Passed
Pull Request — master (#2)
by Muhammad Dyas
01:24
created

tests/cards/poll-card.test.ts   A

Complexity

Total Complexity 5
Complexity/F 0

Size

Lines of Code 60
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 5
mnd 5
bc 5
fnc 0
bpm 0
cpm 0
noi 0
1
import {PollState} from '../../src/helpers/interfaces';
2
import {PollCard} from '../../src/cards/PollCard';
3
4
describe('PollCard', () => {
5
  it('should return a valid GoogleAppsCardV1Card object when create() is called', () => {
6
    const state: PollState = {
7
      topic: 'Test Topic',
8
      choices: ['Choice 1', 'Choice 2'],
9
      votes: {},
10
    };
11
    const pollCard = new PollCard(state);
12
    const result = pollCard.create();
13
    expect(result).toBeDefined();
14
    expect(result.sections).toBeDefined();
15
  });
16
17
  it('should add a header to the card when the topic is less than or equal to 40 characters', () => {
18
    const state: PollState = {
19
      topic: 'Test Topic',
20
      choices: ['Choice 1', 'Choice 2'],
21
      votes: {},
22
    };
23
    const pollCard = new PollCard(state).create();
24
    expect(pollCard.header).toBeDefined();
25
  });
26
27
  it('should add a section header to the card when the topic is greater than 40 characters', () => {
28
    const state: PollState = {
29
      topic: 'This is a very long topic that exceeds the character limit',
30
      choices: ['Choice 1', 'Choice 2'],
31
      votes: {},
32
    };
33
    const pollCard = new PollCard(state).create();
34
    expect(pollCard.sections![0]).toBeDefined();
35
  });
36
37
  it('should not add an "Add Option" button when optionable is false', () => {
38
    const state: PollState = {
39
      topic: 'Test Topic',
40
      choices: ['Choice 1', 'Choice 2'],
41
      votes: {},
42
      optionable: false,
43
    };
44
    const pollCard = new PollCard(state).create();
45
    expect(pollCard.sections!.find((section) => section.widgets?.[0]?.buttonList?.buttons?.[0]?.text === 'Add Option')).
46
      toBeUndefined();
47
  });
48
49
  it('should return a valid GoogleAppsCardV1Section object even when the votes array is undefined', () => {
50
    const state: PollState = {
51
      topic: 'Test Topic',
52
      choices: ['Choice 1', 'Choice 2'],
53
    };
54
    const pollCard = new PollCard(state);
55
    const result = pollCard.choiceSection(0, 0);
56
    expect(result).toBeDefined();
57
    expect(result.widgets).toBeDefined();
58
  });
59
});
60