Skip to content

Commit

Permalink
chore: finish updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
didinele committed Oct 28, 2022
1 parent 85a6cc1 commit e6eeb88
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions packages/discord.js/typings/index.test-d.ts
Expand Up @@ -24,6 +24,7 @@ import {
APIEmbed,
ApplicationCommandType,
APIMessage,
APIStringSelectComponent,
} from 'discord-api-types/v10';
import {
ApplicationCommand,
Expand Down Expand Up @@ -72,7 +73,6 @@ import {
ReactionCollector,
Role,
RoleManager,
SelectMenuInteraction,
Serialized,
ShardClientUtil,
ShardingManager,
Expand Down Expand Up @@ -142,6 +142,8 @@ import {
GuildForumThreadManager,
GuildTextThreadManager,
AnySelectMenuInteraction,
StringSelectMenuInteraction,
StringSelectMenuComponent,
} from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
Expand Down Expand Up @@ -362,14 +364,14 @@ client.on('messageCreate', async message => {
expectAssignable<InteractionCollector<ButtonInteraction>>(buttonCollector);

// Verify that select menus interaction are inferred.
const selectMenuCollector = message.createMessageComponentCollector({ componentType: ComponentType.SelectMenu });
expectAssignable<Promise<SelectMenuInteraction>>(
message.awaitMessageComponent({ componentType: ComponentType.SelectMenu }),
const selectMenuCollector = message.createMessageComponentCollector({ componentType: ComponentType.StringSelect });
expectAssignable<Promise<StringSelectMenuInteraction>>(
message.awaitMessageComponent({ componentType: ComponentType.StringSelect }),
);
expectAssignable<Promise<SelectMenuInteraction>>(
channel.awaitMessageComponent({ componentType: ComponentType.SelectMenu }),
expectAssignable<Promise<StringSelectMenuInteraction>>(
channel.awaitMessageComponent({ componentType: ComponentType.StringSelect }),
);
expectAssignable<InteractionCollector<SelectMenuInteraction>>(selectMenuCollector);
expectAssignable<InteractionCollector<StringSelectMenuInteraction>>(selectMenuCollector);

// Verify that message component interactions are default collected types.
const defaultCollector = message.createMessageComponentCollector();
Expand Down Expand Up @@ -406,9 +408,9 @@ client.on('messageCreate', async message => {
});

message.createMessageComponentCollector({
componentType: ComponentType.SelectMenu,
componentType: ComponentType.StringSelect,
filter: i => {
expectType<SelectMenuInteraction>(i);
expectType<StringSelectMenuInteraction>(i);
return true;
},
});
Expand All @@ -429,9 +431,9 @@ client.on('messageCreate', async message => {
});

message.awaitMessageComponent({
componentType: ComponentType.SelectMenu,
componentType: ComponentType.StringSelect,
filter: i => {
expectType<SelectMenuInteraction>(i);
expectType<StringSelectMenuInteraction>(i);
return true;
},
});
Expand Down Expand Up @@ -465,9 +467,9 @@ client.on('messageCreate', async message => {
});

channel.awaitMessageComponent({
componentType: ComponentType.SelectMenu,
componentType: ComponentType.StringSelect,
filter: i => {
expectType<SelectMenuInteraction<'cached'>>(i);
expectType<StringSelectMenuInteraction<'cached'>>(i);
return true;
},
});
Expand All @@ -492,7 +494,7 @@ client.on('messageCreate', async message => {
components: [
new SelectMenuBuilder(),
{
type: ComponentType.SelectMenu,
type: ComponentType.StringSelect,
label: 'select menu',
options: [{ label: 'test', value: 'test' }],
customId: 'test',
Expand Down Expand Up @@ -1123,7 +1125,7 @@ client.on('guildCreate', async g => {
new ButtonBuilder(),
{ type: ComponentType.Button, style: ButtonStyle.Primary, label: 'string', customId: 'foo' },
{ type: ComponentType.Button, style: ButtonStyle.Link, label: 'test', url: 'test' },
{ type: ComponentType.SelectMenu, customId: 'foo' },
{ type: ComponentType.StringSelect, customId: 'foo' },
new SelectMenuBuilder(),
// @ts-expect-error
{ type: ComponentType.TextInput, style: TextInputStyle.Paragraph, customId: 'foo', label: 'test' },
Expand All @@ -1137,7 +1139,7 @@ client.on('guildCreate', async g => {
components: [
{ type: ComponentType.Button, style: ButtonStyle.Primary, label: 'string', customId: 'foo' },
{ type: ComponentType.Button, style: ButtonStyle.Link, label: 'test', url: 'test' },
{ type: ComponentType.SelectMenu, customId: 'foo' },
{ type: ComponentType.StringSelect, customId: 'foo' },
],
});

Expand Down Expand Up @@ -1641,25 +1643,28 @@ client.on('interactionCreate', async interaction => {
}
}

if (interaction.type === InteractionType.MessageComponent && interaction.componentType === ComponentType.SelectMenu) {
expectType<SelectMenuInteraction>(interaction);
expectType<SelectMenuComponent | APISelectMenuComponent>(interaction.component);
if (
interaction.type === InteractionType.MessageComponent &&
interaction.componentType === ComponentType.StringSelect
) {
expectType<StringSelectMenuInteraction>(interaction);
expectType<StringSelectMenuComponent | APIStringSelectComponent>(interaction.component);
expectType<Message>(interaction.message);
if (interaction.inCachedGuild()) {
expectAssignable<SelectMenuInteraction>(interaction);
expectAssignable<StringSelectMenuInteraction>(interaction);
expectType<SelectMenuComponent>(interaction.component);
expectType<Message<true>>(interaction.message);
expectType<Guild>(interaction.guild);
expectType<Promise<Message<true>>>(interaction.reply({ fetchReply: true }));
} else if (interaction.inRawGuild()) {
expectAssignable<SelectMenuInteraction>(interaction);
expectType<APISelectMenuComponent>(interaction.component);
expectAssignable<StringSelectMenuInteraction>(interaction);
expectType<APIStringSelectComponent>(interaction.component);
expectType<Message<false>>(interaction.message);
expectType<null>(interaction.guild);
expectType<Promise<Message<false>>>(interaction.reply({ fetchReply: true }));
} else if (interaction.inGuild()) {
expectAssignable<SelectMenuInteraction>(interaction);
expectType<SelectMenuComponent | APISelectMenuComponent>(interaction.component);
expectAssignable<StringSelectMenuInteraction>(interaction);
expectType<SelectMenuComponent | APIStringSelectComponent>(interaction.component);
expectType<Message>(interaction.message);
expectType<Guild | null>(interaction.guild);
expectType<Promise<Message>>(interaction.reply({ fetchReply: true }));
Expand Down

0 comments on commit e6eeb88

Please sign in to comment.