Files
talk/src/core/client/stream/local/initLocalState.spec.ts
T
Wyatt JohnsonGitHubkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
9d02391062 [CORL-1239] Swap setTimeout for setLongTimeout (#3071)
* fix: ensure user editable time use setLongTimeout

* fix: fixed wrong type

* fix: fixed snapshots

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-08-04 18:24:31 +00:00

59 lines
1.7 KiB
TypeScript

import { Environment, RecordSource } from "relay-runtime";
import { waitFor } from "coral-common/helpers";
import { CoralContext } from "coral-framework/lib/bootstrap";
import { LOCAL_ID } from "coral-framework/lib/relay";
import { createPromisifiedStorage } from "coral-framework/lib/storage";
import {
createRelayEnvironment,
replaceHistoryLocation,
} from "coral-framework/testHelpers";
import initLocalState from "./initLocalState";
let environment: Environment;
let source: RecordSource;
beforeEach(() => {
source = new RecordSource();
environment = createRelayEnvironment({
source,
initLocalState: false,
});
});
it("init local state", async () => {
const context: Partial<CoralContext> = {
localStorage: createPromisifiedStorage(),
};
await initLocalState(environment, context as any);
await waitFor();
expect(JSON.stringify(source.toJSON(), null, 2)).toMatchSnapshot();
});
it("set storyID from query", async () => {
const context: Partial<CoralContext> = {
localStorage: createPromisifiedStorage(),
};
const storyID = "story-id";
const restoreHistoryLocation = replaceHistoryLocation(
`http://localhost/?storyID=${storyID}`
);
await initLocalState(environment, context as any);
expect(source.get(LOCAL_ID)!.storyID).toBe(storyID);
restoreHistoryLocation();
});
it("set commentID from query", async () => {
const context: Partial<CoralContext> = {
localStorage: createPromisifiedStorage(),
};
const commentID = "comment-id";
const restoreHistoryLocation = replaceHistoryLocation(
`http://localhost/?commentID=${commentID}`
);
await initLocalState(environment, context as any);
expect(source.get(LOCAL_ID)!.commentID).toBe(commentID);
restoreHistoryLocation();
});