var elmRouter = require('../../src/elm-router');

var mockElm = {};
var mockPorts = [];
var mockTestPort = {};
var mockInstantiatedWorkers = {};

function mockInstantiatedApp(cmdPorts, subPorts) {
  const app = {ports: {}};

  cmdPorts.forEach(port => {
    app.ports[port] = {subscribe: jest.fn()}
  });

  subPorts.forEach(port => {
    app.ports[port] = {send: jest.fn()}
  });

  return app;
}

function mockWorker(name, cmdPorts, subPorts) {
  mockInstantiatedWorkers[name] = mockInstantiatedApp(cmdPorts, subPorts);

  mockElm[name] = {
    App: {
      worker: jest.fn(() => mockInstantiatedWorkers[name])
    }
  };
}

function port(portName) {
  return mockInstantiatedWorkers.ElmRouter.ports[portName].subscribe.mock.calls[0][0];
}

function testCmd() {
  console.log('testCmd ran');
}

describe('elm-router', () => {
  beforeEach(() => {
    mockTestPort = {
      register: ports => {
        ports.testCmd.subscribe(testCmd);
      },
      samplePortName: 'testCmd'
    };

    mockInstantiatedWorkers = {};
    mockPorts = [
      mockTestPort
    ];

    mockWorker('ElmRouter', [
      'routerWorker',
      'routerEmbed',
      'routerLog',
      'routerBroadcastUrlUpdate'
    ], [
      'routerReceiveCmd'
    ]);

    mockWorker('TestWorker', ['testCmd'], ['testSub']);

    elmRouter.start(mockElm, mockPorts);
  });

  describe('start', () => {
    test('launches the ElmRouter app', () => {
      expect(mockElm.ElmRouter.App.worker).toHaveBeenCalledWith(undefined); // Called with no flags
    });
  });

  describe('routerWorker', () => {
    beforeEach(() => {
      port('routerWorker')(['TestWorker']);
    });

    test('launches a worker if the given app exists', () => {
      expect(mockElm.TestWorker.App.worker).toHaveBeenCalledWith(undefined); // Called with no flags
    });

    test('registers ports for the worker', () => {
      expect(mockInstantiatedWorkers.TestWorker.ports.testCmd.subscribe).toHaveBeenCalledWith(testCmd);
    });
  });
});

@@ -1964,23 +1964,882 @@
 md);%0A    %7D);
+%0A%0A    test('throws an Error if %60register%60 was not defined', () =%3E %7B%0A%0A    %7D);%0A%0A    test('throws an Error if %60samplePortName%60 was not defined', () =%3E %7B%0A%0A    %7D);%0A  %7D);%0A%0A  describe('routerEmbed', () =%3E %7B%0A    test('embeds an Html app if it exists', () =%3E %7B%0A%0A    %7D);%0A%0A    test('registers ports for the embedded app', () =%3E %7B%0A%0A    %7D);%0A%0A    test('throws an Error if %60register%60 was not defined', () =%3E %7B%0A%0A    %7D);%0A%0A    test('throws an Error if %60samplePortName%60 was not defined', () =%3E %7B%0A%0A    %7D);%0A%0A    test('throws an Error if a DOM node is not found matching the selector', () =%3E %7B%0A%0A    %7D);%0A  %7D);%0A%0A  describe('routerBroadcastUrlUpdate', () =%3E %7B%0A    test('send an urlUpdate port message to all live Elm apps with %60urlUpdate%60', () =%3E %7B%0A%0A    %7D);%0A%0A    test('defaults %60username%60, %60password%60, and %60origin%60 to an empty string if undefined/falsy (IE10 issue)', () =%3E %7B%0A%0A    %7D);
 %0A  %7D);%0A%7D);%0A

Write empty test cases for remaining JavaScript