mirror of
https://github.com/wassname/talk.git
synced 2026-09-10 12:43:11 +08:00
Move uuid generation to TalkContext
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { graphql } from "react-relay";
|
||||
import { Environment, RelayMutationConfig } from "relay-runtime";
|
||||
import uuid from "uuid/v4";
|
||||
|
||||
import { getMe } from "talk-framework/helpers";
|
||||
import { TalkContext } from "talk-framework/lib/bootstrap";
|
||||
import {
|
||||
commitMutationPromiseNormalized,
|
||||
createMutationContainer,
|
||||
@@ -65,7 +65,11 @@ function getConfig(input: CreateCommentInput): RelayMutationConfig[] {
|
||||
];
|
||||
}
|
||||
|
||||
function commit(environment: Environment, input: CreateCommentInput) {
|
||||
function commit(
|
||||
environment: Environment,
|
||||
input: CreateCommentInput,
|
||||
{ uuidGenerator }: TalkContext
|
||||
) {
|
||||
const me = getMe(environment)!;
|
||||
const currentDate = new Date().toISOString();
|
||||
return commitMutationPromiseNormalized<MutationTypes>(environment, {
|
||||
@@ -81,7 +85,7 @@ function commit(environment: Environment, input: CreateCommentInput) {
|
||||
edge: {
|
||||
cursor: currentDate,
|
||||
node: {
|
||||
id: uuid(),
|
||||
id: uuidGenerator(),
|
||||
createdAt: currentDate,
|
||||
author: {
|
||||
id: me.id,
|
||||
|
||||
@@ -213,7 +213,7 @@ exports[`post a comment: optimistic response 1`] = `
|
||||
>
|
||||
<button
|
||||
className="BaseButton-root Button-root Button-sizeSmall Button-colorRegular Button-variantGhost"
|
||||
id="comments-commentContainer-replyButton-comment-optimistic"
|
||||
id="comments-commentContainer-replyButton-uuid-0"
|
||||
onBlur={[Function]}
|
||||
onClick={[Function]}
|
||||
onFocus={[Function]}
|
||||
|
||||
@@ -816,7 +816,7 @@ exports[`post a reply: optimistic response 1`] = `
|
||||
>
|
||||
<button
|
||||
className="BaseButton-root Button-root Button-sizeSmall Button-colorRegular Button-variantGhost"
|
||||
id="comments-commentContainer-replyButton-comment-optimistic"
|
||||
id="comments-commentContainer-replyButton-uuid-0"
|
||||
onBlur={[Function]}
|
||||
onClick={[Function]}
|
||||
onFocus={[Function]}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { PostMessageService } from "talk-framework/lib/postMessage";
|
||||
import { RestClient } from "talk-framework/lib/rest";
|
||||
import { createPromisifiedStorage } from "talk-framework/lib/storage";
|
||||
import AppContainer from "talk-stream/containers/AppContainer";
|
||||
import { createUUIDGenerator } from "talk-framework/testHelpers";
|
||||
|
||||
import createEnvironment from "./createEnvironment";
|
||||
import createFluentBundle from "./createFluentBundle";
|
||||
@@ -44,6 +45,7 @@ export default function create(params: CreateParams) {
|
||||
rest: new RestClient("http://localhost/api"),
|
||||
postMessage: new PostMessageService(),
|
||||
browserInfo: { ios: false },
|
||||
uuidGenerator: createUUIDGenerator(),
|
||||
};
|
||||
|
||||
const testRenderer = TestRenderer.create(
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import { ReactTestRenderer } from "react-test-renderer";
|
||||
import timekeeper from "timekeeper";
|
||||
import uuid from "uuid/v4";
|
||||
|
||||
import { timeout } from "talk-common/utils";
|
||||
import { createSinonStub } from "talk-framework/testHelpers";
|
||||
import { UUIDMock } from "talk-test/mocks";
|
||||
|
||||
import create from "./create";
|
||||
import { assets, users } from "./fixtures";
|
||||
|
||||
const uuidMock = uuid as UUIDMock;
|
||||
|
||||
let testRenderer: ReactTestRenderer;
|
||||
beforeEach(() => {
|
||||
const resolvers = {
|
||||
@@ -70,9 +66,6 @@ it("renders comment stream", async () => {
|
||||
});
|
||||
|
||||
it("post a comment", async () => {
|
||||
// set next UUID of the optimistic response.
|
||||
uuidMock.setMockData(["comment-optimistic"]);
|
||||
|
||||
// Wait for loading.
|
||||
await timeout();
|
||||
testRenderer.root
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import { ReactTestRenderer } from "react-test-renderer";
|
||||
import timekeeper from "timekeeper";
|
||||
import uuid from "uuid/v4";
|
||||
|
||||
import { timeout } from "talk-common/utils";
|
||||
import { createSinonStub } from "talk-framework/testHelpers";
|
||||
import { UUIDMock } from "talk-test/mocks";
|
||||
|
||||
import create from "./create";
|
||||
import { assets, users } from "./fixtures";
|
||||
|
||||
const uuidMock = uuid as UUIDMock;
|
||||
|
||||
let testRenderer: ReactTestRenderer;
|
||||
beforeEach(() => {
|
||||
const resolvers = {
|
||||
@@ -74,9 +70,6 @@ it("renders comment stream", async () => {
|
||||
});
|
||||
|
||||
it("post a reply", async () => {
|
||||
// set next UUID of the optimistic response.
|
||||
uuidMock.setMockData(["comment-optimistic"]);
|
||||
|
||||
// Wait for loading.
|
||||
await timeout();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user