Skip to content

Commit b52c17c

Browse files
committed
fix: labels in 14
1 parent f5b3f84 commit b52c17c

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

packages/builders/__tests__/components/selectMenu.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const selectMenu = () => new StringSelectMenuBuilder();
66
const selectMenuOption = () => new StringSelectMenuOptionBuilder();
77

88
const longStr = 'a'.repeat(256);
9+
const selectMenuOptionLabelAboveLimit = 'a'.repeat(101);
10+
const selectMenuOptionValueAboveLimit = 'a'.repeat(101);
11+
const selectMenuOptionDescriptionAboveLimit = 'a'.repeat(101);
912

1013
const selectMenuOptionData: APISelectMenuOption = {
1114
label: 'test',
@@ -53,12 +56,12 @@ describe('Select Menu Components', () => {
5356
expect(() => selectMenu().setDisabled()).not.toThrowError();
5457
expect(() => selectMenu().setPlaceholder('description')).not.toThrowError();
5558
const option = selectMenuOption()
56-
.setLabel('test')
59+
.setLabel('a'.repeat(100))
5760
.setValue('test')
5861
.setDefault(true)
5962
.setEmoji({ name: 'test' })
6063
.setDescription('description');
61-
expect(() => selectMenu().addOptions(option)).not.toThrowError();
64+
expect(() => selectMenu().setCustomId('customId').addOptions(option).toJSON()).not.toThrowError();
6265
expect(() => selectMenu().setOptions(option)).not.toThrowError();
6366
expect(() => selectMenu().setOptions({ label: 'test', value: 'test' })).not.toThrowError();
6467
expect(() => selectMenu().addOptions([option])).not.toThrowError();
@@ -156,13 +159,13 @@ describe('Select Menu Components', () => {
156159

157160
expect(() => {
158161
selectMenuOption()
159-
.setLabel(longStr)
160-
.setValue(longStr)
162+
.setLabel(selectMenuOptionLabelAboveLimit)
163+
.setValue(selectMenuOptionValueAboveLimit)
161164
// @ts-expect-error: Invalid default value
162165
.setDefault(-1)
163166
// @ts-expect-error: Invalid emoji
164167
.setEmoji({ name: 1 })
165-
.setDescription(longStr);
168+
.setDescription(selectMenuOptionDescriptionAboveLimit);
166169
}).toThrowError();
167170
});
168171

packages/builders/src/components/selectMenu/Assertions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Result, s } from '@sapphire/shapeshift';
22
import { ChannelType, ComponentType, SelectMenuDefaultValueType } from 'discord-api-types/v10';
33
import { isValidationEnabled } from '../../util/validation.js';
44
import { customIdValidator, emojiValidator, idValidator } from '../Assertions.js';
5-
import { labelValidator } from '../textInput/Assertions.js';
65

76
const selectMenuBasePredicate = s.object({
87
id: idValidator.optional(),
@@ -63,7 +62,7 @@ export const selectMenuUserPredicate = selectMenuBasePredicate
6362

6463
export const selectMenuStringOptionPredicate = s
6564
.object({
66-
label: labelValidator,
65+
label: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100),
6766
value: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100),
6867
description: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).optional(),
6968
emoji: emojiValidator.optional(),

packages/builders/src/components/selectMenu/StringSelectMenu.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ComponentType } from 'discord-api-types/v10';
22
import type { APIStringSelectComponent, APISelectMenuOption } from 'discord-api-types/v10';
33
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
4-
import { jsonOptionValidator, optionsLengthValidator, validateRequiredSelectMenuParameters } from '../Assertions.js';
4+
import { optionsLengthValidator, validateRequiredSelectMenuParameters } from '../Assertions.js';
5+
import { selectMenuStringOptionPredicate } from './Assertions.js';
56
import { BaseSelectMenuBuilder } from './BaseSelectMenu.js';
67
import { StringSelectMenuOptionBuilder } from './StringSelectMenuOption.js';
78

@@ -63,7 +64,7 @@ export class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSele
6364
...normalizedOptions.map((normalizedOption) =>
6465
normalizedOption instanceof StringSelectMenuOptionBuilder
6566
? normalizedOption
66-
: new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)),
67+
: new StringSelectMenuOptionBuilder(selectMenuStringOptionPredicate.parse(normalizedOption)),
6768
),
6869
);
6970
return this;
@@ -120,7 +121,7 @@ export class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSele
120121
...normalizedOptions.map((normalizedOption) =>
121122
normalizedOption instanceof StringSelectMenuOptionBuilder
122123
? normalizedOption
123-
: new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)),
124+
: new StringSelectMenuOptionBuilder(selectMenuStringOptionPredicate.parse(normalizedOption)),
124125
),
125126
);
126127

0 commit comments

Comments
 (0)