mirror of
https://github.com/wassname/talk.git
synced 2026-08-05 13:30:26 +08:00
[next] Tests for new story filter and combo box (#2288)
* test: add tests for changes in stories page * test: search box and moderate specific story * fix: remaining snapshot * fix: test
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { Location, Match, Router, withRouter } from "found";
|
||||
import React, { useEffect } from "react";
|
||||
import { withContext } from "talk-framework/lib/bootstrap";
|
||||
|
||||
interface Props {
|
||||
/** router is injected by `withRouter` HOC */
|
||||
router: Router;
|
||||
/** match is injected by `withRouter` HOC */
|
||||
match: Match;
|
||||
/** transitionControl is injected by `withContext` HOC */
|
||||
transitionControl: TransitionControlData | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* TransitionControlData allows controlling router transition.
|
||||
*/
|
||||
export interface TransitionControlData {
|
||||
/** allowTransition if set to false, will prevent router transitions from happening. */
|
||||
allowTransition: boolean;
|
||||
/** history contains all records of router transition requests. */
|
||||
history: Location[];
|
||||
}
|
||||
|
||||
const TransitionControl: React.FunctionComponent<Props> = props => {
|
||||
useEffect(() => {
|
||||
return props.router.addTransitionHook(location => {
|
||||
if (props.transitionControl) {
|
||||
props.transitionControl.history.push(location);
|
||||
if (!props.transitionControl.allowTransition) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return;
|
||||
});
|
||||
}, []);
|
||||
return null;
|
||||
};
|
||||
|
||||
const enhanced = withContext(({ transitionControl }) => ({
|
||||
transitionControl,
|
||||
}))(withRouter(TransitionControl));
|
||||
|
||||
export default enhanced;
|
||||
@@ -6,6 +6,7 @@ import React from "react";
|
||||
import TestRenderer, { ReactTestRenderer } from "react-test-renderer";
|
||||
import { Environment, RecordProxy, RecordSourceProxy } from "relay-runtime";
|
||||
|
||||
import { RequireProperty } from "talk-common/types";
|
||||
import { TalkContext, TalkContextProvider } from "talk-framework/lib/bootstrap";
|
||||
import { PostMessageService } from "talk-framework/lib/postMessage";
|
||||
import { RestClient } from "talk-framework/lib/rest";
|
||||
@@ -77,7 +78,7 @@ export default function createTestRenderer<
|
||||
},
|
||||
});
|
||||
|
||||
const context: TalkContext = {
|
||||
const context: RequireProperty<TalkContext, "transitionControl"> = {
|
||||
relayEnvironment: environment,
|
||||
locales: ["en-US"],
|
||||
localeBundles: [
|
||||
@@ -94,6 +95,10 @@ export default function createTestRenderer<
|
||||
uuidGenerator: createUUIDGenerator(),
|
||||
eventEmitter: new EventEmitter2({ wildcard: true, maxListeners: 20 }),
|
||||
clearSession: () => Promise.resolve(),
|
||||
transitionControl: {
|
||||
allowTransition: true,
|
||||
history: [],
|
||||
},
|
||||
};
|
||||
|
||||
let testRenderer: ReactTestRenderer;
|
||||
|
||||
@@ -36,3 +36,7 @@ export {
|
||||
CreateTestRendererParams,
|
||||
} from "./createTestRenderer";
|
||||
export { default as createResolversStub } from "./createResolversStub";
|
||||
export {
|
||||
TransitionControlData,
|
||||
default as TransitionControl,
|
||||
} from "./TransitionControl";
|
||||
|
||||
Reference in New Issue
Block a user