Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial rapid experiment details page and edit form - Fixes #2687 #2899

Merged
merged 10 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ COPY ./package.json /app/package.json
COPY ./yarn.lock /app/yarn.lock
COPY ./experimenter/static/core/package.json /app/experimenter/static/core/package.json
COPY ./experimenter/static/rapid/package.json /app/experimenter/static/rapid/package.json
RUN yarn install
RUN yarn install --frozen-lockfile
rehandalal marked this conversation as resolved.
Show resolved Hide resolved

# Build assets
COPY ./experimenter/static/ /app/experimenter/static/
Expand Down
4 changes: 4 additions & 0 deletions app/experimenter/static/rapid/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const baseSettings = {
pattern: "experimenter-rapid/**",
group: "parent",
},
{
pattern: "experimenter-types/**",
group: "parent",
},
],
pathGroupsExcludedImportTypes: ["builtin"],
alphabetize: {
Expand Down
4 changes: 0 additions & 4 deletions app/experimenter/static/rapid/__tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"env": {
"jest": true
},
"globals": {
"fetchMock": "writable",
"renderWithRouter": "writable"
}
}
27 changes: 0 additions & 27 deletions app/experimenter/static/rapid/__tests__/app.test.js

This file was deleted.

71 changes: 71 additions & 0 deletions app/experimenter/static/rapid/__tests__/app.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { cleanup, waitFor } from "@testing-library/react";
import fetchMock from "jest-fetch-mock";
import React from "react";

import App from "experimenter-rapid/components/App";

import { renderWithRouter } from "./utils";

afterEach(cleanup);

describe("<App />", () => {
it("root route shows link to create page", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root root! 😆

const { getByText } = renderWithRouter(<App />);
expect(getByText("Create a new experiment")).toBeInTheDocument();
});

it("unknown route shows 404 message", () => {
const { getByText } = renderWithRouter(<App />, {
route: "/a/route/that/does/not/exist/",
});
expect(getByText("404")).toBeInTheDocument();
});

it("includes the experiment form page at `/new/`", () => {
const { getByText } = renderWithRouter(<App />, {
route: "/new/",
});
expect(getByText("Create a New A/A Experiment")).toBeInTheDocument();
});

it("includes the experiment form page at `/:experimentSlug/edit/`", async () => {
fetchMock.mockOnce(async () => {
return JSON.stringify({
slug: "test-slug",
name: "Test Name",
objectives: "Test objectives",
owner: "test@owner.com",
});
});

const { getByText, getByLabelText } = renderWithRouter(<App />, {
route: "/test-slug/edit/",
});
expect(getByText("Create a New A/A Experiment")).toBeInTheDocument();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followup: #2901


const nameField = getByLabelText("Public Name") as HTMLInputElement;
await waitFor(() => {
return expect(nameField.value).toEqual("Test Name");
});
});

it("includes the experiment details page at `/:experimentSlug/`", async () => {
fetchMock.mockOnce(async () => {
return JSON.stringify({
slug: "test-slug",
name: "Test Name",
objectives: "Test objectives",
owner: "test@owner.com",
});
});

const { getByText, getByDisplayValue } = renderWithRouter(<App />, {
route: "/test-slug/",
});
expect(getByText("Experiment Summary")).toBeInTheDocument();

await waitFor(() => {
return expect(getByDisplayValue("test@owner.com")).toBeInTheDocument();
});
});
});
58 changes: 58 additions & 0 deletions app/experimenter/static/rapid/__tests__/experimentDetails.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { cleanup, fireEvent, waitFor } from "@testing-library/react";
import fetchMock from "jest-fetch-mock";
import React from "react";

import {
renderWithRouter,
wrapInExperimentProvider,
} from "experimenter-rapid/__tests__/utils";
import ExperimentDetails from "experimenter-rapid/components/experiments/ExperimentDetails";

afterEach(async () => {
await cleanup();
fetchMock.resetMocks();
});

describe("<ExperimentDetails />", () => {
it("renders without issues", async () => {
const { getByDisplayValue } = renderWithRouter(
wrapInExperimentProvider(<ExperimentDetails />, {
initialState: {
slug: "test-slug",
name: "Test Name",
objectives: "Test objectives",
owner: "test@owner.com",
},
}),
);

await waitFor(() => {
return expect(getByDisplayValue("test@owner.com")).toBeInTheDocument();
});

expect(getByDisplayValue("Test Name")).toBeInTheDocument();
expect(getByDisplayValue("Test objectives")).toBeInTheDocument();
});

it("sends you to the edit page when the 'Back' button is clicked", async () => {
const { getByText, history } = renderWithRouter(
wrapInExperimentProvider(<ExperimentDetails />, {
initialState: {
slug: "test-slug",
name: "Test Name",
objectives: "Test objectives",
owner: "test@owner.com",
},
}),
);

const historyPush = jest.spyOn(history, "push");

const backButton = getByText("Back");
fireEvent.click(backButton);

await waitFor(() => expect(historyPush).toHaveBeenCalledTimes(1));
const lastEntry = history.entries.pop() || { pathname: "" };
expect(lastEntry.pathname).toBe("/test-slug/edit/");
});
});
71 changes: 0 additions & 71 deletions app/experimenter/static/rapid/__tests__/experimentForm.test.js

This file was deleted.

Loading