match test adapter syntax

This commit is contained in:
Domin-MND
2023-10-23 22:25:06 +03:00
parent ce12351a24
commit 13fcf7ddc9
4 changed files with 22 additions and 15 deletions

View File

@@ -6,7 +6,7 @@ import { test } from "vitest"
test("rendering behavior", async () => {
const tester = new ReacordTester()
const reply = tester.reply()
const reply = tester.createInteractionReply()
reply.render(<KitchenSinkCounter onDeactivate={() => reply.deactivate()} />)
await tester.assertMessages([
@@ -244,7 +244,7 @@ test("rendering behavior", async () => {
test("delete", async () => {
const tester = new ReacordTester()
const reply = tester.reply()
const reply = tester.createInteractionReply()
reply.render(
<>
some text

View File

@@ -53,7 +53,7 @@ test("single select", async () => {
])
}
const reply = tester.reply()
const reply = tester.createInteractionReply()
reply.render(<TestSelect />)
await assertSelect([])
@@ -119,7 +119,7 @@ test("multiple select", async () => {
])
}
const reply = tester.reply()
const reply = tester.createInteractionReply()
reply.render(<TestSelect />)
await assertSelect([])
@@ -148,7 +148,7 @@ test("multiple select", async () => {
test("optional onSelect + unknown value", async () => {
const tester = new ReacordTester()
tester.reply().render(<Select placeholder="select" />)
tester.createInteractionReply().render(<Select placeholder="select" />)
await tester.findSelectByPlaceholder("select").select("something")
await tester.assertMessages([
{

View File

@@ -11,6 +11,7 @@ import type {
ChannelInfo,
GuildInfo,
MessageInfo,
ReplyInfo,
UserInfo,
} from "../library/core/component-event"
import type { ButtonClickEvent } from "../library/core/components/button"
@@ -42,14 +43,24 @@ export class ReacordTester extends Reacord {
return [...this.messageContainer]
}
public send(initialContent?: ReactNode): ReacordInstance {
public createChannelMessage(initialContent?: ReactNode): ReacordInstance {
return this.createInstance(
new ChannelMessageRenderer(new TestChannel(this.messageContainer)),
initialContent,
)
}
public reply(initialContent?: ReactNode): ReacordInstance {
public createMessageReply(initialContent?: ReactNode): ReacordInstance {
return this.createInstance(
new ChannelMessageRenderer(new TestChannel(this.messageContainer)),
initialContent,
)
}
public createInteractionReply(
initialContent?: ReactNode,
_options?: ReplyInfo,
): ReacordInstance {
return this.createInstance(
new InteractionReplyRenderer(
new TestCommandInteraction(this.messageContainer),
@@ -58,10 +69,6 @@ export class ReacordTester extends Reacord {
)
}
public ephemeralReply(initialContent?: ReactNode): ReacordInstance {
return this.reply(initialContent)
}
assertMessages(expected: MessageSample[]) {
return waitFor(() => {
expect(this.sampleMessages()).toEqual(expected)
@@ -69,7 +76,7 @@ export class ReacordTester extends Reacord {
}
async assertRender(content: ReactNode, expected: MessageSample[]) {
const instance = this.reply()
const instance = this.createInteractionReply()
instance.render(content)
await this.assertMessages(expected)
instance.destroy()
@@ -254,11 +261,11 @@ class TestComponentEvent {
guild: GuildInfo = {} as GuildInfo // todo
reply(content?: ReactNode): ReacordInstance {
return this.tester.reply(content)
return this.tester.createInteractionReply(content)
}
ephemeralReply(content?: ReactNode): ReacordInstance {
return this.tester.ephemeralReply(content)
return this.tester.createInteractionReply(content, { ephemeral: true })
}
}

View File

@@ -49,7 +49,7 @@ describe("useInstance", () => {
}
const tester = new ReacordTester()
const instance = tester.send(<TestComponent name="parent" />)
const instance = tester.createChannelMessage(<TestComponent name="parent" />)
await tester.assertMessages([messageOutput("parent")])
expect(instanceFromHook).toBe(instance)