Skip to content

Commit 8806500

Browse files
Qjuhvladfrangu
authored andcommitted
chore: added tests that need fixing
1 parent c5c6be8 commit 8806500

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

packages/builders/__tests__/components/v2/container.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ const containerWithTextDisplay: APIContainerComponent = {
2424
],
2525
};
2626

27-
const button: APIButtonComponent = {
28-
type: ComponentType.Button,
29-
style: ButtonStyle.Primary,
27+
const button = {
28+
type: ComponentType.Button as const,
29+
style: ButtonStyle.Primary as const,
3030
custom_id: 'test',
3131
label: 'test',
3232
};
@@ -200,7 +200,7 @@ describe('Container Components', () => {
200200
.addSectionComponents(
201201
new SectionBuilder()
202202
.addTextDisplayComponents({ type: ComponentType.TextDisplay, content: 'test' })
203-
.setPrimaryButtonAccessory(new PrimaryButtonBuilder(button)),
203+
.setPrimaryButtonAccessory(button),
204204
)
205205
.addFileComponents({ type: ComponentType.File, file: { url: 'attachment://discord.png' } })
206206
.setSpoiler(false)

packages/builders/__tests__/components/v2/section.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ComponentType } from 'discord-api-types/v10';
1+
import { ButtonStyle, ComponentType } from 'discord-api-types/v10';
22
import { describe, expect, test } from 'vitest';
33
import { PrimaryButtonBuilder } from '../../../src/components/button/CustomIdButton';
44
import { SectionBuilder } from '../../../src/components/v2/Section';
@@ -123,6 +123,28 @@ describe('Section', () => {
123123
});
124124
});
125125

126+
test('GIVEN section with primary button accessory JSON THEN returns valid toJSON data', () => {
127+
const section = new SectionBuilder()
128+
.addTextDisplayComponents(new TextDisplayBuilder().setContent('Hello world'))
129+
.setPrimaryButtonAccessory({
130+
type: ComponentType.Button as const,
131+
style: ButtonStyle.Primary as const,
132+
custom_id: 'click_me',
133+
lLabel: 'Click me',
134+
});
135+
136+
expect(section.toJSON()).toEqual({
137+
type: ComponentType.Section,
138+
components: [{ type: ComponentType.TextDisplay, content: 'Hello world' }],
139+
accessory: {
140+
type: ComponentType.Button,
141+
style: 1,
142+
custom_id: 'click_me',
143+
label: 'Click me',
144+
},
145+
});
146+
});
147+
126148
test('GIVEN changing accessory type THEN returns the latest accessory in toJSON', () => {
127149
const section = new SectionBuilder()
128150
.addTextDisplayComponents(new TextDisplayBuilder().setContent('Hello world'))

0 commit comments

Comments
 (0)