1 | import { test } from 'ava';
|
2 | import { Play, playToString } from './models';
|
3 |
|
4 | const EMPTY_STRING = '';
|
5 |
|
6 | test(`'playToString' is a function`, t => {
|
7 | t.is(typeof playToString, 'function');
|
8 | });
|
9 |
|
10 | test(`'playToString' returns the name and project count`, t => {
|
11 | const EXPECTED_PROJECT_COUNT = 3;
|
12 | const EXPECTED_NAME = 'TestPlay';
|
13 | const EXPECTED_OUTPUT = `${EXPECTED_NAME} (${EXPECTED_PROJECT_COUNT})`;
|
14 | const play: Play = {
|
15 | name: EXPECTED_NAME,
|
16 | projects: Array(EXPECTED_PROJECT_COUNT).fill(0)
|
17 | };
|
18 | const actualOutput = playToString(play);
|
19 | t.is(actualOutput, EXPECTED_OUTPUT);
|
20 | });
|
21 |
|
22 | test(`'playToString' returns an empty string when play is falsy`, t => {
|
23 | const actualOutput = playToString(null);
|
24 | t.is(actualOutput, EMPTY_STRING);
|
25 | });
|
26 |
|
27 | test(`'playToString' gracefully handles a missing projects array`, t => {
|
28 | const EXPECTED_NAME = 'TestPlay';
|
29 | const EXPECTED_OUTPUT = `${EXPECTED_NAME} (0)`;
|
30 | const play: Play = {
|
31 | name: EXPECTED_NAME
|
32 | };
|
33 | const actualOutput = playToString(play);
|
34 | t.is(actualOutput, EXPECTED_OUTPUT);
|
35 | }); |
\ | No newline at end of file |