forked from discordjs/discord.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
components.test.ts
73 lines (63 loc) · 2.06 KB
/
components.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
68
69
70
71
72
73
import {
ButtonStyle,
ComponentType,
TextInputStyle,
type APIButtonComponent,
type APIMessageActionRowComponent,
type APISelectMenuComponent,
type APITextInputComponent,
type APIActionRowComponent,
} from 'discord-api-types/v10';
import { describe, test, expect } from 'vitest';
import {
ActionRowBuilder,
ButtonBuilder,
createComponentBuilder,
StringSelectMenuBuilder,
TextInputBuilder,
} from '../../src/index.js';
describe('createComponentBuilder', () => {
test.each([ButtonBuilder, StringSelectMenuBuilder, TextInputBuilder])(
'passing an instance of %j should return itself',
(Builder) => {
const builder = new Builder();
expect(createComponentBuilder(builder)).toBe(builder);
},
);
test('GIVEN an action row component THEN returns a ActionRowBuilder', () => {
const actionRow: APIActionRowComponent<APIMessageActionRowComponent> = {
components: [],
type: ComponentType.ActionRow,
};
expect(createComponentBuilder(actionRow)).toBeInstanceOf(ActionRowBuilder);
});
test('GIVEN a button component THEN returns a ButtonBuilder', () => {
const button: APIButtonComponent = {
custom_id: 'abc',
style: ButtonStyle.Primary,
type: ComponentType.Button,
};
expect(createComponentBuilder(button)).toBeInstanceOf(ButtonBuilder);
});
test('GIVEN a select menu component THEN returns a StringSelectMenuBuilder', () => {
const selectMenu: APISelectMenuComponent = {
custom_id: 'abc',
options: [],
type: ComponentType.StringSelect,
};
expect(createComponentBuilder(selectMenu)).toBeInstanceOf(StringSelectMenuBuilder);
});
test('GIVEN a text input component THEN returns a TextInputBuilder', () => {
const textInput: APITextInputComponent = {
custom_id: 'abc',
label: 'abc',
style: TextInputStyle.Short,
type: ComponentType.TextInput,
};
expect(createComponentBuilder(textInput)).toBeInstanceOf(TextInputBuilder);
});
test('GIVEN an unknown component type THEN throws error', () => {
// @ts-expect-error: Unknown component type
expect(() => createComponentBuilder({ type: 'invalid' })).toThrowError();
});
});