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

View File

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

View File

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