Skip to content
This repository has been archived by the owner on Jul 9, 2019. It is now read-only.

Commit

Permalink
Studies Tests (#1680)
Browse files Browse the repository at this point in the history
* nearly done studies addition [ci skip]

* fix tests and lints for studies

* project adjustments for testing

* added studies changes

* fix failing ci test

* add aphrodite reset to slider test

* add in more aphrodite stuff

* sheesh, add it to all new tests?
  • Loading branch information
delianides authored and James Baxley committed Dec 22, 2016
1 parent f383ca6 commit 58bfc03
Show file tree
Hide file tree
Showing 25 changed files with 2,273 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ docs

# editor files
.vscode
.tsconfig
6 changes: 6 additions & 0 deletions .meteor/mocks/mongo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

export const DDP = {
_CurrentInvocation: {
get: jest.fn(() => {}),
},
}
2 changes: 1 addition & 1 deletion imports/pages/studies/EntryList.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class StudyEntryWithoutData extends Component {
}

const STUDY_ENTRY_QUERY = gql`
query GetEntriesFromSeries($id: ID!) {
query GetEntriesFromStudy($id: ID!) {
content: node(id: $id) {
... on Content {
studyEntries: children(channels: ["study_entries"]) {
Expand Down
91 changes: 91 additions & 0 deletions imports/pages/studies/__tests__/EntryList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* eslint-disable */
import renderer from "react-test-renderer";
import { shallow } from "enzyme";
import { shallowToJson } from "enzyme-to-json";
import { reset, startBuffering } from "aphrodite/lib/inject";

beforeEach(() => {
reset();
startBuffering();
});

afterEach(() => {
reset();
});

import {
StudyEntryWithoutData as StudyEntry,
STUDY_ENTRY_QUERY,
} from "../EntryList";

const defaultProps = {
studyEntries: {
loading: false,
content: {
studyEntries: [
{
title: "Study Entry"
},
],
},
},
light: true,
focus: "1"
};

const generateComponent = (additionalProps = {}) => {
const newProps = {
...defaultProps,
...additionalProps,
};

return <StudyEntry { ...newProps } />;
};

it("parses study entry query", () => {
expect(STUDY_ENTRY_QUERY).toMatchSnapshot();
});

it("renders with props", () => {
const tree = renderer.create(generateComponent());
expect(tree).toMatchSnapshot();
});

it("returns null if there is no studyEntries", () => {
const tree = renderer.create(generateComponent({
studyEntries: {
content: {
studyEntries: [],
}
},
}));
expect(tree).toMatchSnapshot();
});

it("has a loading state", () => {
const tree = renderer.create(generateComponent({
studyEntries: {
loading: true
},
}));
expect(tree).toMatchSnapshot();
})

it("calculates width based on window size", () => {
const wrapper = shallow(generateComponent());
const result = wrapper.instance().dynamicWidth();
expect(result).toEqual({ width: "847.2px" });
});

it("calculates tablet version", () => {
window.isTablet = true;
const wrapper = shallow(generateComponent());
const result = wrapper.instance().dynamicWidth();
expect(result).toEqual({ width: "429px" });
});

it("overflow contains css object", () => {
const wrapper = shallow(generateComponent());
const result = wrapper.instance().overflow;
expect(result).toMatchSnapshot();
});
48 changes: 48 additions & 0 deletions imports/pages/studies/__tests__/EntryListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable */
import renderer from "react-test-renderer";
import { reset, startBuffering } from "aphrodite/lib/inject";

import StudiesEntryListItem from "../EntryListItem";

beforeEach(() => {
reset();
startBuffering();
});

afterEach(() => {
reset();
});

describe("StudiesEntryListItem", () => {
it("takes a single study as a prop", () => {
const study = {
"id": "e2a6f1a585c90a33b88f8e41b26c9ffe",
"entryId": "e2a6f1a585c90a33b88f8e41b26c9ffe",
"title": "Who are you trying to please?",
"status": "open",
"channelName": "study_entries",
"parent": {
"entryId": "9bff3ab47f41d1818fa3dc2803fa141b"
},
"meta": {
"urlTitle": "who-are-you-trying-to-please",
"siteId": "393ebdf414cdf68c96bb7fd149f7a434",
"date": "Wed Dec 07 2016 00:00:00 GMT+0000 (UTC)",
"channelId": "d89926c004a563d46e0d10ca1a5fea53"
},
"content": {
"speaker": ""
}
};

const tree = renderer.create(
<StudiesEntryListItem
studyEntry={study}
order={1}
light={true}
/>
);

expect(tree).toMatchSnapshot();
});
});
36 changes: 36 additions & 0 deletions imports/pages/studies/__tests__/Hero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable */
import renderer from "react-test-renderer";
import { reset, startBuffering } from "aphrodite/lib/inject";

import StudyHero from "../Hero";

beforeEach(() => {
reset();
startBuffering();
});

afterEach(() => {
reset();
});

describe("StudyHero", () => {
it("changes class name based on props", () => {
const study = {
"content": {
"isLight": true,
"images":[
{ "url": "http://exampleimage.org" }
]
}
};

const tree = renderer.create(
<StudyHero study={study} />
);

expect(tree).toMatchSnapshot();
});
})



113 changes: 113 additions & 0 deletions imports/pages/studies/__tests__/Single.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* eslint-disable */
import renderer from "react-test-renderer";
import { shallow, mount } from "enzyme";
import { reset, startBuffering } from "aphrodite/lib/inject";

import { StudiesSingleWithoutData } from "../Single";
import {
nav as navActions,
} from "../../../store";
import headerActions from "../../../store/header";

jest.mock("../../../database/collections/likes", () => {});
jest.mock("../../../blocks/related-content");

jest.mock("../../../mixins/mixins.Shareable");
jest.mock("../../../mixins/mixins.Header");

jest.mock("../EntryList");
jest.mock("../Hero");

jest.mock("../../../store/header", () => ({
set: jest.fn(),
}));

jest.mock("../../../store", () => ({
nav: {
setLevel: jest.fn(),
setAction: jest.fn(),
},
}));

const defaultProps = {
dispatch: jest.fn(),
params: {
id: "1",
},
study: {
content: {
id: "1",
content: {
description: "<h1>study</h1>",
images: [],
},
},
},
};

beforeEach(() => {
reset();
startBuffering();
});

afterEach(() => {
reset();
});

const generateComponent = (additionalProps = {}) => {
const newProps = {
...defaultProps,
...additionalProps,
};

return <StudiesSingleWithoutData { ...newProps } />;
};

it("renders with no image", () => {
const tree = renderer.create(generateComponent());
expect(tree).toMatchSnapshot();
});

it("renders loading with no study", () => {
const tree = renderer.create(generateComponent({
study: {}
}));
expect(tree).toMatchSnapshot();
});

it("renders studies content", () => {
const tree = renderer.create(generateComponent({
study: {
content: {
id: "1",
content: {
description: "<h1>study</h1>",
images: [
{ fileLabel: "1:1", url: "http://test.com/1x1.jpg" },
],
},
},
}
}));

expect(tree).toMatchSnapshot();
});

it("dispatches store on mount", () => {
const mockDispatch = jest.fn();

navActions.setLevel = jest.fn();
navActions.setAction = jest.fn();
headerActions.set = jest.fn();

const wrapper = shallow(generateComponent({
dispatch: mockDispatch,
}));

expect(mockDispatch).toHaveBeenCalledTimes(3);
expect(navActions.setLevel).toHaveBeenCalledTimes(1);
expect(navActions.setLevel).toHaveBeenCalledWith("CONTENT");
expect(navActions.setAction).toHaveBeenCalledTimes(1);
expect(navActions.setAction.mock.calls[0][0]).toBe("CONTENT");
expect(headerActions.set).toHaveBeenCalledTimes(1);
});
Loading

0 comments on commit 58bfc03

Please sign in to comment.