/* 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 type { EventsKey } from 'ol/events';
import Interaction from 'ol/interaction/Interaction';
import Map from 'ol/Map';
import { InteractionMode } from './interaction-mode';

class MockInteractionMode extends InteractionMode {}

class TestMode extends InteractionMode {
  listener: EventsKey = <EventsKey>{};
  interaction: Interaction = <Interaction>{};

  activate() {
    super.activate();
    this.registerListener(this.listener);
    this.activateInteraction(this.interaction);
  }

  deactivate() {
    super.deactivate();
  }
}

describe('InteractionMode', () => {
  let mode: TestMode;
  let map: Map;

  beforeEach(() => {
    map = <any>(<Partial<Map>>{
      addInteraction: jest.fn(),
      removeInteraction: jest.fn(),
    });
    mode = new TestMode();
  });

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

  it('should handle activated interactions', () => {
    mode.setMap(map);
    mode.activate();
    expect(map.addInteraction).toHaveBeenCalledTimes(1);
    mode.deactivate();
    expect(map.removeInteraction).toHaveBeenCalledTimes(1);
  });

  it('should be able to incorporate other modes', () => {
    const incorporatedMode = new MockInteractionMode();
    jest.spyOn(incorporatedMode, 'deactivate').mockImplementation(() => {});
    jest.spyOn(incorporatedMode, 'activate').mockImplementation(() => {});
    jest.spyOn(incorporatedMode, 'setMap').mockImplementation(() => {});
    mode.extends(incorporatedMode);

    mode.setMap(map);
    expect(incorporatedMode.setMap).toHaveBeenCalledTimes(1);

    mode.activate();
    expect(incorporatedMode.activate).toHaveBeenCalledTimes(1);

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