<commit_before>import DataTableRow, { DataTableRuleRow } from "../row";
import "jest";
import "./setup";
import { expect } from "chai";
import * as React from "react";

import { shouldntThrowWithProps, testEnvironment } from "./assertions";
import { categorizedAndLabeledEmployeeProps, categorizedEmployeeProps } from "../data/category.props";
import { mount } from "enzyme";
import DataTable, { IDataTableCategoryProps, IDataTableProps } from "../";
import { DataTableCategorySection } from "../body";
import { ObjectOmit } from "typelevel-ts";

testEnvironment();

type EnforcedCategoryProps<T extends object = object> = (
	ObjectOmit<IDataTableProps<T>, keyof IDataTableCategoryProps<T>> & IDataTableCategoryProps<T>
);

function testTableForCategoriesBehaviour<T extends object = object>(props: EnforcedCategoryProps<T>) {
	shouldntThrowWithProps(props, DataTable);

	const wrapper = mount<EnforcedCategoryProps<T>>(<DataTable {...props}/>);
	const uniqueCategories = [...new Set(props.data.map(props.categoryAccessor))];

	it("should have as many categories as category sections", () => {
		expect(
			wrapper.find("tbody").find(DataTableCategorySection).length,
		).to.be.equal(uniqueCategories.length);
	});

	it("every regular row inside a category section should have its category", () => {
		expect(
			wrapper.find("tbody").find(DataTableCategorySection).everyWhere(
				(section) => {
					const sectionCategory = section.props().category;
					return section.find(DataTableRow).everyWhere(
						(row) => {
							const datum = row.props().datum;
							const rowCategory = wrapper.props().categoryAccessor(datum);
							return rowCategory === sectionCategory;
						},
					);
				},
			),
		).to.be.true;
	});

	it("every category section should start with a rule row", () => {
		expect(wrapper.find("tbody").find(DataTableCategorySection).everyWhere(
			(section) => section.childAt(0).is(DataTableRuleRow),
		)).to.be.true;
	});

	it("should repass label to rule rows", () => {
		expect(
			wrapper.find(DataTableRuleRow).everyWhere(
				(ruleRow) => ruleRow.props().label === wrapper.props().categoryLabel,
			),
		).to.be.true;
	});
}

describe("the main component with categories' enabled", () => {
	testTableForCategoriesBehaviour(categorizedEmployeeProps);
	testTableForCategoriesBehaviour(categorizedAndLabeledEmployeeProps);
});<commit_msg>More category feature tests<commit_after>import DataTableRow, { DataTableRuleRow } from "../row";
import "jest";
import "./setup";
import { expect } from "chai";
import * as React from "react";

import { shouldntThrowWithProps, testEnvironment } from "./assertions";
import { categorizedAndLabeledEmployeeProps, categorizedEmployeeProps } from "../data/category.props";
import { mount } from "enzyme";
import DataTable, { IDataTableCategoryProps, IDataTableProps } from "../";
import { DataTableCategorySection } from "../body";
import { ObjectOmit } from "typelevel-ts";

testEnvironment();

type EnforcedCategoryProps<T extends object = object> = (
	ObjectOmit<IDataTableProps<T>, keyof IDataTableCategoryProps<T>> & IDataTableCategoryProps<T>
);

function testTableForCategoriesBehaviour<T extends object = object>(props: EnforcedCategoryProps<T>) {
	shouldntThrowWithProps(props, DataTable);

	const wrapper = mount<EnforcedCategoryProps<T>>(<DataTable {...props}/>);
	const uniqueCategories = [...new Set(props.data.map(props.categoryAccessor))];

	it("should have as many categories as category sections", () => {
		expect(
			wrapper.find("tbody").find(DataTableCategorySection).length,
		).to.be.equal(uniqueCategories.length);
	});

	it("every regular row inside a category section should have its category", () => {
		expect(
			wrapper.find("tbody").find(DataTableCategorySection).everyWhere(
				(section) => {
					const sectionCategory = section.props().category;
					return section.find(DataTableRow).everyWhere(
						(row) => {
							const datum = row.props().datum;
							const rowCategory = wrapper.props().categoryAccessor(datum);
							return rowCategory === sectionCategory;
						},
					);
				},
			),
		).to.be.true;
	});

	it("every category section should start with a rule row", () => {
		expect(wrapper.find("tbody").find(DataTableCategorySection).everyWhere(
			(section) => section.childAt(0).is(DataTableRuleRow),
		)).to.be.true;
	});

	it("every category section should have only one rule row", () => {
		expect(wrapper.find("tbody").find(DataTableCategorySection).everyWhere(
			(section) => section.find(DataTableRuleRow).length === 1,
		)).to.be.true;
	});

	it("should repass right category to each rule row", () => {
		expect(
			wrapper.find(DataTableCategorySection).everyWhere((section) => {
				return section.find(DataTableRuleRow).props().content === section.props().category;
			}),
		).to.be.true;
	});

	it("should repass label to rule rows", () => {
		expect(
			wrapper.find(DataTableRuleRow).everyWhere(
				(ruleRow) => ruleRow.props().label === wrapper.props().categoryLabel,
			),
		).to.be.true;
	});
}

describe("the main component with categories' enabled", () => {
	testTableForCategoriesBehaviour(categorizedEmployeeProps);
	testTableForCategoriesBehaviour(categorizedAndLabeledEmployeeProps);
});
{'fraction_non_alphanumeric': 0.14944508228090317, 'fraction_numerical': 0.000574052812858783, 'mean_word_length': 4.960091220068415, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3683771', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1499, 'n_words': 321}