import WsMultipleInputController from './ws-multiple-input.controller';

describe('WsMultipleInputController', () => {
  let controller;

  let mockWindow;
  let mockTimeout;

  beforeEach(() => {
    mockWindow = {
      navigator: { userAgent: 'desktop' },
    };
    mockTimeout = func => new Promise(resolve => resolve()).then(func);

    controller = new WsMultipleInputController(mockWindow, mockTimeout);
    controller.$onInit();
    controller.onCompleted = () => true;
    controller.isReadonly = false;
  });

  it('should call onCompleted when all elements are populated', async () => {
    controller.inputCount = 3;
    controller.inputs = ['1', '2', '3'];

    spyOn(controller, 'onCompleted');

    await controller.onKeyPress({ target: { value: '3', maxLength: 1 } });
    expect(controller.onCompleted).toHaveBeenCalledWith({ result: '123' });
  });
});
