import * as React from "react";
import { ThemeProvider } from "styled-components";
import { parseTheme } from "@ax/helpers";
import globalTheme from "@ax/themes/theme.json";
import { render, cleanup, screen } from "../../../../../config/jest/test-utils";
import { mock } from "jest-mock-extended";
import configureStore from "redux-mock-store";
import thunk from "redux-thunk";
import SummaryButton, { ISummaryButtonProps } from "@ax/components/Fields/SummaryButton";

afterEach(cleanup);

const middlewares: any = [thunk];
const mockStore = configureStore(middlewares);

const defaultProps = mock<ISummaryButtonProps>();

describe("Summary Button component rendering", () => {
	it("should render the component", () => {
		const initialStore = {
			app: { globalSettings: { autoSummary: true } },
		};
		const store = mockStore(initialStore);

		render(
			<ThemeProvider theme={parseTheme(globalTheme)}>
				<SummaryButton {...defaultProps} />
			</ThemeProvider>,
			{ store },
		);

		const summaryButtonWrapper = screen.getByTestId("summary-button-wrapper");

		expect(summaryButtonWrapper).toBeTruthy();
	});

	it("should not render the component", () => {
		const initialStore = {
			app: { globalSettings: { autoSummary: false } },
		};
		const store = mockStore(initialStore);

		render(
			<ThemeProvider theme={parseTheme(globalTheme)}>
				<SummaryButton {...defaultProps} />
			</ThemeProvider>,
			{ store },
		);

		const summaryButtonWrapper = screen.queryByTestId("summary-button-wrapper");

		expect(summaryButtonWrapper).toBeFalsy();
	});
});
