import "@testing-library/jest-dom";

import { parseTheme } from "@ax/helpers";
import type { IBulkHeaderProps } from "@ax/modules/Sites/SitesList/ListView/BulkHeader";
import BulkHeader from "@ax/modules/Sites/SitesList/ListView/BulkHeader";
import globalTheme from "@ax/themes/theme.json";

import { act, cleanup, screen } from "@testing-library/react";
import { mock } from "jest-mock-extended";
import configureStore from "redux-mock-store";
import thunk from "redux-thunk";
import { ThemeProvider } from "styled-components";

import { render } from "../../../../../../../config/jest/test-utils";
import { defaultStore } from "./../../../../../../__mocks__/store/GenericStore";

afterEach(cleanup);

const store = configureStore([thunk])(defaultStore);
const defaultProps = mock<IBulkHeaderProps>();

describe("BulkHeader component rendering", () => {
	it("should render table header", async () => {
		defaultProps.showBulk = false;
		defaultProps.checkState = { isAllSelected: false, indeterminate: false };
		defaultProps.filterValues = {
			order: [{ value: "lastAccess-desc", label: "lastAccess-desc" }],
			liveStatus: [{ value: "all", label: "All" }],
		};
		defaultProps.sortedListStatus = {
			isAscending: false,
			sortedByTitle: false,
			sortedByLastAccess: true,
			sortedByDateCreated: false,
		};
		defaultProps.totalItems = 22;

		await act(async () => {
			render(
				<ThemeProvider theme={parseTheme(globalTheme)}>
					<BulkHeader {...defaultProps} />
				</ThemeProvider>,
				{ store },
			);
		});

		expect(screen.getByTestId("sites-table-header")).toBeTruthy();
	});

	it("should render bulk header", async () => {
		defaultProps.showBulk = true;

		await act(async () => {
			render(
				<ThemeProvider theme={parseTheme(globalTheme)}>
					<BulkHeader {...defaultProps} />
				</ThemeProvider>,
				{ store },
			);
		});

		expect(screen.getByTestId("sites-list-bulk-wrapper")).toBeTruthy();
	});
});
