Hello, redux-doctitle!

This commit is contained in:
2018-01-18 17:53:52 +01:00
commit 64c18f7eba
17 changed files with 560 additions and 0 deletions

2
tests/__entry__.js Normal file
View File

@@ -0,0 +1,2 @@
let testsContext = require.context(".", true, /\.spec\.js$/);
testsContext.keys().forEach(testsContext);

18
tests/actions.spec.js Normal file
View File

@@ -0,0 +1,18 @@
import {TITLE_ACTIONS_SET} from "src/defs";
import * as doctitleActions from "src/actions";
describe("actions", () => {
describe("setDocumentTitle", () => {
it("should create the action", () => {
let result = doctitleActions.setDocumentTitle("Spam");
expect(result.type).toEqual(TITLE_ACTIONS_SET);
expect(result.title).toEqual("Spam");
});
it("should create the action without the custom part", () => {
let result = doctitleActions.setDocumentTitle();
expect(result.type).toEqual(TITLE_ACTIONS_SET);
expect(result.title).toEqual("");
});
});
});

77
tests/middleware.spec.js Normal file
View File

@@ -0,0 +1,77 @@
import {TITLE_ACTIONS_SET} from "src/defs";
import * as doctitleMiddleware from "src/middleware";
describe("middleware", () => {
describe("documentTitleMiddleware", () => {
let origTitle = null;
let next = null;
beforeAll(() => {
origTitle = window.document.title;
});
beforeEach(() => {
next = jasmine.createSpy("next");
});
afterAll(() => {
window.document.title = origTitle;
});
it("should set title to empty if no default parts are specified and custom part is empty", () => {
let middleware = doctitleMiddleware.documentTitleMiddlewareFactory()(
undefined, undefined
);
let action = {type: TITLE_ACTIONS_SET, title: undefined};
middleware(next)(action);
expect(window.document.title).toEqual("");
});
it("should not set custom document title if it isn't specified", () => {
let middleware = doctitleMiddleware.documentTitleMiddlewareFactory(["Test"])(
undefined, undefined
);
let action = {type: TITLE_ACTIONS_SET, title: undefined};
middleware(next)(action);
expect(window.document.title).toEqual("Test");
});
it("should set custom document title", () => {
let middleware = doctitleMiddleware.documentTitleMiddlewareFactory(["Test"])(
undefined, undefined
);
let action = {type: TITLE_ACTIONS_SET, title: "Spam"};
middleware(next)(action);
expect(window.document.title).toEqual("Spam | Test");
});
it("should not call the next middleware if got the setDocumentTitle action", () => {
let middleware = doctitleMiddleware.documentTitleMiddlewareFactory(["Test"])(
undefined, undefined
);
let action = {type: TITLE_ACTIONS_SET, title: "Spam"};
middleware(next)(action);
expect(next).not.toHaveBeenCalled();
});
it("should call the next middleware if didn't get the setDocumentTitle action", () => {
let middleware = doctitleMiddleware.documentTitleMiddlewareFactory(["Test"])(
undefined, undefined
);
let action = {type: "SPAM"};
middleware(next)(action);
expect(next).toHaveBeenCalledWith(action);
});
});
});