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); }); }); });