mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
feat(utils): add EmbedsBuilder.addFields() (#4077)
* feat(embed-builder): add addFields function * feat(embed-builder): add tests for addField and addFields function * Update packages/utils/src/builders/embeds.ts Co-authored-by: Fleny <Fleny113@outlook.com> * feat(embed-builder): add undefined check to addFields * fix: make inline field optional in push * revert: EmbedBuilder tsdoc rename * Update packages/utils/src/builders/embeds.ts Co-authored-by: Fleny <Fleny113@outlook.com> * fix(embed-builder): expect inline to be undefined * revert: outdated changes * fix(embed-builder): fix embed unit test * feat(embed-builder): add stickz jsdoc suggestions --------- Co-authored-by: Fleny <Fleny113@outlook.com>
This commit is contained in:
@@ -22,7 +22,7 @@ export class EmbedsBuilder extends Array<DiscordEmbed> {
|
||||
#currentEmbedIndex: number = 0
|
||||
|
||||
/**
|
||||
* Adds a new field to the embed fields array.
|
||||
* Adds a new field to the current embed.
|
||||
*
|
||||
* @param {string} name - Field name
|
||||
* @param {string} value - Field value
|
||||
@@ -43,6 +43,22 @@ export class EmbedsBuilder extends Array<DiscordEmbed> {
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds multiple new fields to the current embed.
|
||||
*
|
||||
* @param {DiscordEmbedField[]} fields - The fields to add
|
||||
* @returns {EmbedsBuilder}
|
||||
*/
|
||||
addFields(fields: DiscordEmbedField[]): this {
|
||||
if (this.#currentEmbed.fields === undefined) {
|
||||
this.#currentEmbed.fields = []
|
||||
}
|
||||
|
||||
this.#currentEmbed.fields.push(...fields)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a blank embed.
|
||||
*
|
||||
|
||||
@@ -22,6 +22,14 @@ describe('builders/embeds.ts', () => {
|
||||
expect(new EmbedsBuilder().setDescription('My Description')).to.eql([{ description: 'My Description' }])
|
||||
})
|
||||
|
||||
it('should add a field in the embed JSON', () => {
|
||||
expect(new EmbedsBuilder().addField('firstname', 'firstvalue')).to.eql([
|
||||
{
|
||||
fields: [{ name: 'firstname', value: 'firstvalue', inline: undefined }],
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('should set the fields in the embed JSON', () => {
|
||||
expect(
|
||||
new EmbedsBuilder().setFields([
|
||||
@@ -38,6 +46,23 @@ describe('builders/embeds.ts', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('should add the fields in the embed JSON', () => {
|
||||
expect(
|
||||
new EmbedsBuilder().addField('firstname', 'firstvalue').addFields([
|
||||
{ name: 'secondname', value: 'secondvalue' },
|
||||
{ name: 'thirdname', value: 'thirdvalue', inline: true },
|
||||
]),
|
||||
).to.eql([
|
||||
{
|
||||
fields: [
|
||||
{ name: 'firstname', value: 'firstvalue', inline: undefined },
|
||||
{ name: 'secondname', value: 'secondvalue' },
|
||||
{ name: 'thirdname', value: 'thirdvalue', inline: true },
|
||||
],
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('should set the footer text in the embed JSON', () => {
|
||||
expect(new EmbedsBuilder().setFooter('footer text')).to.eql([{ footer: { text: 'footer text' } }])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user