/* eslint-disable @typescript-eslint/no-empty-function */
/*
 * Copyright (C) 2018 Robert Bosch GmbH Copyright (C) 2018 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import Map from 'ol/Map';
import { InteractionsManager } from './interaction-manager';
import { InteractionMode } from './interaction-mode';

class MockInteractionMode extends InteractionMode {}

describe('InteractionsManager', () => {
  let manager: InteractionsManager;
  let map: Map;

  beforeEach(() => {
    map = <Map>{};
    manager = new InteractionsManager(map);
  });

  it('should be created', () => {
    expect(manager).toBeTruthy();
  });

  it('should replace mode', () => {
    const oldMode = new MockInteractionMode();
    jest.spyOn(oldMode, 'deactivate').mockImplementation(() => {});
    manager.switchMode(oldMode);
    expect(oldMode.deactivate).not.toHaveBeenCalledTimes(1);
    const newMode = new MockInteractionMode();
    jest.spyOn(newMode, 'deactivate').mockImplementation(() => {});
    jest.spyOn(newMode, 'activate').mockImplementation(() => {});
    jest.spyOn(newMode, 'setMap').mockImplementation(() => {});

    manager.switchMode(newMode);

    expect(newMode.setMap).toHaveBeenCalledTimes(1);
    expect(newMode.activate).toHaveBeenCalledTimes(1);
    expect(newMode.deactivate).not.toHaveBeenCalledTimes(1);
    expect(oldMode.deactivate).toHaveBeenCalledTimes(1);
  });

  it('should deactivate old mode without new mode', () => {
    const oldMode = new MockInteractionMode();
    jest.spyOn(oldMode, 'deactivate').mockImplementation(() => {});
    manager.switchMode(oldMode);
    expect(oldMode.deactivate).not.toHaveBeenCalled();

    manager.switchMode();

    expect(oldMode.deactivate).toHaveBeenCalledTimes(1);
  });

  it('should deactive interaction mode when destroyed', () => {
    const mode = new MockInteractionMode();
    jest.spyOn(mode, 'deactivate').mockImplementation(() => {});
    manager.switchMode(mode);

    manager.destroy();

    expect(mode.deactivate).toHaveBeenCalledTimes(1);
  });
});
