Merge branch 'next' into timestamp

This commit is contained in:
Wyatt Johnson
2018-07-13 17:11:05 +00:00
committed by GitHub
8 changed files with 121 additions and 51 deletions
+5
View File
@@ -0,0 +1,5 @@
import Enzyme from "enzyme";
import Adapter from "enzyme-adapter-react-16";
// React 16 Enzyme adapter
Enzyme.configure({ adapter: new Adapter() });
+27
View File
@@ -0,0 +1,27 @@
import { JSDOM } from "jsdom";
declare var global: any;
const jsdom = new JSDOM("<!doctype html><html><body></body></html>");
const { window } = jsdom;
function copyProps(src: any, target: any) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === "undefined")
.reduce(
(result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(src, prop),
}),
{}
);
Object.defineProperties(target, props);
}
global.window = window;
global.document = (window as any).document;
global.navigator = {
userAgent: "node.js",
};
copyProps(window, global);
+24
View File
@@ -0,0 +1,24 @@
import "./enzyme";
import "./jsdom";
// TODO: Remove when fixed.
// Mock React.createContext because of https://github.com/airbnb/enzyme/issues/1509.
function mockReact() {
const originalReact = require.requireActual("react");
return {
...originalReact,
createContext: jest.fn(defaultValue => {
let value = defaultValue;
const Provider = (props: any) => {
value = props.value;
return props.children;
};
const Consumer = (props: any) => props.children(value);
return {
Provider,
Consumer,
};
}),
};
}
jest.mock("react", () => mockReact());
+59
View File
@@ -0,0 +1,59 @@
import { getPageInfo } from "./connection";
it("handles when there is none requested", () => {
const pageInfo = getPageInfo({ first: 0 }, []);
expect(pageInfo).toEqual({
hasNextPage: false,
hasPreviousPage: false,
startCursor: null,
endCursor: null,
});
});
it("handles when there is no edges", () => {
const pageInfo = getPageInfo({ first: 10 }, []);
expect(pageInfo).toEqual({
hasNextPage: false,
hasPreviousPage: false,
startCursor: null,
endCursor: null,
});
});
it("handles when there is more edges than requested", () => {
const pageInfo = getPageInfo({ first: 1 }, [
{
node: null,
cursor: 1,
},
{
node: null,
cursor: 2,
},
]);
expect(pageInfo).toEqual({
hasNextPage: true,
hasPreviousPage: false,
startCursor: null,
endCursor: 1,
});
});
it("handles when there is exactly as many edges as requested", () => {
const pageInfo = getPageInfo({ first: 1 }, [
{
node: null,
cursor: 1,
},
]);
expect(pageInfo).toEqual({
hasNextPage: false,
hasPreviousPage: false,
startCursor: null,
endCursor: 1,
});
});