import { configure } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import 'jest-enzyme';

configure({ adapter: new Adapter() });

global.localStorage = {
  getItem: jest.fn(),
  setItem: jest.fn(),
  removeItem: jest.fn(),
  clear: jest.fn(),
};

const fakeClass = class {
  constructor(...args) {
    this.calledWith = args;
    this.listeners = new Map();
  }

  addListener = (name, fn) => {
    const list = this.listeners.get(name) ?? [];
    list.push(fn);
    this.listeners.set(name, list);
  }
}

global.google = {
  maps: {
    Geocoder: class extends fakeClass {
      geocode = jest.fn();
    },
    Polyline: fakeClass,
    Marker: fakeClass,
    Point: fakeClass,
  },
};

jest.useFakeTimers();

window.open = jest.fn();