mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
feat(StringSelectMenu): add spliceOptions() (#8937)
* feat(StringSelectMenu): add `spliceOptions()` * fix: requested changes Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -29,6 +29,20 @@ const selectMenuData: APISelectMenuComponent = {
|
||||
options: [selectMenuOptionData],
|
||||
};
|
||||
|
||||
function makeStringSelectMenuWithOptions() {
|
||||
const selectMenu = new StringSelectMenuBuilder();
|
||||
selectMenu.addOptions(
|
||||
{ label: 'foo', value: 'bar' },
|
||||
{ label: 'foo2', value: 'bar2' },
|
||||
{ label: 'foo3', value: 'bar3' },
|
||||
);
|
||||
return selectMenu;
|
||||
}
|
||||
|
||||
function mapStringSelectMenuOptionBuildersToJson(selectMenu: StringSelectMenuBuilder) {
|
||||
return selectMenu.options.map((option) => option.toJSON());
|
||||
}
|
||||
|
||||
describe('Select Menu Components', () => {
|
||||
describe('Assertion Tests', () => {
|
||||
test('GIVEN valid inputs THEN Select Menu does not throw', () => {
|
||||
@@ -176,5 +190,40 @@ describe('Select Menu Components', () => {
|
||||
).toEqual(selectMenuData);
|
||||
expect(new StringSelectMenuOptionBuilder(selectMenuOptionData).toJSON()).toEqual(selectMenuOptionData);
|
||||
});
|
||||
|
||||
test('GIVEN a StringSelectMenuBuilder using StringSelectMenuBuilder#spliceOptions works', () => {
|
||||
expect(
|
||||
mapStringSelectMenuOptionBuildersToJson(makeStringSelectMenuWithOptions().spliceOptions(0, 1)),
|
||||
).toStrictEqual([
|
||||
{ label: 'foo2', value: 'bar2' },
|
||||
{ label: 'foo3', value: 'bar3' },
|
||||
]);
|
||||
|
||||
expect(
|
||||
mapStringSelectMenuOptionBuildersToJson(
|
||||
makeStringSelectMenuWithOptions().spliceOptions(0, 1, selectMenuOptionData),
|
||||
),
|
||||
).toStrictEqual([selectMenuOptionData, { label: 'foo2', value: 'bar2' }, { label: 'foo3', value: 'bar3' }]);
|
||||
|
||||
expect(
|
||||
mapStringSelectMenuOptionBuildersToJson(
|
||||
makeStringSelectMenuWithOptions().spliceOptions(0, 3, selectMenuOptionData),
|
||||
),
|
||||
).toStrictEqual([selectMenuOptionData]);
|
||||
|
||||
expect(() =>
|
||||
makeStringSelectMenuWithOptions().spliceOptions(
|
||||
0,
|
||||
0,
|
||||
...Array.from({ length: 26 }, () => selectMenuOptionData),
|
||||
),
|
||||
).toThrowError();
|
||||
|
||||
expect(() =>
|
||||
makeStringSelectMenuWithOptions()
|
||||
.setOptions(Array.from({ length: 25 }, () => selectMenuOptionData))
|
||||
.spliceOptions(-1, 2, selectMenuOptionData, selectMenuOptionData),
|
||||
).toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user