import React, { Component } from "react";
import { Provider } from "react-redux";
import { injectIntl } from "react-intl";
import "@testing-library/jest-dom";
import { render, getByText, screen } from "../../../utils/test-utils";
import { configureStore }  from '@capillarytech/vulcan-react-sdk/utils'
import { initialReducer } from '../../../initialReducer';
import Ckeditor from "../index";
import  history  from 'utils/history';



jest.mock('../../../v2Containers/TagList/index.js', () => ({
  __esModule: true,
  default: (props) => (
    <div className="tag-mock" {...props}>
      TagList
    </div>
  ),
}));

let store;
beforeAll(() => {
  store = configureStore({},initialReducer, history);
});
const initializeComponent = () => {
  const Component = injectIntl(Ckeditor);

  Ckeditor.prototype.componentDidMount = jest.fn();
  Ckeditor.prototype.handleContentChange = jest.fn();

  return render(
    <Provider store={store}>
      <Component />
    </Provider>
  );
};

describe("Load Ckeditor", () => {
  it("Test if Ckeditor Mounts", () => {
    initializeComponent();

    expect(Ckeditor.prototype.componentDidMount).toHaveBeenCalled();
  });

  it("Test if Ckeditor un-Mounts", () => {
    // Spy on the componentWillUnmount method
    const componentWillUnmountSpy = jest.spyOn(
      Ckeditor.prototype,
      "componentWillUnmount"
    );

    // Render the component
    const { unmount } = initializeComponent();

    // Manually unmount the component (simulate unmounting)
    unmount();

    // Assert that componentWillUnmount has been called
    expect(componentWillUnmountSpy).toHaveBeenCalled();

    // Clean up the spy
    componentWillUnmountSpy.mockRestore();
  });
});
