mirror of
https://github.com/wassname/talk.git
synced 2026-08-14 12:50:17 +08:00
[next] Fix warnings and errors that appear during test (#2348)
* fix: handle react act errors * fix: fixed deprecated reporter option
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { pureMerge } from "coral-common/utils";
|
||||
import { GQLResolver } from "coral-framework/schema";
|
||||
import {
|
||||
act,
|
||||
createAccessToken,
|
||||
createResolversStub,
|
||||
CreateTestRendererParams,
|
||||
@@ -117,11 +118,13 @@ it("do not render createPassword view when local auth is disabled", async () =>
|
||||
}),
|
||||
});
|
||||
|
||||
await wait(() =>
|
||||
expect(window.location.toString()).toBe(
|
||||
"http://localhost/admin/moderate/reported"
|
||||
)
|
||||
);
|
||||
await act(async () => {
|
||||
await wait(() =>
|
||||
expect(window.location.toString()).toBe(
|
||||
"http://localhost/admin/moderate/reported"
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("complete account", async () => {
|
||||
@@ -137,9 +140,11 @@ it("complete account", async () => {
|
||||
},
|
||||
}),
|
||||
});
|
||||
await wait(() =>
|
||||
expect(window.location.toString()).toBe(
|
||||
"http://localhost/admin/moderate/reported"
|
||||
)
|
||||
);
|
||||
await act(async () => {
|
||||
await wait(() =>
|
||||
expect(window.location.toString()).toBe(
|
||||
"http://localhost/admin/moderate/reported"
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
QueryToModerationQueuesResolver,
|
||||
} from "coral-framework/schema";
|
||||
import {
|
||||
act,
|
||||
createAccessToken,
|
||||
createQueryResolverStub,
|
||||
createResolversStub,
|
||||
@@ -55,11 +56,13 @@ async function createTestRenderer(
|
||||
|
||||
it("redirect when already logged in", async () => {
|
||||
await createTestRenderer();
|
||||
await wait(() =>
|
||||
expect(window.location.toString()).toBe(
|
||||
"http://localhost/admin/moderate/reported"
|
||||
)
|
||||
);
|
||||
await act(async () => {
|
||||
await wait(() =>
|
||||
expect(window.location.toString()).toBe(
|
||||
"http://localhost/admin/moderate/reported"
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("redirect to redirectPath when already logged in", async () => {
|
||||
@@ -68,9 +71,11 @@ it("redirect to redirectPath when already logged in", async () => {
|
||||
localRecord.setValue("/admin/moderate/pending", "redirectPath");
|
||||
},
|
||||
});
|
||||
await wait(() =>
|
||||
expect(window.location.toString()).toBe(
|
||||
"http://localhost/admin/moderate/pending"
|
||||
)
|
||||
);
|
||||
await act(async () => {
|
||||
await wait(() =>
|
||||
expect(window.location.toString()).toBe(
|
||||
"http://localhost/admin/moderate/pending"
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
QueryToModerationQueuesResolver,
|
||||
} from "coral-framework/schema";
|
||||
import {
|
||||
act,
|
||||
createQueryResolverStub,
|
||||
createResolversStub,
|
||||
CreateTestRendererParams,
|
||||
@@ -50,10 +51,12 @@ async function createTestRenderer(
|
||||
|
||||
it("redirect when not logged in", async () => {
|
||||
const { context } = await createTestRenderer();
|
||||
await wait(() => {
|
||||
expect(lookup(context.relayEnvironment, LOCAL_ID)!.redirectPath).toBe(
|
||||
"/admin/moderate/reported"
|
||||
);
|
||||
expect(window.location.toString()).toBe("http://localhost/admin/login");
|
||||
await act(async () => {
|
||||
await wait(() => {
|
||||
expect(lookup(context.relayEnvironment, LOCAL_ID)!.redirectPath).toBe(
|
||||
"/admin/moderate/reported"
|
||||
);
|
||||
expect(window.location.toString()).toBe("http://localhost/admin/login");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import sinon from "sinon";
|
||||
import { pureMerge } from "coral-common/utils";
|
||||
import { GQLResolver } from "coral-framework/schema";
|
||||
import {
|
||||
act,
|
||||
createAccessToken,
|
||||
createResolversStub,
|
||||
CreateTestRendererParams,
|
||||
@@ -12,6 +13,7 @@ import {
|
||||
within,
|
||||
} from "coral-framework/testHelpers";
|
||||
|
||||
import { ReactTestInstance } from "react-test-renderer";
|
||||
import create from "../create";
|
||||
import {
|
||||
emptyModerationQueues,
|
||||
@@ -47,10 +49,14 @@ async function createTestRenderer(
|
||||
},
|
||||
});
|
||||
|
||||
const form = await waitForElement(() =>
|
||||
within(testRenderer.root).getByType("form")
|
||||
);
|
||||
return { testRenderer, form, context };
|
||||
let form: ReactTestInstance;
|
||||
|
||||
await act(async () => {
|
||||
form = await waitForElement(() =>
|
||||
within(testRenderer.root).getByType("form")
|
||||
);
|
||||
});
|
||||
return { testRenderer, form: form!, context };
|
||||
}
|
||||
|
||||
it("renders sign in form", async () => {
|
||||
@@ -150,12 +156,16 @@ it("submits form successfully", async () => {
|
||||
|
||||
const historyMock = sinon.mock(window.history);
|
||||
|
||||
form.props.onSubmit();
|
||||
act(() => {
|
||||
form.props.onSubmit();
|
||||
});
|
||||
const submitButton = within(form).getByText("Sign in with Email", {
|
||||
selector: "button",
|
||||
});
|
||||
expect(submitButton.props.disabled).toBe(true);
|
||||
await wait(() => expect(submitButton.props.disabled).toBe(false));
|
||||
await act(async () => {
|
||||
await wait(() => expect(submitButton.props.disabled).toBe(false));
|
||||
});
|
||||
expect(location.toString()).toMatchSnapshot();
|
||||
restMock.verify();
|
||||
historyMock.verify();
|
||||
|
||||
Reference in New Issue
Block a user