/**
 * @jest-environment jsdom
 */
import CfCore from "../../core/CfCore";
import Navigation from "../Navigation";
import {
  NavigationTypes,
  SearchProperties,
} from "../../modules/Navigation/typings";

let windowSpy;
let mockDeferredRunner;

class MockImpressionsDetector {
  start() {}
  stop() {}
  restart() {}
}

describe("Navigation", () => {
  beforeEach(() => {
    mockDeferredRunner = {
      activate() {},
      execute() {},
    };
    windowSpy = jest.spyOn(window, "window", "get");
  });

  afterEach(() => {
    // to remove the singleton instance
    (CfCore as any).instance = null;
  });

  describe("[Loader] Navigation", () => {
    it('Should deliver a "Search" event with the same ID', async () => {
      Navigation.init(mockDeferredRunner);

      const firstID = Navigation.logIngestEvent(
        NavigationTypes.Search,
        {} as SearchProperties,
        true
      );
      const secondID = Navigation.logIngestEvent(
        NavigationTypes.Search,
        {} as SearchProperties,
        false
      );

      expect(firstID).toEqual(secondID);
    });

    it('Should deliver a "Search" event with different ID', async () => {
      Navigation.init(mockDeferredRunner);

      const firstID = Navigation.logIngestEvent(
        NavigationTypes.Search,
        {} as SearchProperties,
        true
      );
      const secondID = Navigation.logIngestEvent(
        NavigationTypes.Search,
        {} as SearchProperties,
        true
      );

      expect(firstID).not.toEqual(secondID);
    });
  });
});
