-
Notifications
You must be signed in to change notification settings - Fork 34
/
GameBoardBuilder.test.ts
67 lines (56 loc) 路 2.5 KB
/
GameBoardBuilder.test.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
import GameBoardBuilder from '@bot/builder/GameBoardBuilder';
import localize from '@i18n/localize';
import AI from '@tictactoe/AI';
import { Player } from '@tictactoe/Player';
jest.mock('@tictactoe/AI');
describe('GameBoardBuilder', () => {
let builder: GameBoardBuilder;
beforeAll(() => {
localize.loadFromLocale('en');
});
beforeEach(() => {
builder = new GameBoardBuilder();
});
it('should send empty message by default', () => {
expect(builder.toMessageOptions()).toEqual({
allowedMentions: { parse: ['users'] },
content: '',
components: []
});
});
it('should compute title based on entity names', () => {
builder.withTitle({ id: '1', displayName: 'entity1' }, { id: '2', displayName: 'entity2' });
expect(builder.toMessageOptions()).toEqual(
expect.objectContaining({ content: ':game_die: `entity1` **VS** `entity2`\n\n' })
);
});
it('should compute board using custom emojies', () => {
builder
.withEmojies(':dog:', ':cat:')
.withBoard(2, [Player.First, Player.Second, Player.Second, Player.First]);
expect(builder.toMessageOptions()).toEqual(
expect.objectContaining({ content: ':dog: :cat: \n:cat: :dog: \n' })
);
});
it('should add an empty line between board and state if both defined', () => {
builder.withBoard(1, [Player.None]).withEntityPlaying();
expect(builder.toMessageOptions().content).toContain('\n');
});
it.each`
entity | state
${undefined} | ${'Reactions are loading, please wait...'}
${new AI()} | ${':robot: AI is playing, please wait...'}
${{ toString: () => 'fake' }} | ${'fake, select your move:'}
`('should set state based if playing entity is $entity', ({ entity, state }) => {
builder.withEntityPlaying(entity);
expect(builder.toMessageOptions()).toEqual(expect.objectContaining({ content: state }));
});
it.each`
entity | state
${undefined} | ${"No one won the game, it's a tie! Let's try again?"}
${{ toString: () => 'fake' }} | ${':tada: fake has won the game!'}
`('should set state based if winning entity is $entity', ({ entity, state }) => {
builder.withEndingMessage(entity);
expect(builder.toMessageOptions()).toEqual(expect.objectContaining({ content: state }));
});
});