workspace
This commit is contained in:
40
packages/reacord/test/action-row.test.tsx
Normal file
40
packages/reacord/test/action-row.test.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import React from "react"
|
||||
import { ReacordTester } from "../library/core/reacord-tester"
|
||||
import { ActionRow, Button, Select } from "../library/main"
|
||||
|
||||
const testing = new ReacordTester()
|
||||
|
||||
test("action row", async () => {
|
||||
await testing.assertRender(
|
||||
<>
|
||||
<Button label="outside button" onClick={() => {}} />
|
||||
<ActionRow>
|
||||
<Button label="button inside action row" onClick={() => {}} />
|
||||
</ActionRow>
|
||||
<Select />
|
||||
<Button label="last row 1" onClick={() => {}} />
|
||||
<Button label="last row 2" onClick={() => {}} />
|
||||
</>,
|
||||
[
|
||||
{
|
||||
content: "",
|
||||
embeds: [],
|
||||
actionRows: [
|
||||
[{ type: "button", style: "secondary", label: "outside button" }],
|
||||
[
|
||||
{
|
||||
type: "button",
|
||||
style: "secondary",
|
||||
label: "button inside action row",
|
||||
},
|
||||
],
|
||||
[{ type: "select", options: [], values: [] }],
|
||||
[
|
||||
{ type: "button", style: "secondary", label: "last row 1" },
|
||||
{ type: "button", style: "secondary", label: "last row 2" },
|
||||
],
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
})
|
||||
2
packages/reacord/test/channel-message-renderer.tsx
Normal file
2
packages/reacord/test/channel-message-renderer.tsx
Normal file
@@ -0,0 +1,2 @@
|
||||
test.todo("channel message renderer")
|
||||
export {}
|
||||
2
packages/reacord/test/discord-js.test.tsx
Normal file
2
packages/reacord/test/discord-js.test.tsx
Normal file
@@ -0,0 +1,2 @@
|
||||
test.todo("discord js integration")
|
||||
export {}
|
||||
274
packages/reacord/test/embed.test.tsx
Normal file
274
packages/reacord/test/embed.test.tsx
Normal file
@@ -0,0 +1,274 @@
|
||||
import React from "react"
|
||||
import { ReacordTester } from "../library/core/reacord-tester"
|
||||
import {
|
||||
Embed,
|
||||
EmbedAuthor,
|
||||
EmbedField,
|
||||
EmbedFooter,
|
||||
EmbedImage,
|
||||
EmbedThumbnail,
|
||||
EmbedTitle,
|
||||
} from "../library/main"
|
||||
|
||||
const testing = new ReacordTester()
|
||||
|
||||
test("kitchen sink", async () => {
|
||||
const now = new Date()
|
||||
|
||||
await testing.assertRender(
|
||||
<>
|
||||
<Embed color={0xfe_ee_ef}>
|
||||
<EmbedAuthor name="author" iconUrl="https://example.com/author.png" />
|
||||
<EmbedTitle>title text</EmbedTitle>
|
||||
description text
|
||||
<EmbedThumbnail url="https://example.com/thumbnail.png" />
|
||||
<EmbedImage url="https://example.com/image.png" />
|
||||
<EmbedField name="field name" value="field value" inline />
|
||||
<EmbedField name="block field" value="block field value" />
|
||||
<EmbedFooter
|
||||
text="footer text"
|
||||
iconUrl="https://example.com/footer.png"
|
||||
timestamp={now}
|
||||
/>
|
||||
</Embed>
|
||||
</>,
|
||||
[
|
||||
{
|
||||
actionRows: [],
|
||||
content: "",
|
||||
embeds: [
|
||||
{
|
||||
description: "description text",
|
||||
author: {
|
||||
icon_url: "https://example.com/author.png",
|
||||
name: "author",
|
||||
},
|
||||
color: 0xfe_ee_ef,
|
||||
fields: [
|
||||
{
|
||||
inline: true,
|
||||
name: "field name",
|
||||
value: "field value",
|
||||
},
|
||||
{
|
||||
name: "block field",
|
||||
value: "block field value",
|
||||
},
|
||||
],
|
||||
footer: {
|
||||
icon_url: "https://example.com/footer.png",
|
||||
text: "footer text",
|
||||
},
|
||||
image: {
|
||||
url: "https://example.com/image.png",
|
||||
},
|
||||
thumbnail: {
|
||||
url: "https://example.com/thumbnail.png",
|
||||
},
|
||||
timestamp: now.toISOString(),
|
||||
title: "title text",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
})
|
||||
|
||||
test("author variants", async () => {
|
||||
await testing.assertRender(
|
||||
<>
|
||||
<Embed>
|
||||
<EmbedAuthor iconUrl="https://example.com/author.png">
|
||||
author name
|
||||
</EmbedAuthor>
|
||||
</Embed>
|
||||
<Embed>
|
||||
<EmbedAuthor iconUrl="https://example.com/author.png" />
|
||||
</Embed>
|
||||
</>,
|
||||
[
|
||||
{
|
||||
content: "",
|
||||
actionRows: [],
|
||||
embeds: [
|
||||
{
|
||||
author: {
|
||||
icon_url: "https://example.com/author.png",
|
||||
name: "author name",
|
||||
},
|
||||
},
|
||||
{
|
||||
author: {
|
||||
icon_url: "https://example.com/author.png",
|
||||
name: "",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
})
|
||||
|
||||
test("field variants", async () => {
|
||||
await testing.assertRender(
|
||||
<>
|
||||
<Embed>
|
||||
<EmbedField name="field name" value="field value" />
|
||||
<EmbedField name="field name" value="field value" inline />
|
||||
<EmbedField name="field name" inline>
|
||||
field value
|
||||
</EmbedField>
|
||||
<EmbedField name="field name" />
|
||||
</Embed>
|
||||
</>,
|
||||
[
|
||||
{
|
||||
content: "",
|
||||
actionRows: [],
|
||||
embeds: [
|
||||
{
|
||||
fields: [
|
||||
{
|
||||
name: "field name",
|
||||
value: "field value",
|
||||
},
|
||||
{
|
||||
inline: true,
|
||||
name: "field name",
|
||||
value: "field value",
|
||||
},
|
||||
{
|
||||
inline: true,
|
||||
name: "field name",
|
||||
value: "field value",
|
||||
},
|
||||
{
|
||||
name: "field name",
|
||||
value: "",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
})
|
||||
|
||||
test("footer variants", async () => {
|
||||
const now = new Date()
|
||||
|
||||
await testing.assertRender(
|
||||
<>
|
||||
<Embed>
|
||||
<EmbedFooter text="footer text" />
|
||||
</Embed>
|
||||
<Embed>
|
||||
<EmbedFooter
|
||||
text="footer text"
|
||||
iconUrl="https://example.com/footer.png"
|
||||
/>
|
||||
</Embed>
|
||||
<Embed>
|
||||
<EmbedFooter timestamp={now}>footer text</EmbedFooter>
|
||||
</Embed>
|
||||
<Embed>
|
||||
<EmbedFooter iconUrl="https://example.com/footer.png" timestamp={now} />
|
||||
</Embed>
|
||||
</>,
|
||||
[
|
||||
{
|
||||
content: "",
|
||||
actionRows: [],
|
||||
embeds: [
|
||||
{
|
||||
footer: {
|
||||
text: "footer text",
|
||||
},
|
||||
},
|
||||
{
|
||||
footer: {
|
||||
icon_url: "https://example.com/footer.png",
|
||||
text: "footer text",
|
||||
},
|
||||
},
|
||||
{
|
||||
footer: {
|
||||
text: "footer text",
|
||||
},
|
||||
timestamp: now.toISOString(),
|
||||
},
|
||||
{
|
||||
footer: {
|
||||
icon_url: "https://example.com/footer.png",
|
||||
text: "",
|
||||
},
|
||||
timestamp: now.toISOString(),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
})
|
||||
|
||||
test("embed props", async () => {
|
||||
const now = new Date()
|
||||
|
||||
await testing.assertRender(
|
||||
<Embed
|
||||
title="title text"
|
||||
description="description text"
|
||||
url="https://example.com/"
|
||||
color={0xfe_ee_ef}
|
||||
timestamp={now}
|
||||
author={{
|
||||
name: "author name",
|
||||
url: "https://example.com/author",
|
||||
iconUrl: "https://example.com/author.png",
|
||||
}}
|
||||
thumbnail={{
|
||||
url: "https://example.com/thumbnail.png",
|
||||
}}
|
||||
image={{
|
||||
url: "https://example.com/image.png",
|
||||
}}
|
||||
footer={{
|
||||
text: "footer text",
|
||||
iconUrl: "https://example.com/footer.png",
|
||||
}}
|
||||
fields={[
|
||||
{ name: "field name", value: "field value", inline: true },
|
||||
{ name: "block field", value: "block field value" },
|
||||
]}
|
||||
/>,
|
||||
[
|
||||
{
|
||||
content: "",
|
||||
actionRows: [],
|
||||
embeds: [
|
||||
{
|
||||
title: "title text",
|
||||
description: "description text",
|
||||
url: "https://example.com/",
|
||||
color: 0xfe_ee_ef,
|
||||
timestamp: now.toISOString(),
|
||||
author: {
|
||||
name: "author name",
|
||||
url: "https://example.com/author",
|
||||
icon_url: "https://example.com/author.png",
|
||||
},
|
||||
thumbnail: { url: "https://example.com/thumbnail.png" },
|
||||
image: { url: "https://example.com/image.png" },
|
||||
footer: {
|
||||
text: "footer text",
|
||||
icon_url: "https://example.com/footer.png",
|
||||
},
|
||||
fields: [
|
||||
{ name: "field name", value: "field value", inline: true },
|
||||
{ name: "block field", value: "block field value" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
})
|
||||
2
packages/reacord/test/ephemeral-reply.test.ts
Normal file
2
packages/reacord/test/ephemeral-reply.test.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
test.todo("ephemeral reply")
|
||||
export {}
|
||||
3
packages/reacord/test/event-callbacks.test.tsx
Normal file
3
packages/reacord/test/event-callbacks.test.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
test.todo("button onClick")
|
||||
test.todo("select onChange")
|
||||
export {}
|
||||
41
packages/reacord/test/link.test.tsx
Normal file
41
packages/reacord/test/link.test.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import React from "react"
|
||||
import { ReacordTester } from "../library/core/reacord-tester"
|
||||
import { Link } from "../library/main"
|
||||
|
||||
const tester = new ReacordTester()
|
||||
|
||||
test("link", async () => {
|
||||
await tester.assertRender(
|
||||
<>
|
||||
<Link url="https://example.com/">link text</Link>
|
||||
<Link label="link text" url="https://example.com/" />
|
||||
<Link label="link text" url="https://example.com/" disabled />
|
||||
</>,
|
||||
[
|
||||
{
|
||||
content: "",
|
||||
embeds: [],
|
||||
actionRows: [
|
||||
[
|
||||
{
|
||||
type: "link",
|
||||
url: "https://example.com/",
|
||||
label: "link text",
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
url: "https://example.com/",
|
||||
label: "link text",
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
url: "https://example.com/",
|
||||
label: "link text",
|
||||
disabled: true,
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
})
|
||||
309
packages/reacord/test/reacord.test.tsx
Normal file
309
packages/reacord/test/reacord.test.tsx
Normal file
@@ -0,0 +1,309 @@
|
||||
import * as React from "react"
|
||||
import {
|
||||
Button,
|
||||
Embed,
|
||||
EmbedField,
|
||||
EmbedTitle,
|
||||
ReacordTester,
|
||||
} from "../library/main"
|
||||
|
||||
test("rendering behavior", async () => {
|
||||
const tester = new ReacordTester()
|
||||
|
||||
const reply = tester.reply()
|
||||
reply.render(<KitchenSinkCounter onDeactivate={() => reply.deactivate()} />)
|
||||
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "count: 0",
|
||||
embeds: [],
|
||||
actionRows: [
|
||||
[
|
||||
{
|
||||
type: "button",
|
||||
style: "primary",
|
||||
label: "clicc",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "secondary",
|
||||
label: "show embed",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "danger",
|
||||
label: "deactivate",
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
tester.findButtonByLabel("show embed").click()
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "count: 0",
|
||||
embeds: [{ title: "the counter" }],
|
||||
actionRows: [
|
||||
[
|
||||
{
|
||||
type: "button",
|
||||
style: "secondary",
|
||||
label: "hide embed",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "primary",
|
||||
label: "clicc",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "danger",
|
||||
label: "deactivate",
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
tester.findButtonByLabel("clicc").click()
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "count: 1",
|
||||
embeds: [
|
||||
{
|
||||
title: "the counter",
|
||||
fields: [{ name: "is it even?", value: "no" }],
|
||||
},
|
||||
],
|
||||
actionRows: [
|
||||
[
|
||||
{
|
||||
type: "button",
|
||||
style: "secondary",
|
||||
label: "hide embed",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "primary",
|
||||
label: "clicc",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "danger",
|
||||
label: "deactivate",
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
tester.findButtonByLabel("clicc").click()
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "count: 2",
|
||||
embeds: [
|
||||
{
|
||||
title: "the counter",
|
||||
fields: [{ name: "is it even?", value: "yes" }],
|
||||
},
|
||||
],
|
||||
actionRows: [
|
||||
[
|
||||
{
|
||||
type: "button",
|
||||
style: "secondary",
|
||||
label: "hide embed",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "primary",
|
||||
label: "clicc",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "danger",
|
||||
label: "deactivate",
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
tester.findButtonByLabel("hide embed").click()
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "count: 2",
|
||||
embeds: [],
|
||||
actionRows: [
|
||||
[
|
||||
{
|
||||
type: "button",
|
||||
style: "primary",
|
||||
label: "clicc",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "secondary",
|
||||
label: "show embed",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "danger",
|
||||
label: "deactivate",
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
tester.findButtonByLabel("clicc").click()
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "count: 3",
|
||||
embeds: [],
|
||||
actionRows: [
|
||||
[
|
||||
{
|
||||
type: "button",
|
||||
style: "primary",
|
||||
label: "clicc",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "secondary",
|
||||
label: "show embed",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "danger",
|
||||
label: "deactivate",
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
tester.findButtonByLabel("deactivate").click()
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "count: 3",
|
||||
embeds: [],
|
||||
actionRows: [
|
||||
[
|
||||
{
|
||||
type: "button",
|
||||
style: "primary",
|
||||
label: "clicc",
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "secondary",
|
||||
label: "show embed",
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "danger",
|
||||
label: "deactivate",
|
||||
disabled: true,
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
tester.findButtonByLabel("clicc").click()
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "count: 3",
|
||||
embeds: [],
|
||||
actionRows: [
|
||||
[
|
||||
{
|
||||
type: "button",
|
||||
style: "primary",
|
||||
label: "clicc",
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "secondary",
|
||||
label: "show embed",
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
style: "danger",
|
||||
label: "deactivate",
|
||||
disabled: true,
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
test("delete", async () => {
|
||||
const tester = new ReacordTester()
|
||||
|
||||
const reply = tester.reply()
|
||||
reply.render(
|
||||
<>
|
||||
some text
|
||||
<Embed>some embed</Embed>
|
||||
<Button label="some button" onClick={() => {}} />
|
||||
</>,
|
||||
)
|
||||
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "some text",
|
||||
embeds: [{ description: "some embed" }],
|
||||
actionRows: [
|
||||
[{ type: "button", style: "secondary", label: "some button" }],
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
reply.destroy()
|
||||
await tester.assertMessages([])
|
||||
})
|
||||
|
||||
// test multiple instances that can be updated independently,
|
||||
// + old instances getting deactivated once the limit is reached
|
||||
test.todo("multiple instances")
|
||||
|
||||
function KitchenSinkCounter(props: { onDeactivate: () => void }) {
|
||||
const [count, setCount] = React.useState(0)
|
||||
const [embedVisible, setEmbedVisible] = React.useState(false)
|
||||
|
||||
return (
|
||||
<>
|
||||
count: {count}
|
||||
{embedVisible && (
|
||||
<Embed>
|
||||
<EmbedTitle>the counter</EmbedTitle>
|
||||
{count > 0 && (
|
||||
<EmbedField name="is it even?">
|
||||
{count % 2 === 0 ? "yes" : "no"}
|
||||
</EmbedField>
|
||||
)}
|
||||
</Embed>
|
||||
)}
|
||||
{embedVisible && (
|
||||
<Button label="hide embed" onClick={() => setEmbedVisible(false)} />
|
||||
)}
|
||||
<Button
|
||||
style="primary"
|
||||
label="clicc"
|
||||
onClick={() => setCount(count + 1)}
|
||||
/>
|
||||
{!embedVisible && (
|
||||
<Button label="show embed" onClick={() => setEmbedVisible(true)} />
|
||||
)}
|
||||
<Button style="danger" label="deactivate" onClick={props.onDeactivate} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
6
packages/reacord/test/renderer.test.ts
Normal file
6
packages/reacord/test/renderer.test.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
// test that the interaction update is _eventually_ deferred if there's no component update,
|
||||
// and that update isn't called after the fact
|
||||
// ...somehow
|
||||
test.todo("defer update timeout")
|
||||
|
||||
export {}
|
||||
159
packages/reacord/test/select.test.tsx
Normal file
159
packages/reacord/test/select.test.tsx
Normal file
@@ -0,0 +1,159 @@
|
||||
import { jest } from "@jest/globals"
|
||||
import React, { useState } from "react"
|
||||
import { Button, Option, ReacordTester, Select } from "../library/main"
|
||||
|
||||
test("single select", async () => {
|
||||
const tester = new ReacordTester()
|
||||
const onSelect = jest.fn()
|
||||
|
||||
function TestSelect() {
|
||||
const [value, setValue] = useState<string>()
|
||||
const [disabled, setDisabled] = useState(false)
|
||||
return (
|
||||
<>
|
||||
<Select
|
||||
placeholder="choose one"
|
||||
value={value}
|
||||
onChange={onSelect}
|
||||
onChangeValue={setValue}
|
||||
disabled={disabled}
|
||||
>
|
||||
<Option value="1" />
|
||||
<Option value="2" label="two" />
|
||||
<Option value="3">three</Option>
|
||||
</Select>
|
||||
<Button label="disable" onClick={() => setDisabled(true)} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
async function assertSelect(values: string[], disabled = false) {
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "",
|
||||
embeds: [],
|
||||
actionRows: [
|
||||
[
|
||||
{
|
||||
type: "select",
|
||||
placeholder: "choose one",
|
||||
values,
|
||||
disabled,
|
||||
options: [
|
||||
{ label: "1", value: "1" },
|
||||
{ label: "two", value: "2" },
|
||||
{ label: "three", value: "3" },
|
||||
],
|
||||
},
|
||||
],
|
||||
[{ type: "button", style: "secondary", label: "disable" }],
|
||||
],
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
const reply = tester.reply()
|
||||
|
||||
reply.render(<TestSelect />)
|
||||
await assertSelect([])
|
||||
expect(onSelect).toHaveBeenCalledTimes(0)
|
||||
|
||||
tester.findSelectByPlaceholder("choose one").select("2")
|
||||
await assertSelect(["2"])
|
||||
expect(onSelect).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ values: ["2"] }),
|
||||
)
|
||||
|
||||
tester.findButtonByLabel("disable").click()
|
||||
await assertSelect(["2"], true)
|
||||
|
||||
tester.findSelectByPlaceholder("choose one").select("1")
|
||||
await assertSelect(["2"], true)
|
||||
expect(onSelect).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test("multiple select", async () => {
|
||||
const tester = new ReacordTester()
|
||||
const onSelect = jest.fn()
|
||||
|
||||
function TestSelect() {
|
||||
const [values, setValues] = useState<string[]>([])
|
||||
return (
|
||||
<Select
|
||||
placeholder="select"
|
||||
multiple
|
||||
values={values}
|
||||
onChange={onSelect}
|
||||
onChangeMultiple={setValues}
|
||||
>
|
||||
<Option value="1">one</Option>
|
||||
<Option value="2">two</Option>
|
||||
<Option value="3">three</Option>
|
||||
</Select>
|
||||
)
|
||||
}
|
||||
|
||||
async function assertSelect(values: string[]) {
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "",
|
||||
embeds: [],
|
||||
actionRows: [
|
||||
[
|
||||
{
|
||||
type: "select",
|
||||
placeholder: "select",
|
||||
values,
|
||||
minValues: 0,
|
||||
maxValues: 25,
|
||||
options: [
|
||||
{ label: "one", value: "1" },
|
||||
{ label: "two", value: "2" },
|
||||
{ label: "three", value: "3" },
|
||||
],
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
const reply = tester.reply()
|
||||
|
||||
reply.render(<TestSelect />)
|
||||
await assertSelect([])
|
||||
expect(onSelect).toHaveBeenCalledTimes(0)
|
||||
|
||||
tester.findSelectByPlaceholder("select").select("1", "3")
|
||||
await assertSelect(expect.arrayContaining(["1", "3"]))
|
||||
expect(onSelect).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ values: expect.arrayContaining(["1", "3"]) }),
|
||||
)
|
||||
|
||||
tester.findSelectByPlaceholder("select").select("2")
|
||||
await assertSelect(expect.arrayContaining(["2"]))
|
||||
expect(onSelect).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ values: expect.arrayContaining(["2"]) }),
|
||||
)
|
||||
|
||||
tester.findSelectByPlaceholder("select").select()
|
||||
await assertSelect([])
|
||||
expect(onSelect).toHaveBeenCalledWith(expect.objectContaining({ values: [] }))
|
||||
})
|
||||
|
||||
test("optional onSelect + unknown value", async () => {
|
||||
const tester = new ReacordTester()
|
||||
tester.reply().render(<Select placeholder="select" />)
|
||||
tester.findSelectByPlaceholder("select").select("something")
|
||||
await tester.assertMessages([
|
||||
{
|
||||
content: "",
|
||||
embeds: [],
|
||||
actionRows: [
|
||||
[{ type: "select", placeholder: "select", options: [], values: [] }],
|
||||
],
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
test.todo("select minValues and maxValues")
|
||||
Reference in New Issue
Block a user