Skip to content

Commit

Permalink
chore: make requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Feb 25, 2022
1 parent 9def045 commit 7da5407
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 16 additions & 1 deletion packages/builders/__tests__/components/selectMenu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe('Select Menu Components', () => {
expect(() => selectMenu().setDisabled(true)).not.toThrowError();
expect(() => selectMenu().setDisabled()).not.toThrowError();
expect(() => selectMenu().setPlaceholder('description')).not.toThrowError();

const option = selectMenuOption()
.setLabel('test')
.setValue('test')
Expand All @@ -48,6 +47,17 @@ describe('Select Menu Components', () => {
expect(() => selectMenu().addOptions(option)).not.toThrowError();
expect(() => selectMenu().setOptions(option)).not.toThrowError();
expect(() => selectMenu().setOptions({ label: 'test', value: 'test' })).not.toThrowError();
expect(() =>
selectMenu().addOptions({
label: 'test',
value: 'test',
emoji: {
id: '123',
name: 'test',
animated: true,
},
}),
).not.toThrowError();

const options = new Array<APISelectMenuOption>(25).fill({ label: 'test', value: 'test' });
expect(() => selectMenu().addOptions(...options)).not.toThrowError();
Expand All @@ -69,6 +79,11 @@ describe('Select Menu Components', () => {
expect(() => selectMenu().setPlaceholder(longStr)).toThrowError();
// @ts-expect-error
expect(() => selectMenu().addOptions({ label: 'test' })).toThrowError();
expect(() => selectMenu().addOptions({ label: longStr, value: 'test' })).toThrowError();
expect(() => selectMenu().addOptions({ value: longStr, label: 'test' })).toThrowError();
expect(() => selectMenu().addOptions({ label: 'test', value: 'test', description: longStr })).toThrowError();
// @ts-expect-error
expect(() => selectMenu().addOptions({ label: 'test', value: 'test', default: 100 })).toThrowError();
// @ts-expect-error
expect(() => selectMenu().addOptions({ value: 'test' })).toThrowError();
// @ts-expect-error
Expand Down
8 changes: 6 additions & 2 deletions packages/builders/src/components/Assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ export const placeholderValidator = z.string().max(100);
export const minMaxValidator = z.number().int().min(0).max(25);

export const optionsValidator = z.object({}).array().nonempty();
export const labelValueDescriptionValidator = z.string().min(1).max(100);
export const optionValidator = z.object({
label: z.string(),
value: z.string(),
label: labelValueDescriptionValidator,
value: labelValueDescriptionValidator,
description: labelValueDescriptionValidator.optional(),
emoji: emojiValidator.optional(),
default: z.boolean().optional(),
});
export const optionsLengthValidator = z.number().int().min(0).max(25);

Expand Down

0 comments on commit 7da5407

Please sign in to comment.