import * as React from "react";

import { ThemeProvider } from "styled-components";
import { render, cleanup } from "@testing-library/react";
import { parseTheme } from "@ax/helpers";
import "@testing-library/jest-dom";

import Flag, { IStateProps } from "@ax/components/Flag";
import globalTheme from "@ax/themes/theme.json";

afterEach(cleanup);

describe("Flag component rendering", () => {
	it("should render the component", () => {
		const defaultProps: IStateProps = {
			name: "es",
			size: "20",
		};

		const { container } = render(
			<ThemeProvider theme={parseTheme(globalTheme)}>
				<Flag {...defaultProps} />
			</ThemeProvider>,
		);

		const svgFlag = container.querySelector("svg");
		expect(svgFlag).toBeTruthy();
	});

	it("should render the component with the lang passed", () => {
		const defaultProps: IStateProps = {
			name: "It_IT",
			size: "20",
		};

		const { container } = render(
			<ThemeProvider theme={parseTheme(globalTheme)}>
				<Flag {...defaultProps} />
			</ThemeProvider>,
		);

		const svgFlag = container.querySelector("svg");
		expect(svgFlag).toBeTruthy();
	});

	it("should return null if the lang doesn't exists", () => {
		const defaultProps: IStateProps = {
			name: "err",
		};

		const { container } = render(
			<ThemeProvider theme={parseTheme(globalTheme)}>
				<Flag {...defaultProps} />
			</ThemeProvider>,
		);

		const svgFlag = container.querySelector("svg");
		expect(svgFlag).not.toBeTruthy();
	});
});
