mirror of
https://github.com/wassname/talk.git
synced 2026-09-09 11:38:08 +08:00
[next] Decision History (#2103)
* feat: decision history components * feat: implement decision history container * test: add unit tests * test: integration test * test: fix remaining snapshots * test: add more concepts from react-testing-library * fix: wrap long username into the next line * fix: fallback to word-break: break-all;
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import { ReactTestInstance } from "react-test-renderer";
|
||||
|
||||
export default function getByTestID(id: string, instance: ReactTestInstance) {
|
||||
return instance.findByProps({ "data-test": id });
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import React from "react";
|
||||
import { ReactTestInstance } from "react-test-renderer";
|
||||
|
||||
export default function getByText(text: string, instance: ReactTestInstance) {
|
||||
return instance.find(i => {
|
||||
if (!i.props.children) {
|
||||
return false;
|
||||
}
|
||||
const children = React.Children.toArray(i.props.children);
|
||||
for (const c of children) {
|
||||
if (
|
||||
typeof c === "string" &&
|
||||
c.toLowerCase().includes(text.toLowerCase())
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
@@ -13,3 +13,7 @@ export * from "./denormalize";
|
||||
export { default as replaceHistoryLocation } from "./replaceHistoryLocation";
|
||||
export { default as limitSnapshotTo } from "./limitSnapshotTo";
|
||||
export { default as inputPredicate } from "./inputPredicate";
|
||||
export { default as getByTestID } from "./getByTestID";
|
||||
export { default as getByText } from "./getByText";
|
||||
export { default as wait } from "./wait";
|
||||
export { default as waitForElement } from "./waitForElement";
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import waitForExpect from "wait-for-expect";
|
||||
|
||||
interface Options {
|
||||
timeout?: number;
|
||||
interval?: number;
|
||||
}
|
||||
|
||||
export default async function wait(
|
||||
callback: () => void,
|
||||
{ timeout = 4500, interval = 50 }: Options = {}
|
||||
) {
|
||||
return waitForExpect(callback, timeout, interval);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { ReactTestInstance } from "react-test-renderer";
|
||||
|
||||
import wait from "./wait";
|
||||
|
||||
interface Options {
|
||||
timeout?: number;
|
||||
interval?: number;
|
||||
}
|
||||
|
||||
export default async function waitForElement(
|
||||
callback: () => ReactTestInstance | null,
|
||||
options?: Options
|
||||
): Promise<ReactTestInstance> {
|
||||
let result: ReactTestInstance | null = null;
|
||||
await wait(() => {
|
||||
result = callback();
|
||||
if (!result) {
|
||||
throw new Error();
|
||||
}
|
||||
}, options);
|
||||
return result!;
|
||||
}
|
||||
Reference in New Issue
Block a user