[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:
Kiwi
2019-04-27 01:04:16 +02:00
committed by GitHub
parent b1efdad981
commit 60c8f9a0d5
13 changed files with 764 additions and 159 deletions
@@ -11,6 +11,7 @@ import { BrowserInfo } from "talk-framework/lib/browserInfo";
import { PostMessageService } from "talk-framework/lib/postMessage";
import { RestClient } from "talk-framework/lib/rest";
import { PromisifiedStorage } from "talk-framework/lib/storage";
import { TransitionControlData } from "talk-framework/testHelpers";
import { UIContext } from "talk-ui/components";
import { ClickFarAwayRegister } from "talk-ui/components/ClickOutside";
@@ -62,6 +63,9 @@ export interface TalkContext {
/** Clear session data. */
clearSession: () => Promise<void>;
/** Controls router transitions (for tests) */
transitionControl?: TransitionControlData;
}
export const TalkReactContext = React.createContext<TalkContext>({} as any);
@@ -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";