Skip to content

Commit

Permalink
chore: added tests that need fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
Qjuh committed Mar 11, 2025
1 parent 8f41b17 commit 3981c9f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/builders/__tests__/components/v2/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const containerWithTextDisplay: APIContainerComponent = {
],
};

const button: APIButtonComponent = {
type: ComponentType.Button,
style: ButtonStyle.Primary,
const button = {
type: ComponentType.Button as const,
style: ButtonStyle.Primary as const,
custom_id: 'test',
label: 'test',
};
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('Container Components', () => {
.addSectionComponents(
new SectionBuilder()
.addTextDisplayComponents({ type: ComponentType.TextDisplay, content: 'test' })
.setPrimaryButtonAccessory(new PrimaryButtonBuilder(button)),
.setPrimaryButtonAccessory(button),
)
.addFileComponents({ type: ComponentType.File, file: { url: 'attachment://discord.png' } })
.setSpoiler(false)
Expand Down
24 changes: 23 additions & 1 deletion packages/builders/__tests__/components/v2/section.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentType } from 'discord-api-types/v10';
import { ButtonStyle, ComponentType } from 'discord-api-types/v10';
import { describe, expect, test } from 'vitest';
import { PrimaryButtonBuilder } from '../../../src/components/button/CustomIdButton';
import { SectionBuilder } from '../../../src/components/v2/Section';
Expand Down Expand Up @@ -123,6 +123,28 @@ describe('Section', () => {
});
});

test('GIVEN section with primary button accessory JSON THEN returns valid toJSON data', () => {
const section = new SectionBuilder()
.addTextDisplayComponents(new TextDisplayBuilder().setContent('Hello world'))
.setPrimaryButtonAccessory({
type: ComponentType.Button as const,
style: ButtonStyle.Primary as const,
custom_id: 'click_me',
lLabel: 'Click me',
});

expect(section.toJSON()).toEqual({
type: ComponentType.Section,
components: [{ type: ComponentType.TextDisplay, content: 'Hello world' }],
accessory: {
type: ComponentType.Button,
style: 1,
custom_id: 'click_me',
label: 'Click me',
},
});
});

test('GIVEN changing accessory type THEN returns the latest accessory in toJSON', () => {
const section = new SectionBuilder()
.addTextDisplayComponents(new TextDisplayBuilder().setContent('Hello world'))
Expand Down

0 comments on commit 3981c9f

Please sign in to comment.