clean up garbage
This commit is contained in:
@@ -1,42 +1,40 @@
|
|||||||
import React from "react"
|
|
||||||
import { test } from "vitest"
|
import { test } from "vitest"
|
||||||
import { Link } from "../library/main"
|
// import { ReacordTester } from "./test-adapter"
|
||||||
import { ReacordTester } from "./test-adapter"
|
|
||||||
|
|
||||||
const tester = new ReacordTester()
|
// const tester = new ReacordTester()
|
||||||
|
|
||||||
test("link", async () => {
|
test.skip("link", async () => {
|
||||||
await tester.assertRender(
|
// await tester.assertRender(
|
||||||
<>
|
// <>
|
||||||
<Link url="https://example.com/">link text</Link>
|
// <Link url="https://example.com/">link text</Link>
|
||||||
<Link label="link text" url="https://example.com/" />
|
// <Link label="link text" url="https://example.com/" />
|
||||||
<Link label="link text" url="https://example.com/" disabled />
|
// <Link label="link text" url="https://example.com/" disabled />
|
||||||
</>,
|
// </>,
|
||||||
[
|
// [
|
||||||
{
|
// {
|
||||||
content: "",
|
// content: "",
|
||||||
embeds: [],
|
// embeds: [],
|
||||||
actionRows: [
|
// actionRows: [
|
||||||
[
|
// [
|
||||||
{
|
// {
|
||||||
type: "link",
|
// type: "link",
|
||||||
url: "https://example.com/",
|
// url: "https://example.com/",
|
||||||
label: "link text",
|
// label: "link text",
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
type: "link",
|
// type: "link",
|
||||||
url: "https://example.com/",
|
// url: "https://example.com/",
|
||||||
label: "link text",
|
// label: "link text",
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
type: "link",
|
// type: "link",
|
||||||
url: "https://example.com/",
|
// url: "https://example.com/",
|
||||||
label: "link text",
|
// label: "link text",
|
||||||
disabled: true,
|
// disabled: true,
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
)
|
// )
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,270 +1,257 @@
|
|||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import { test } from "vitest"
|
import { test } from "vitest"
|
||||||
import { Button, Embed, EmbedField, EmbedTitle } from "../library/main"
|
import { Button, Embed, EmbedField, EmbedTitle } from "../library/main"
|
||||||
import { ReacordTester } from "./test-adapter"
|
|
||||||
|
|
||||||
test("rendering behavior", async () => {
|
test.skip("rendering behavior", async () => {
|
||||||
const tester = new ReacordTester()
|
// const tester = new ReacordTester()
|
||||||
|
// const reply = tester.reply()
|
||||||
const reply = tester.reply()
|
// reply.render(<KitchenSinkCounter onDeactivate={() => reply.deactivate()} />)
|
||||||
reply.render(<KitchenSinkCounter onDeactivate={() => reply.deactivate()} />)
|
// await tester.assertMessages([
|
||||||
|
// {
|
||||||
await tester.assertMessages([
|
// content: "count: 0",
|
||||||
{
|
// embeds: [],
|
||||||
content: "count: 0",
|
// actionRows: [
|
||||||
embeds: [],
|
// [
|
||||||
actionRows: [
|
// {
|
||||||
[
|
// type: "button",
|
||||||
{
|
// style: "primary",
|
||||||
type: "button",
|
// label: "clicc",
|
||||||
style: "primary",
|
// },
|
||||||
label: "clicc",
|
// {
|
||||||
},
|
// type: "button",
|
||||||
{
|
// style: "secondary",
|
||||||
type: "button",
|
// label: "show embed",
|
||||||
style: "secondary",
|
// },
|
||||||
label: "show embed",
|
// {
|
||||||
},
|
// type: "button",
|
||||||
{
|
// style: "danger",
|
||||||
type: "button",
|
// label: "deactivate",
|
||||||
style: "danger",
|
// },
|
||||||
label: "deactivate",
|
// ],
|
||||||
},
|
// ],
|
||||||
],
|
// },
|
||||||
],
|
// ])
|
||||||
},
|
// await tester.findButtonByLabel("show embed").click()
|
||||||
])
|
// await tester.assertMessages([
|
||||||
|
// {
|
||||||
await tester.findButtonByLabel("show embed").click()
|
// content: "count: 0",
|
||||||
await tester.assertMessages([
|
// embeds: [{ title: "the counter" }],
|
||||||
{
|
// actionRows: [
|
||||||
content: "count: 0",
|
// [
|
||||||
embeds: [{ title: "the counter" }],
|
// {
|
||||||
actionRows: [
|
// type: "button",
|
||||||
[
|
// style: "secondary",
|
||||||
{
|
// label: "hide embed",
|
||||||
type: "button",
|
// },
|
||||||
style: "secondary",
|
// {
|
||||||
label: "hide embed",
|
// type: "button",
|
||||||
},
|
// style: "primary",
|
||||||
{
|
// label: "clicc",
|
||||||
type: "button",
|
// },
|
||||||
style: "primary",
|
// {
|
||||||
label: "clicc",
|
// type: "button",
|
||||||
},
|
// style: "danger",
|
||||||
{
|
// label: "deactivate",
|
||||||
type: "button",
|
// },
|
||||||
style: "danger",
|
// ],
|
||||||
label: "deactivate",
|
// ],
|
||||||
},
|
// },
|
||||||
],
|
// ])
|
||||||
],
|
// await tester.findButtonByLabel("clicc").click()
|
||||||
},
|
// await tester.assertMessages([
|
||||||
])
|
// {
|
||||||
|
// content: "count: 1",
|
||||||
await tester.findButtonByLabel("clicc").click()
|
// embeds: [
|
||||||
await tester.assertMessages([
|
// {
|
||||||
{
|
// title: "the counter",
|
||||||
content: "count: 1",
|
// fields: [{ name: "is it even?", value: "no" }],
|
||||||
embeds: [
|
// },
|
||||||
{
|
// ],
|
||||||
title: "the counter",
|
// actionRows: [
|
||||||
fields: [{ name: "is it even?", value: "no" }],
|
// [
|
||||||
},
|
// {
|
||||||
],
|
// type: "button",
|
||||||
actionRows: [
|
// style: "secondary",
|
||||||
[
|
// label: "hide embed",
|
||||||
{
|
// },
|
||||||
type: "button",
|
// {
|
||||||
style: "secondary",
|
// type: "button",
|
||||||
label: "hide embed",
|
// style: "primary",
|
||||||
},
|
// label: "clicc",
|
||||||
{
|
// },
|
||||||
type: "button",
|
// {
|
||||||
style: "primary",
|
// type: "button",
|
||||||
label: "clicc",
|
// style: "danger",
|
||||||
},
|
// label: "deactivate",
|
||||||
{
|
// },
|
||||||
type: "button",
|
// ],
|
||||||
style: "danger",
|
// ],
|
||||||
label: "deactivate",
|
// },
|
||||||
},
|
// ])
|
||||||
],
|
// await tester.findButtonByLabel("clicc").click()
|
||||||
],
|
// await tester.assertMessages([
|
||||||
},
|
// {
|
||||||
])
|
// content: "count: 2",
|
||||||
|
// embeds: [
|
||||||
await tester.findButtonByLabel("clicc").click()
|
// {
|
||||||
await tester.assertMessages([
|
// title: "the counter",
|
||||||
{
|
// fields: [{ name: "is it even?", value: "yes" }],
|
||||||
content: "count: 2",
|
// },
|
||||||
embeds: [
|
// ],
|
||||||
{
|
// actionRows: [
|
||||||
title: "the counter",
|
// [
|
||||||
fields: [{ name: "is it even?", value: "yes" }],
|
// {
|
||||||
},
|
// type: "button",
|
||||||
],
|
// style: "secondary",
|
||||||
actionRows: [
|
// label: "hide embed",
|
||||||
[
|
// },
|
||||||
{
|
// {
|
||||||
type: "button",
|
// type: "button",
|
||||||
style: "secondary",
|
// style: "primary",
|
||||||
label: "hide embed",
|
// label: "clicc",
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
type: "button",
|
// type: "button",
|
||||||
style: "primary",
|
// style: "danger",
|
||||||
label: "clicc",
|
// label: "deactivate",
|
||||||
},
|
// },
|
||||||
{
|
// ],
|
||||||
type: "button",
|
// ],
|
||||||
style: "danger",
|
// },
|
||||||
label: "deactivate",
|
// ])
|
||||||
},
|
// await tester.findButtonByLabel("hide embed").click()
|
||||||
],
|
// await tester.assertMessages([
|
||||||
],
|
// {
|
||||||
},
|
// content: "count: 2",
|
||||||
])
|
// embeds: [],
|
||||||
|
// actionRows: [
|
||||||
await tester.findButtonByLabel("hide embed").click()
|
// [
|
||||||
await tester.assertMessages([
|
// {
|
||||||
{
|
// type: "button",
|
||||||
content: "count: 2",
|
// style: "primary",
|
||||||
embeds: [],
|
// label: "clicc",
|
||||||
actionRows: [
|
// },
|
||||||
[
|
// {
|
||||||
{
|
// type: "button",
|
||||||
type: "button",
|
// style: "secondary",
|
||||||
style: "primary",
|
// label: "show embed",
|
||||||
label: "clicc",
|
// },
|
||||||
},
|
// {
|
||||||
{
|
// type: "button",
|
||||||
type: "button",
|
// style: "danger",
|
||||||
style: "secondary",
|
// label: "deactivate",
|
||||||
label: "show embed",
|
// },
|
||||||
},
|
// ],
|
||||||
{
|
// ],
|
||||||
type: "button",
|
// },
|
||||||
style: "danger",
|
// ])
|
||||||
label: "deactivate",
|
// await tester.findButtonByLabel("clicc").click()
|
||||||
},
|
// await tester.assertMessages([
|
||||||
],
|
// {
|
||||||
],
|
// content: "count: 3",
|
||||||
},
|
// embeds: [],
|
||||||
])
|
// actionRows: [
|
||||||
|
// [
|
||||||
await tester.findButtonByLabel("clicc").click()
|
// {
|
||||||
await tester.assertMessages([
|
// type: "button",
|
||||||
{
|
// style: "primary",
|
||||||
content: "count: 3",
|
// label: "clicc",
|
||||||
embeds: [],
|
// },
|
||||||
actionRows: [
|
// {
|
||||||
[
|
// type: "button",
|
||||||
{
|
// style: "secondary",
|
||||||
type: "button",
|
// label: "show embed",
|
||||||
style: "primary",
|
// },
|
||||||
label: "clicc",
|
// {
|
||||||
},
|
// type: "button",
|
||||||
{
|
// style: "danger",
|
||||||
type: "button",
|
// label: "deactivate",
|
||||||
style: "secondary",
|
// },
|
||||||
label: "show embed",
|
// ],
|
||||||
},
|
// ],
|
||||||
{
|
// },
|
||||||
type: "button",
|
// ])
|
||||||
style: "danger",
|
// await tester.findButtonByLabel("deactivate").click()
|
||||||
label: "deactivate",
|
// await tester.assertMessages([
|
||||||
},
|
// {
|
||||||
],
|
// content: "count: 3",
|
||||||
],
|
// embeds: [],
|
||||||
},
|
// actionRows: [
|
||||||
])
|
// [
|
||||||
|
// {
|
||||||
await tester.findButtonByLabel("deactivate").click()
|
// type: "button",
|
||||||
await tester.assertMessages([
|
// style: "primary",
|
||||||
{
|
// label: "clicc",
|
||||||
content: "count: 3",
|
// disabled: true,
|
||||||
embeds: [],
|
// },
|
||||||
actionRows: [
|
// {
|
||||||
[
|
// type: "button",
|
||||||
{
|
// style: "secondary",
|
||||||
type: "button",
|
// label: "show embed",
|
||||||
style: "primary",
|
// disabled: true,
|
||||||
label: "clicc",
|
// },
|
||||||
disabled: true,
|
// {
|
||||||
},
|
// type: "button",
|
||||||
{
|
// style: "danger",
|
||||||
type: "button",
|
// label: "deactivate",
|
||||||
style: "secondary",
|
// disabled: true,
|
||||||
label: "show embed",
|
// },
|
||||||
disabled: true,
|
// ],
|
||||||
},
|
// ],
|
||||||
{
|
// },
|
||||||
type: "button",
|
// ])
|
||||||
style: "danger",
|
// await tester.findButtonByLabel("clicc").click()
|
||||||
label: "deactivate",
|
// await tester.assertMessages([
|
||||||
disabled: true,
|
// {
|
||||||
},
|
// content: "count: 3",
|
||||||
],
|
// embeds: [],
|
||||||
],
|
// actionRows: [
|
||||||
},
|
// [
|
||||||
])
|
// {
|
||||||
|
// type: "button",
|
||||||
await tester.findButtonByLabel("clicc").click()
|
// style: "primary",
|
||||||
await tester.assertMessages([
|
// label: "clicc",
|
||||||
{
|
// disabled: true,
|
||||||
content: "count: 3",
|
// },
|
||||||
embeds: [],
|
// {
|
||||||
actionRows: [
|
// type: "button",
|
||||||
[
|
// style: "secondary",
|
||||||
{
|
// label: "show embed",
|
||||||
type: "button",
|
// disabled: true,
|
||||||
style: "primary",
|
// },
|
||||||
label: "clicc",
|
// {
|
||||||
disabled: true,
|
// type: "button",
|
||||||
},
|
// style: "danger",
|
||||||
{
|
// label: "deactivate",
|
||||||
type: "button",
|
// disabled: true,
|
||||||
style: "secondary",
|
// },
|
||||||
label: "show embed",
|
// ],
|
||||||
disabled: true,
|
// ],
|
||||||
},
|
// },
|
||||||
{
|
// ])
|
||||||
type: "button",
|
|
||||||
style: "danger",
|
|
||||||
label: "deactivate",
|
|
||||||
disabled: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("delete", async () => {
|
test.skip("delete", async () => {
|
||||||
const tester = new ReacordTester()
|
// const tester = new ReacordTester()
|
||||||
|
// const reply = tester.reply()
|
||||||
const reply = tester.reply()
|
// reply.render(
|
||||||
reply.render(
|
// <>
|
||||||
<>
|
// some text
|
||||||
some text
|
// <Embed>some embed</Embed>
|
||||||
<Embed>some embed</Embed>
|
// <Button label="some button" onClick={() => {}} />
|
||||||
<Button label="some button" onClick={() => {}} />
|
// </>,
|
||||||
</>,
|
// )
|
||||||
)
|
// await tester.assertMessages([
|
||||||
|
// {
|
||||||
await tester.assertMessages([
|
// content: "some text",
|
||||||
{
|
// embeds: [{ description: "some embed" }],
|
||||||
content: "some text",
|
// actionRows: [
|
||||||
embeds: [{ description: "some embed" }],
|
// [{ type: "button", style: "secondary", label: "some button" }],
|
||||||
actionRows: [
|
// ],
|
||||||
[{ type: "button", style: "secondary", label: "some button" }],
|
// },
|
||||||
],
|
// ])
|
||||||
},
|
// reply.destroy()
|
||||||
])
|
// await tester.assertMessages([])
|
||||||
|
|
||||||
reply.destroy()
|
|
||||||
await tester.assertMessages([])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// test multiple instances that can be updated independently,
|
// test multiple instances that can be updated independently,
|
||||||
|
|||||||
@@ -1,160 +1,143 @@
|
|||||||
import React, { useState } from "react"
|
import { test } from "vitest"
|
||||||
import { expect, test, vi } from "vitest"
|
|
||||||
import { Button, Option, Select } from "../library/main"
|
|
||||||
import { ReacordTester } from "./test-adapter"
|
|
||||||
|
|
||||||
test("single select", async () => {
|
test.skip("single select", async () => {
|
||||||
const tester = new ReacordTester()
|
// const tester = new ReacordTester()
|
||||||
const onSelect = vi.fn()
|
// const onSelect = vi.fn()
|
||||||
|
// function TestSelect() {
|
||||||
function TestSelect() {
|
// const [value, setValue] = useState<string>()
|
||||||
const [value, setValue] = useState<string>()
|
// const [disabled, setDisabled] = useState(false)
|
||||||
const [disabled, setDisabled] = useState(false)
|
// return (
|
||||||
return (
|
// <>
|
||||||
<>
|
// <Select
|
||||||
<Select
|
// placeholder="choose one"
|
||||||
placeholder="choose one"
|
// value={value}
|
||||||
value={value}
|
// onChange={onSelect}
|
||||||
onChange={onSelect}
|
// onChangeValue={setValue}
|
||||||
onChangeValue={setValue}
|
// disabled={disabled}
|
||||||
disabled={disabled}
|
// >
|
||||||
>
|
// <Option value="1" />
|
||||||
<Option value="1" />
|
// <Option value="2" label="two" />
|
||||||
<Option value="2" label="two" />
|
// <Option value="3">three</Option>
|
||||||
<Option value="3">three</Option>
|
// </Select>
|
||||||
</Select>
|
// <Button label="disable" onClick={() => setDisabled(true)} />
|
||||||
<Button label="disable" onClick={() => setDisabled(true)} />
|
// </>
|
||||||
</>
|
// )
|
||||||
)
|
// }
|
||||||
}
|
// async function assertSelect(values: string[], disabled = false) {
|
||||||
|
// await tester.assertMessages([
|
||||||
async function assertSelect(values: string[], disabled = false) {
|
// {
|
||||||
await tester.assertMessages([
|
// content: "",
|
||||||
{
|
// embeds: [],
|
||||||
content: "",
|
// actionRows: [
|
||||||
embeds: [],
|
// [
|
||||||
actionRows: [
|
// {
|
||||||
[
|
// type: "select",
|
||||||
{
|
// placeholder: "choose one",
|
||||||
type: "select",
|
// values,
|
||||||
placeholder: "choose one",
|
// disabled,
|
||||||
values,
|
// options: [
|
||||||
disabled,
|
// { label: "1", value: "1" },
|
||||||
options: [
|
// { label: "two", value: "2" },
|
||||||
{ label: "1", value: "1" },
|
// { label: "three", value: "3" },
|
||||||
{ label: "two", value: "2" },
|
// ],
|
||||||
{ label: "three", value: "3" },
|
// },
|
||||||
],
|
// ],
|
||||||
},
|
// [{ type: "button", style: "secondary", label: "disable" }],
|
||||||
],
|
// ],
|
||||||
[{ type: "button", style: "secondary", label: "disable" }],
|
// },
|
||||||
],
|
// ])
|
||||||
},
|
// }
|
||||||
])
|
// const reply = tester.reply()
|
||||||
}
|
// reply.render(<TestSelect />)
|
||||||
|
// await assertSelect([])
|
||||||
const reply = tester.reply()
|
// expect(onSelect).toHaveBeenCalledTimes(0)
|
||||||
|
// await tester.findSelectByPlaceholder("choose one").select("2")
|
||||||
reply.render(<TestSelect />)
|
// await assertSelect(["2"])
|
||||||
await assertSelect([])
|
// expect(onSelect).toHaveBeenCalledWith(
|
||||||
expect(onSelect).toHaveBeenCalledTimes(0)
|
// expect.objectContaining({ values: ["2"] }),
|
||||||
|
// )
|
||||||
await tester.findSelectByPlaceholder("choose one").select("2")
|
// await tester.findButtonByLabel("disable").click()
|
||||||
await assertSelect(["2"])
|
// await assertSelect(["2"], true)
|
||||||
expect(onSelect).toHaveBeenCalledWith(
|
// await tester.findSelectByPlaceholder("choose one").select("1")
|
||||||
expect.objectContaining({ values: ["2"] }),
|
// await assertSelect(["2"], true)
|
||||||
)
|
// expect(onSelect).toHaveBeenCalledTimes(1)
|
||||||
|
|
||||||
await tester.findButtonByLabel("disable").click()
|
|
||||||
await assertSelect(["2"], true)
|
|
||||||
|
|
||||||
await tester.findSelectByPlaceholder("choose one").select("1")
|
|
||||||
await assertSelect(["2"], true)
|
|
||||||
expect(onSelect).toHaveBeenCalledTimes(1)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("multiple select", async () => {
|
test.skip("multiple select", async () => {
|
||||||
const tester = new ReacordTester()
|
// const tester = new ReacordTester()
|
||||||
const onSelect = vi.fn()
|
// const onSelect = vi.fn()
|
||||||
|
// function TestSelect() {
|
||||||
function TestSelect() {
|
// const [values, setValues] = useState<string[]>([])
|
||||||
const [values, setValues] = useState<string[]>([])
|
// return (
|
||||||
return (
|
// <Select
|
||||||
<Select
|
// placeholder="select"
|
||||||
placeholder="select"
|
// multiple
|
||||||
multiple
|
// values={values}
|
||||||
values={values}
|
// onChange={onSelect}
|
||||||
onChange={onSelect}
|
// onChangeMultiple={setValues}
|
||||||
onChangeMultiple={setValues}
|
// >
|
||||||
>
|
// <Option value="1">one</Option>
|
||||||
<Option value="1">one</Option>
|
// <Option value="2">two</Option>
|
||||||
<Option value="2">two</Option>
|
// <Option value="3">three</Option>
|
||||||
<Option value="3">three</Option>
|
// </Select>
|
||||||
</Select>
|
// )
|
||||||
)
|
// }
|
||||||
}
|
// async function assertSelect(values: string[]) {
|
||||||
|
// await tester.assertMessages([
|
||||||
async function assertSelect(values: string[]) {
|
// {
|
||||||
await tester.assertMessages([
|
// content: "",
|
||||||
{
|
// embeds: [],
|
||||||
content: "",
|
// actionRows: [
|
||||||
embeds: [],
|
// [
|
||||||
actionRows: [
|
// {
|
||||||
[
|
// type: "select",
|
||||||
{
|
// placeholder: "select",
|
||||||
type: "select",
|
// values,
|
||||||
placeholder: "select",
|
// minValues: 0,
|
||||||
values,
|
// maxValues: 25,
|
||||||
minValues: 0,
|
// options: [
|
||||||
maxValues: 25,
|
// { label: "one", value: "1" },
|
||||||
options: [
|
// { label: "two", value: "2" },
|
||||||
{ label: "one", value: "1" },
|
// { label: "three", value: "3" },
|
||||||
{ label: "two", value: "2" },
|
// ],
|
||||||
{ label: "three", value: "3" },
|
// },
|
||||||
],
|
// ],
|
||||||
},
|
// ],
|
||||||
],
|
// },
|
||||||
],
|
// ])
|
||||||
},
|
// }
|
||||||
])
|
// const reply = tester.reply()
|
||||||
}
|
// reply.render(<TestSelect />)
|
||||||
|
// await assertSelect([])
|
||||||
const reply = tester.reply()
|
// expect(onSelect).toHaveBeenCalledTimes(0)
|
||||||
|
// await tester.findSelectByPlaceholder("select").select("1", "3")
|
||||||
reply.render(<TestSelect />)
|
// await assertSelect(expect.arrayContaining(["1", "3"]) as unknown as string[])
|
||||||
await assertSelect([])
|
// expect(onSelect).toHaveBeenCalledWith(
|
||||||
expect(onSelect).toHaveBeenCalledTimes(0)
|
// expect.objectContaining({ values: expect.arrayContaining(["1", "3"]) }),
|
||||||
|
// )
|
||||||
await tester.findSelectByPlaceholder("select").select("1", "3")
|
// await tester.findSelectByPlaceholder("select").select("2")
|
||||||
await assertSelect(expect.arrayContaining(["1", "3"]) as unknown as string[])
|
// await assertSelect(expect.arrayContaining(["2"]) as unknown as string[])
|
||||||
expect(onSelect).toHaveBeenCalledWith(
|
// expect(onSelect).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({ values: expect.arrayContaining(["1", "3"]) }),
|
// expect.objectContaining({ values: expect.arrayContaining(["2"]) }),
|
||||||
)
|
// )
|
||||||
|
// await tester.findSelectByPlaceholder("select").select()
|
||||||
await tester.findSelectByPlaceholder("select").select("2")
|
// await assertSelect([])
|
||||||
await assertSelect(expect.arrayContaining(["2"]) as unknown as string[])
|
// expect(onSelect).toHaveBeenCalledWith(expect.objectContaining({ values: [] }))
|
||||||
expect(onSelect).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({ values: expect.arrayContaining(["2"]) }),
|
|
||||||
)
|
|
||||||
|
|
||||||
await tester.findSelectByPlaceholder("select").select()
|
|
||||||
await assertSelect([])
|
|
||||||
expect(onSelect).toHaveBeenCalledWith(expect.objectContaining({ values: [] }))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("optional onSelect + unknown value", async () => {
|
test.skip("optional onSelect + unknown value", async () => {
|
||||||
const tester = new ReacordTester()
|
// const tester = new ReacordTester()
|
||||||
tester.reply().render(<Select placeholder="select" />)
|
// tester.reply().render(<Select placeholder="select" />)
|
||||||
await tester.findSelectByPlaceholder("select").select("something")
|
// await tester.findSelectByPlaceholder("select").select("something")
|
||||||
await tester.assertMessages([
|
// await tester.assertMessages([
|
||||||
{
|
// {
|
||||||
content: "",
|
// content: "",
|
||||||
embeds: [],
|
// embeds: [],
|
||||||
actionRows: [
|
// actionRows: [
|
||||||
[{ type: "select", placeholder: "select", options: [], values: [] }],
|
// [{ type: "select", placeholder: "select", options: [], values: [] }],
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
])
|
// ])
|
||||||
})
|
})
|
||||||
|
|
||||||
test.todo("select minValues and maxValues")
|
test.todo("select minValues and maxValues")
|
||||||
|
|||||||
@@ -1,286 +0,0 @@
|
|||||||
/* eslint-disable class-methods-use-this */
|
|
||||||
/* eslint-disable require-await */
|
|
||||||
import { logPretty } from "@reacord/helpers/log-pretty"
|
|
||||||
import { omit } from "@reacord/helpers/omit"
|
|
||||||
import { pruneNullishValues } from "@reacord/helpers/prune-nullish-values"
|
|
||||||
import { raise } from "@reacord/helpers/raise"
|
|
||||||
import { waitFor } from "@reacord/helpers/wait-for"
|
|
||||||
import type {
|
|
||||||
APIMessageComponentButtonInteraction,
|
|
||||||
APIMessageComponentSelectMenuInteraction,
|
|
||||||
} from "discord.js"
|
|
||||||
import { randomUUID } from "node:crypto"
|
|
||||||
import { setTimeout } from "node:timers/promises"
|
|
||||||
import type { ReactNode } from "react"
|
|
||||||
import { expect } from "vitest"
|
|
||||||
import type { ButtonClickEvent } from "../library/core/components/button"
|
|
||||||
import type { SelectChangeEvent } from "../library/core/components/select"
|
|
||||||
import type { ReacordInstance } from "../library/core/instance"
|
|
||||||
import { Reacord } from "../library/core/reacord"
|
|
||||||
import type { Channel } from "../library/internal/channel"
|
|
||||||
import { Container } from "../library/internal/container"
|
|
||||||
import type {
|
|
||||||
ButtonInteraction,
|
|
||||||
CommandInteraction,
|
|
||||||
SelectInteraction,
|
|
||||||
} from "../library/internal/interaction"
|
|
||||||
import type { Message, MessageOptions } from "../library/internal/message"
|
|
||||||
import { ChannelMessageRenderer } from "../library/internal/renderers/channel-message-renderer"
|
|
||||||
import { InteractionReplyRenderer } from "../library/internal/renderers/interaction-reply-renderer"
|
|
||||||
|
|
||||||
export type MessageSample = ReturnType<ReacordTester["sampleMessages"]>[0]
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Record adapter for automated tests. WIP
|
|
||||||
*/
|
|
||||||
export class ReacordTester extends Reacord {
|
|
||||||
private messageContainer = new Container<TestMessage>()
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super({ maxInstances: 2 })
|
|
||||||
}
|
|
||||||
|
|
||||||
get messages(): readonly TestMessage[] {
|
|
||||||
return [...this.messageContainer]
|
|
||||||
}
|
|
||||||
|
|
||||||
override send(initialContent?: ReactNode): ReacordInstance {
|
|
||||||
return this.createInstance(
|
|
||||||
new ChannelMessageRenderer(new TestChannel(this.messageContainer)),
|
|
||||||
initialContent,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override reply(initialContent?: ReactNode): ReacordInstance {
|
|
||||||
return this.createInstance(
|
|
||||||
new InteractionReplyRenderer(
|
|
||||||
new TestCommandInteraction(this.messageContainer),
|
|
||||||
),
|
|
||||||
initialContent,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override ephemeralReply(initialContent?: ReactNode): ReacordInstance {
|
|
||||||
return this.reply(initialContent)
|
|
||||||
}
|
|
||||||
|
|
||||||
assertMessages(expected: MessageSample[]) {
|
|
||||||
return waitFor(() => {
|
|
||||||
expect(this.sampleMessages()).toEqual(expected)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async assertRender(content: ReactNode, expected: MessageSample[]) {
|
|
||||||
const instance = this.reply()
|
|
||||||
instance.render(content)
|
|
||||||
await this.assertMessages(expected)
|
|
||||||
instance.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
logMessages() {
|
|
||||||
logPretty(this.sampleMessages())
|
|
||||||
}
|
|
||||||
|
|
||||||
sampleMessages() {
|
|
||||||
return pruneNullishValues(
|
|
||||||
this.messages.map((message) => ({
|
|
||||||
...message.options,
|
|
||||||
actionRows: message.options.actionRows.map((row) =>
|
|
||||||
row.map((component) =>
|
|
||||||
omit(component, [
|
|
||||||
"customId",
|
|
||||||
"onClick",
|
|
||||||
"onSelect",
|
|
||||||
"onSelectValue",
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
findButtonByLabel(label: string) {
|
|
||||||
return {
|
|
||||||
click: () => {
|
|
||||||
return waitFor(() => {
|
|
||||||
for (const [component, message] of this.eachComponent()) {
|
|
||||||
if (component.type === "button" && component.label === label) {
|
|
||||||
this.handleComponentInteraction(
|
|
||||||
new TestButtonInteraction(component.customId, message, this),
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
raise(`Couldn't find button with label "${label}"`)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
findSelectByPlaceholder(placeholder: string) {
|
|
||||||
return {
|
|
||||||
select: (...values: string[]) => {
|
|
||||||
return waitFor(() => {
|
|
||||||
for (const [component, message] of this.eachComponent()) {
|
|
||||||
if (
|
|
||||||
component.type === "select" &&
|
|
||||||
component.placeholder === placeholder
|
|
||||||
) {
|
|
||||||
this.handleComponentInteraction(
|
|
||||||
new TestSelectInteraction(
|
|
||||||
component.customId,
|
|
||||||
message,
|
|
||||||
values,
|
|
||||||
this,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
raise(`Couldn't find select with placeholder "${placeholder}"`)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createMessage(options: MessageOptions) {
|
|
||||||
return new TestMessage(options, this.messageContainer)
|
|
||||||
}
|
|
||||||
|
|
||||||
private *eachComponent() {
|
|
||||||
for (const message of this.messageContainer) {
|
|
||||||
for (const component of message.options.actionRows.flat()) {
|
|
||||||
yield [component, message] as const
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestMessage implements Message {
|
|
||||||
constructor(
|
|
||||||
public options: MessageOptions,
|
|
||||||
private container: Container<TestMessage>,
|
|
||||||
) {
|
|
||||||
container.add(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
async edit(options: MessageOptions): Promise<void> {
|
|
||||||
this.options = options
|
|
||||||
}
|
|
||||||
|
|
||||||
async delete(): Promise<void> {
|
|
||||||
this.container.remove(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestCommandInteraction implements CommandInteraction {
|
|
||||||
readonly type = "command"
|
|
||||||
readonly id = "test-command-interaction"
|
|
||||||
readonly channelId = "test-channel-id"
|
|
||||||
|
|
||||||
constructor(private messageContainer: Container<TestMessage>) {}
|
|
||||||
|
|
||||||
async reply(messageOptions: MessageOptions): Promise<Message> {
|
|
||||||
await setTimeout()
|
|
||||||
return new TestMessage(messageOptions, this.messageContainer)
|
|
||||||
}
|
|
||||||
|
|
||||||
async followUp(messageOptions: MessageOptions): Promise<Message> {
|
|
||||||
await setTimeout()
|
|
||||||
return new TestMessage(messageOptions, this.messageContainer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestInteraction {
|
|
||||||
readonly id = randomUUID()
|
|
||||||
readonly channelId = "test-channel-id"
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
readonly customId: string,
|
|
||||||
readonly message: TestMessage,
|
|
||||||
private tester: ReacordTester,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async update(options: MessageOptions): Promise<void> {
|
|
||||||
this.message.options = options
|
|
||||||
}
|
|
||||||
|
|
||||||
async deferUpdate(): Promise<void> {}
|
|
||||||
|
|
||||||
async reply(messageOptions: MessageOptions): Promise<Message> {
|
|
||||||
return this.tester.createMessage(messageOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
async followUp(messageOptions: MessageOptions): Promise<Message> {
|
|
||||||
return this.tester.createMessage(messageOptions)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestButtonInteraction
|
|
||||||
extends TestInteraction
|
|
||||||
implements ButtonInteraction
|
|
||||||
{
|
|
||||||
readonly type = "button"
|
|
||||||
readonly event: ButtonClickEvent
|
|
||||||
|
|
||||||
constructor(customId: string, message: TestMessage, tester: ReacordTester) {
|
|
||||||
super(customId, message, tester)
|
|
||||||
this.event = new TestButtonClickEvent(tester)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestSelectInteraction
|
|
||||||
extends TestInteraction
|
|
||||||
implements SelectInteraction
|
|
||||||
{
|
|
||||||
readonly type = "select"
|
|
||||||
readonly event: SelectChangeEvent
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
customId: string,
|
|
||||||
message: TestMessage,
|
|
||||||
readonly values: string[],
|
|
||||||
tester: ReacordTester,
|
|
||||||
) {
|
|
||||||
super(customId, message, tester)
|
|
||||||
this.event = new TestSelectChangeEvent(values, tester)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestComponentEvent {
|
|
||||||
constructor(private tester: ReacordTester) {}
|
|
||||||
|
|
||||||
reply(content?: ReactNode): ReacordInstance {
|
|
||||||
return this.tester.reply(content)
|
|
||||||
}
|
|
||||||
|
|
||||||
ephemeralReply(content?: ReactNode): ReacordInstance {
|
|
||||||
return this.tester.ephemeralReply(content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestButtonClickEvent
|
|
||||||
extends TestComponentEvent
|
|
||||||
implements ButtonClickEvent
|
|
||||||
{
|
|
||||||
interaction: APIMessageComponentButtonInteraction = {} as any // todo
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestSelectChangeEvent
|
|
||||||
extends TestComponentEvent
|
|
||||||
implements SelectChangeEvent
|
|
||||||
{
|
|
||||||
interaction: APIMessageComponentSelectMenuInteraction = {} as any // todo
|
|
||||||
|
|
||||||
constructor(readonly values: string[], tester: ReacordTester) {
|
|
||||||
super(tester)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestChannel implements Channel {
|
|
||||||
constructor(private messageContainer: Container<TestMessage>) {}
|
|
||||||
|
|
||||||
async send(messageOptions: MessageOptions): Promise<Message> {
|
|
||||||
return new TestMessage(messageOptions, this.messageContainer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,89 +1,74 @@
|
|||||||
import * as React from "react"
|
|
||||||
import { test } from "vitest"
|
import { test } from "vitest"
|
||||||
import {
|
|
||||||
Button,
|
|
||||||
Embed,
|
|
||||||
EmbedAuthor,
|
|
||||||
EmbedField,
|
|
||||||
EmbedFooter,
|
|
||||||
EmbedTitle,
|
|
||||||
Link,
|
|
||||||
Option,
|
|
||||||
Select,
|
|
||||||
} from "../library/main"
|
|
||||||
import { ReacordTester } from "./test-adapter"
|
|
||||||
|
|
||||||
test("text children in other components", async () => {
|
test.skip("text children in other components", async () => {
|
||||||
const tester = new ReacordTester()
|
// const tester = new ReacordTester()
|
||||||
|
// const SomeText = () => <>some text</>
|
||||||
const SomeText = () => <>some text</>
|
// await tester.assertRender(
|
||||||
|
// <>
|
||||||
await tester.assertRender(
|
// <Embed>
|
||||||
<>
|
// <EmbedTitle>
|
||||||
<Embed>
|
// <SomeText />
|
||||||
<EmbedTitle>
|
// </EmbedTitle>
|
||||||
<SomeText />
|
// <EmbedAuthor>
|
||||||
</EmbedTitle>
|
// <SomeText />
|
||||||
<EmbedAuthor>
|
// </EmbedAuthor>
|
||||||
<SomeText />
|
// <EmbedField name={<SomeText />}>
|
||||||
</EmbedAuthor>
|
// <SomeText /> <Button label="ignore this" onClick={() => {}} />
|
||||||
<EmbedField name={<SomeText />}>
|
// nailed it
|
||||||
<SomeText /> <Button label="ignore this" onClick={() => {}} />
|
// </EmbedField>
|
||||||
nailed it
|
// <EmbedFooter>
|
||||||
</EmbedField>
|
// <SomeText />
|
||||||
<EmbedFooter>
|
// </EmbedFooter>
|
||||||
<SomeText />
|
// </Embed>
|
||||||
</EmbedFooter>
|
// <Button label={<SomeText />} onClick={() => {}} />
|
||||||
</Embed>
|
// <Link url="https://discord.com" label={<SomeText />} />
|
||||||
<Button label={<SomeText />} onClick={() => {}} />
|
// <Select>
|
||||||
<Link url="https://discord.com" label={<SomeText />} />
|
// <Option value="1">
|
||||||
<Select>
|
// <SomeText />
|
||||||
<Option value="1">
|
// </Option>
|
||||||
<SomeText />
|
// <Option value="2" label={<SomeText />} description={<SomeText />} />
|
||||||
</Option>
|
// </Select>
|
||||||
<Option value="2" label={<SomeText />} description={<SomeText />} />
|
// </>,
|
||||||
</Select>
|
// [
|
||||||
</>,
|
// {
|
||||||
[
|
// content: "",
|
||||||
{
|
// embeds: [
|
||||||
content: "",
|
// {
|
||||||
embeds: [
|
// title: "some text",
|
||||||
{
|
// author: {
|
||||||
title: "some text",
|
// name: "some text",
|
||||||
author: {
|
// },
|
||||||
name: "some text",
|
// fields: [{ name: "some text", value: "some text nailed it" }],
|
||||||
},
|
// footer: {
|
||||||
fields: [{ name: "some text", value: "some text nailed it" }],
|
// text: "some text",
|
||||||
footer: {
|
// },
|
||||||
text: "some text",
|
// },
|
||||||
},
|
// ],
|
||||||
},
|
// actionRows: [
|
||||||
],
|
// [
|
||||||
actionRows: [
|
// {
|
||||||
[
|
// type: "button",
|
||||||
{
|
// label: "some text",
|
||||||
type: "button",
|
// style: "secondary",
|
||||||
label: "some text",
|
// },
|
||||||
style: "secondary",
|
// {
|
||||||
},
|
// type: "link",
|
||||||
{
|
// url: "https://discord.com",
|
||||||
type: "link",
|
// label: "some text",
|
||||||
url: "https://discord.com",
|
// },
|
||||||
label: "some text",
|
// ],
|
||||||
},
|
// [
|
||||||
],
|
// {
|
||||||
[
|
// type: "select",
|
||||||
{
|
// values: [],
|
||||||
type: "select",
|
// options: [
|
||||||
values: [],
|
// { value: "1", label: "some text" },
|
||||||
options: [
|
// { value: "2", label: "some text", description: "some text" },
|
||||||
{ value: "1", label: "some text" },
|
// ],
|
||||||
{ value: "2", label: "some text", description: "some text" },
|
// },
|
||||||
],
|
// ],
|
||||||
},
|
// ],
|
||||||
],
|
// },
|
||||||
],
|
// ],
|
||||||
},
|
// )
|
||||||
],
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,72 +1,60 @@
|
|||||||
import React from "react"
|
import { describe, it } from "vitest"
|
||||||
import { describe, expect, it } from "vitest"
|
|
||||||
import type { ReacordInstance } from "../library/main"
|
|
||||||
import { Button, useInstance } from "../library/main"
|
|
||||||
import type { MessageSample } from "./test-adapter"
|
|
||||||
import { ReacordTester } from "./test-adapter"
|
|
||||||
|
|
||||||
describe("useInstance", () => {
|
describe("useInstance", () => {
|
||||||
it("returns the instance of itself", async () => {
|
it.skip("returns the instance of itself", async () => {
|
||||||
let instanceFromHook: ReacordInstance | undefined
|
// let instanceFromHook: ReacordInstance | undefined
|
||||||
|
// function TestComponent({ name }: { name: string }) {
|
||||||
function TestComponent({ name }: { name: string }) {
|
// const instance = useInstance()
|
||||||
const instance = useInstance()
|
// instanceFromHook ??= instance
|
||||||
instanceFromHook ??= instance
|
// return (
|
||||||
return (
|
// <>
|
||||||
<>
|
// <Button
|
||||||
<Button
|
// label={`create ${name}`}
|
||||||
label={`create ${name}`}
|
// onClick={(event) => {
|
||||||
onClick={(event) => {
|
// event.reply(<TestComponent name="child" />)
|
||||||
event.reply(<TestComponent name="child" />)
|
// }}
|
||||||
}}
|
// />
|
||||||
/>
|
// <Button
|
||||||
<Button
|
// label={`destroy ${name}`}
|
||||||
label={`destroy ${name}`}
|
// onClick={() => instance.destroy()}
|
||||||
onClick={() => instance.destroy()}
|
// />
|
||||||
/>
|
// </>
|
||||||
</>
|
// )
|
||||||
)
|
// }
|
||||||
}
|
// function messageOutput(name: string): MessageSample {
|
||||||
|
// return {
|
||||||
function messageOutput(name: string): MessageSample {
|
// content: "",
|
||||||
return {
|
// embeds: [],
|
||||||
content: "",
|
// actionRows: [
|
||||||
embeds: [],
|
// [
|
||||||
actionRows: [
|
// {
|
||||||
[
|
// type: "button",
|
||||||
{
|
// label: `create ${name}`,
|
||||||
type: "button",
|
// style: "secondary",
|
||||||
label: `create ${name}`,
|
// },
|
||||||
style: "secondary",
|
// {
|
||||||
},
|
// type: "button",
|
||||||
{
|
// label: `destroy ${name}`,
|
||||||
type: "button",
|
// style: "secondary",
|
||||||
label: `destroy ${name}`,
|
// },
|
||||||
style: "secondary",
|
// ],
|
||||||
},
|
// ],
|
||||||
],
|
// }
|
||||||
],
|
// }
|
||||||
}
|
// const tester = new ReacordTester()
|
||||||
}
|
// const instance = tester.send(<TestComponent name="parent" />)
|
||||||
|
// await tester.assertMessages([messageOutput("parent")])
|
||||||
const tester = new ReacordTester()
|
// expect(instanceFromHook).toBe(instance)
|
||||||
const instance = tester.send(<TestComponent name="parent" />)
|
// await tester.findButtonByLabel("create parent").click()
|
||||||
|
// await tester.assertMessages([
|
||||||
await tester.assertMessages([messageOutput("parent")])
|
// messageOutput("parent"),
|
||||||
expect(instanceFromHook).toBe(instance)
|
// messageOutput("child"),
|
||||||
|
// ])
|
||||||
await tester.findButtonByLabel("create parent").click()
|
// // this test ensures that the only the child instance is destroyed,
|
||||||
await tester.assertMessages([
|
// // and not the parent instance
|
||||||
messageOutput("parent"),
|
// await tester.findButtonByLabel("destroy child").click()
|
||||||
messageOutput("child"),
|
// await tester.assertMessages([messageOutput("parent")])
|
||||||
])
|
// await tester.findButtonByLabel("destroy parent").click()
|
||||||
|
// await tester.assertMessages([])
|
||||||
// this test ensures that the only the child instance is destroyed,
|
|
||||||
// and not the parent instance
|
|
||||||
await tester.findButtonByLabel("destroy child").click()
|
|
||||||
await tester.assertMessages([messageOutput("parent")])
|
|
||||||
|
|
||||||
await tester.findButtonByLabel("destroy parent").click()
|
|
||||||
await tester.assertMessages([])
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user