11import { ComponentType , TextInputStyle , type APIModalInteractionResponseCallbackData } from 'discord-api-types/v10' ;
22import { describe , test , expect } from 'vitest' ;
3- import { ActionRowBuilder , ModalBuilder , TextInputBuilder } from '../../src/index.js' ;
3+ import { ModalBuilder , TextInputBuilder , LabelBuilder } from '../../src/index.js' ;
44
55const modal = ( ) => new ModalBuilder ( ) ;
6- const textInput = ( ) =>
7- new ActionRowBuilder ( ) . addTextInputComponent (
8- new TextInputBuilder ( ) . setCustomId ( 'text' ) . setLabel ( ':3' ) . setStyle ( TextInputStyle . Short ) ,
9- ) ;
6+
7+ const label = ( ) =>
8+ new LabelBuilder ( )
9+ . setLabel ( 'label' )
10+ . setTextInputComponent ( new TextInputBuilder ( ) . setCustomId ( 'text' ) . setStyle ( TextInputStyle . Short ) ) ;
1011
1112describe ( 'Modals' , ( ) => {
1213 test ( 'GIVEN valid fields THEN builder does not throw' , ( ) => {
13- expect ( ( ) => modal ( ) . setTitle ( 'test' ) . setCustomId ( 'foobar' ) . setActionRows ( textInput ( ) ) . toJSON ( ) ) . not . toThrowError ( ) ;
14- expect ( ( ) => modal ( ) . setTitle ( 'test' ) . setCustomId ( 'foobar' ) . addActionRows ( textInput ( ) ) . toJSON ( ) ) . not . toThrowError ( ) ;
14+ expect ( ( ) =>
15+ modal ( ) . setTitle ( 'test' ) . setCustomId ( 'foobar' ) . setLabelComponents ( label ( ) ) . toJSON ( ) ,
16+ ) . not . toThrowError ( ) ;
17+ expect ( ( ) =>
18+ modal ( ) . setTitle ( 'test' ) . setCustomId ( 'foobar' ) . setLabelComponents ( label ( ) ) . toJSON ( ) ,
19+ ) . not . toThrowError ( ) ;
1520 } ) ;
1621
1722 test ( 'GIVEN invalid fields THEN builder does throw' , ( ) => {
@@ -21,51 +26,53 @@ describe('Modals', () => {
2126 } ) ;
2227
2328 test ( 'GIVEN valid input THEN valid JSON outputs are given' , ( ) => {
24- const modalData : APIModalInteractionResponseCallbackData = {
29+ const modalData = {
2530 title : 'title' ,
2631 custom_id : 'custom id' ,
2732 components : [
2833 {
29- type : ComponentType . ActionRow ,
30- components : [
31- {
32- type : ComponentType . TextInput ,
33- label : 'label' ,
34- style : TextInputStyle . Paragraph ,
35- custom_id : 'custom id' ,
36- } ,
37- ] ,
34+ type : ComponentType . Label ,
35+ id : 33 ,
36+ label : 'label' ,
37+ description : 'description' ,
38+ component : {
39+ type : ComponentType . TextInput ,
40+ style : TextInputStyle . Paragraph ,
41+ custom_id : 'custom id' ,
42+ } ,
3843 } ,
3944 {
40- type : ComponentType . ActionRow ,
41- components : [
42- {
43- type : ComponentType . TextInput ,
44- label : 'label' ,
45- style : TextInputStyle . Paragraph ,
46- custom_id : 'custom id' ,
47- } ,
48- ] ,
45+ type : ComponentType . Label ,
46+ label : 'label' ,
47+ description : 'description' ,
48+ component : {
49+ type : ComponentType . TextInput ,
50+ style : TextInputStyle . Paragraph ,
51+ custom_id : 'custom id' ,
52+ } ,
4953 } ,
5054 ] ,
51- } ;
55+ } satisfies APIModalInteractionResponseCallbackData ;
5256
5357 expect ( new ModalBuilder ( modalData ) . toJSON ( ) ) . toEqual ( modalData ) ;
5458
5559 expect (
5660 modal ( )
5761 . setTitle ( modalData . title )
5862 . setCustomId ( 'custom id' )
59- . setActionRows (
60- new ActionRowBuilder ( ) . addTextInputComponent (
61- new TextInputBuilder ( ) . setCustomId ( 'custom id' ) . setLabel ( 'label' ) . setStyle ( TextInputStyle . Paragraph ) ,
62- ) ,
63+ . setLabelComponents (
64+ new LabelBuilder ( )
65+ . setId ( 33 )
66+ . setLabel ( 'label' )
67+ . setDescription ( 'description' )
68+ . setTextInputComponent ( new TextInputBuilder ( ) . setCustomId ( 'custom id' ) . setStyle ( TextInputStyle . Paragraph ) ) ,
69+ )
70+ . addLabelComponents (
71+ new LabelBuilder ( )
72+ . setLabel ( 'label' )
73+ . setDescription ( 'description' )
74+ . setTextInputComponent ( new TextInputBuilder ( ) . setCustomId ( 'custom id' ) . setStyle ( TextInputStyle . Paragraph ) ) ,
6375 )
64- . addActionRows ( [
65- new ActionRowBuilder ( ) . addTextInputComponent (
66- new TextInputBuilder ( ) . setCustomId ( 'custom id' ) . setLabel ( 'label' ) . setStyle ( TextInputStyle . Paragraph ) ,
67- ) ,
68- ] )
6976 . toJSON ( ) ,
7077 ) . toEqual ( modalData ) ;
7178 } ) ;
0 commit comments