more tests
parent
fdf2216931
commit
7c05c77b7d
|
@ -0,0 +1,44 @@
|
|||
jest.mock("fastclick", () => ({
|
||||
attach: jest.fn(),
|
||||
}));
|
||||
|
||||
import { auth } from "../__test_support__/fake_state/token";
|
||||
const mockAuth = auth;
|
||||
const mockClear = jest.fn();
|
||||
jest.mock("../session", () => ({
|
||||
Session: {
|
||||
fetchStoredToken: jest.fn(() => mockAuth)
|
||||
.mockImplementationOnce(() => { }),
|
||||
getNum: () => undefined,
|
||||
getBool: () => undefined,
|
||||
getAll: () => undefined,
|
||||
clear: mockClear
|
||||
}
|
||||
}));
|
||||
|
||||
import * as React from "react";
|
||||
import { shallow } from "enzyme";
|
||||
import { RootComponent } from "../routes";
|
||||
import { store } from "../redux/store";
|
||||
|
||||
describe("<RootComponent />", () => {
|
||||
beforeEach(function () {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("clears session when not authorized", () => {
|
||||
Object.defineProperty(location, "pathname", {
|
||||
value: "/app/account"
|
||||
});
|
||||
shallow(<RootComponent store={store} />);
|
||||
expect(mockClear).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("authorized", () => {
|
||||
Object.defineProperty(location, "pathname", {
|
||||
value: "/app/account"
|
||||
});
|
||||
shallow(<RootComponent store={store} />);
|
||||
expect(mockClear).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
|
@ -71,4 +71,11 @@ describe("<Logs />", () => {
|
|||
expect(wrapper.text()).toContain("Unknown");
|
||||
expect(wrapper.text()).toContain("0, 1, 2");
|
||||
});
|
||||
|
||||
it("shows verbosity", () => {
|
||||
const logs = fakeLogs();
|
||||
logs[0].body.meta.verbosity = 999;
|
||||
const wrapper = mount(<Logs logs={logs} bot={bot} />);
|
||||
expect(wrapper.text()).toContain(999);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,10 +1,34 @@
|
|||
import { buildResourceIndex } from "../../__test_support__/resource_index_builder";
|
||||
import { findSlotByToolId, getFeeds, selectAllLogs } from "../selectors";
|
||||
import {
|
||||
findSlotByToolId,
|
||||
getFeeds,
|
||||
selectAllLogs,
|
||||
findResourceById,
|
||||
isKind,
|
||||
groupPointsByType,
|
||||
findPointerByTypeAndId,
|
||||
findToolSlot,
|
||||
findPlant,
|
||||
selectCurrentToolSlot,
|
||||
getSequenceByUUID,
|
||||
toArray,
|
||||
findAllById,
|
||||
toolsInUse,
|
||||
hasId,
|
||||
findFarmEventById,
|
||||
maybeFindToolById,
|
||||
findToolById,
|
||||
findSequenceById,
|
||||
findRegimenById,
|
||||
maybeFindPlantById
|
||||
} from "../selectors";
|
||||
import { resourceReducer, emptyState } from "../reducer";
|
||||
import { TaggedTool, TaggedToolSlotPointer, SpecialStatus } from "../tagged_resources";
|
||||
import { createOK } from "../actions";
|
||||
import { generateUuid } from "../util";
|
||||
import { fakeWebcamFeed } from "../../__test_support__/fake_state/resources";
|
||||
import {
|
||||
fakeWebcamFeed, fakeSequence
|
||||
} from "../../__test_support__/fake_state/resources";
|
||||
import { Actions } from "../../constants";
|
||||
import * as _ from "lodash";
|
||||
|
||||
|
@ -35,6 +59,7 @@ const fakeSlot: TaggedToolSlotPointer = {
|
|||
meta: {}
|
||||
}
|
||||
};
|
||||
const fakeIndex = buildResourceIndex().index;
|
||||
|
||||
describe("findSlotByToolId", () => {
|
||||
it("returns undefined when not found", () => {
|
||||
|
@ -74,10 +99,152 @@ describe("getFeeds", () => {
|
|||
|
||||
describe("selectAllLogs", () => {
|
||||
it("stays truthful to its name by finding all logs", () => {
|
||||
const results = selectAllLogs(buildResourceIndex().index);
|
||||
const results = selectAllLogs(fakeIndex);
|
||||
expect(results.length).toBeGreaterThan(0);
|
||||
const kinds = _(results).map("kind").uniq().value();
|
||||
expect(kinds.length).toEqual(1);
|
||||
expect(kinds[0]).toEqual("Log");
|
||||
});
|
||||
});
|
||||
|
||||
describe("findResourceById()", () => {
|
||||
it("returns UUID", () => {
|
||||
const uuid = findResourceById(fakeIndex, "Sequence", 23);
|
||||
expect(uuid).toContain("Sequence.23");
|
||||
});
|
||||
|
||||
it("throws error", () => {
|
||||
const findUuid = () =>
|
||||
findResourceById(fakeIndex, "Sequence", NaN);
|
||||
expect(findUuid).toThrow("UUID not found for id NaN");
|
||||
});
|
||||
});
|
||||
|
||||
describe("isKind()", () => {
|
||||
it("is", () => {
|
||||
const ret = isKind("Sequence")(fakeSequence());
|
||||
expect(ret).toBeTruthy();
|
||||
});
|
||||
|
||||
it("isn't", () => {
|
||||
const ret = isKind("Tool")(fakeSequence());
|
||||
expect(ret).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("groupPointsByType()", () => {
|
||||
it("returns points", () => {
|
||||
const points = groupPointsByType(fakeIndex);
|
||||
const expectedKeys = ["Plant", "GenericPointer", "ToolSlot"];
|
||||
expect(expectedKeys.every(key => key in points)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("findPointerByTypeAndId()", () => {
|
||||
it("throws error", () => {
|
||||
const find = () => findPointerByTypeAndId(fakeIndex, "Other", 0);
|
||||
expect(find).toThrow("Tried to fetch bad point Other 0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("findToolSlot()", () => {
|
||||
it("throws error", () => {
|
||||
const find = () => findToolSlot(fakeIndex, "bad");
|
||||
expect(find).toThrow("ToolSlotPointer not found: bad");
|
||||
});
|
||||
});
|
||||
|
||||
describe("findPlant()", () => {
|
||||
it("throws error", () => {
|
||||
console.warn = jest.fn();
|
||||
const find = () => findPlant(fakeIndex, "bad");
|
||||
expect(find).toThrowError();
|
||||
expect(console.warn).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("selectCurrentToolSlot()", () => {
|
||||
it("throws error", () => {
|
||||
const find = () => selectCurrentToolSlot(fakeIndex, "bad");
|
||||
expect(find).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSequenceByUUID()", () => {
|
||||
it("throws error", () => {
|
||||
console.warn = jest.fn();
|
||||
const find = () => getSequenceByUUID(fakeIndex, "bad");
|
||||
expect(find).toThrow("BAD Sequence UUID");
|
||||
expect(console.warn).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("toArray()", () => {
|
||||
it("returns array", () => {
|
||||
const array = toArray(fakeIndex);
|
||||
expect(array.length).toEqual(fakeIndex.all.length);
|
||||
});
|
||||
});
|
||||
|
||||
describe("findAllById()", () => {
|
||||
it("returns", () => {
|
||||
const result = findAllById(fakeIndex, [23], "Sequence");
|
||||
expect(result.length).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("toolsInUse()", () => {
|
||||
it("returns tools", () => {
|
||||
const activeTools = toolsInUse(fakeIndex);
|
||||
expect(activeTools.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("hasId()", () => {
|
||||
it("has", () => {
|
||||
const result = hasId(fakeIndex, "Sequence", 23);
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("findFarmEventById()", () => {
|
||||
it("throws error", () => {
|
||||
const find = () => findFarmEventById(fakeIndex, 0);
|
||||
expect(find).toThrow("Bad farm_event id: 0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("maybeFindToolById()", () => {
|
||||
it("not found", () => {
|
||||
const result = maybeFindToolById(fakeIndex, 0);
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("findToolById()", () => {
|
||||
it("throws error", () => {
|
||||
const find = () => findToolById(fakeIndex, 0);
|
||||
expect(find).toThrow("Bad tool id: 0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("findSequenceById()", () => {
|
||||
it("throws error", () => {
|
||||
const find = () => findSequenceById(fakeIndex, 0);
|
||||
expect(find).toThrow("Bad sequence id: 0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("findRegimenById()", () => {
|
||||
it("throws error", () => {
|
||||
const find = () => findRegimenById(fakeIndex, 0);
|
||||
expect(find).toThrow("Bad regimen id: 0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("maybeFindPlantById()", () => {
|
||||
it("not found", () => {
|
||||
const result = maybeFindPlantById(fakeIndex, 0);
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue