mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
* 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>
88 lines
3.0 KiB
TypeScript
88 lines
3.0 KiB
TypeScript
import { expect } from 'chai'
|
|
import { describe, it } from 'mocha'
|
|
import { EmbedsBuilder } from '../src/builders.js'
|
|
|
|
describe('builders/embeds.ts', () => {
|
|
it('should create a new blank embed JSON', () => {
|
|
expect(new EmbedsBuilder().newEmbed()).to.eql([{}])
|
|
})
|
|
|
|
it('should set the author name in the embed JSON', () => {
|
|
expect(new EmbedsBuilder().setAuthor('Author')).to.eql([{ author: { name: 'Author' } }])
|
|
})
|
|
|
|
it('should set the color in the embed JSON', () => {
|
|
expect(new EmbedsBuilder().setColor('#000000')).to.eql([{ color: 0 }])
|
|
expect(new EmbedsBuilder().setColor('#21fa99')).to.eql([{ color: 2226841 }])
|
|
expect(new EmbedsBuilder().setColor('#thisisnotacolor')).to.eql([{ color: 0 }])
|
|
expect(new EmbedsBuilder().setColor(13530)).to.eql([{ color: 13530 }])
|
|
})
|
|
|
|
it('should set the description in the embed JSON', () => {
|
|
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([
|
|
{ name: 'firstname', value: 'firstvalue' },
|
|
{ name: 'secondname', value: 'secondvalue', inline: true },
|
|
]),
|
|
).to.eql([
|
|
{
|
|
fields: [
|
|
{ name: 'firstname', value: 'firstvalue' },
|
|
{ name: 'secondname', value: 'secondvalue', inline: true },
|
|
],
|
|
},
|
|
])
|
|
})
|
|
|
|
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' } }])
|
|
})
|
|
|
|
it('should set the set a random color in the embed JSON', () => {
|
|
expect(new EmbedsBuilder().setRandomColor()[0]).to.haveOwnProperty('color')
|
|
})
|
|
|
|
it('should set the timestamp in the embed JSON', () => {
|
|
const now = new Date()
|
|
|
|
expect(new EmbedsBuilder().setTimestamp(now)).to.eql([{ timestamp: now.toISOString() }])
|
|
})
|
|
|
|
it('should set the title in the embed JSON', () => {
|
|
expect(new EmbedsBuilder().setTitle('My Title')).to.eql([{ title: 'My Title' }])
|
|
})
|
|
|
|
it('should set the url in the embed JSON', () => {
|
|
expect(new EmbedsBuilder().setUrl('https://google.com')).to.eql([{ url: 'https://google.com' }])
|
|
})
|
|
})
|