UNPKG

html-table-to-dataframe

Version:
277 lines (276 loc) 9.68 kB
import { TableData } from './types'; /** * toHaveTableRowCountGreaterThan expects a tableData as processed by toDataFrame. * The assertion checks that the total row count of the table is greater than the expected value. * * @example: * * | one | two | * | 1 | 3 | * | 2 | 100 | * * toHaveTableRowCountGreaterThan(dt, 3) will fail because the row count is 2. */ export declare const toHaveTableRowCountGreaterThan: (tableData: TableData, expectedLength: number) => void; /** * toHaveTableRowCountLessThan expects a tableData as processed by toDataFrame. * The assertion checks that the total row count of the table is less than than the expected value. * * @example: * * | one | two | * | 1 | 3 | * | 2 | 100 | * * toHaveTableRowCountLessThan(dt, 1) will fail because the row count is 2. */ export declare const toHaveTableRowCountLessThan: (tableData: TableData, expectedLength: number) => void; /** * toHaveTableRowCountEqualTo expects a tableData as processed by convertHTMLTable. * The assertion checks that the total row count of the table equal to the the expected value. * * Example: * * | one | two | * | 1 | 3 | * | 2 | 100 | * * toHaveTableRowCountEqualTo(dt, 3) will fail because the row count is 2. */ export declare const toHaveTableRowCountEqualTo: (tableData: TableData, expectedLength: number) => void; /** * toHaveColumnValuesToMatchRegex expects tableData as processed by convertHTMLTable. * The assertion will check that the values in the specified column match the given regular expression pattern. * * @example: * * | one | two | * | 1 | 3 | * | 2 | 100 | * * toHaveColumnValuesToMatchRegex(dt, "two", "\\d\\d") will fail because {"two":"100"} has 3 digits. * * "Write Once, Never Read" - Use sparingly, add expectations where RegExs can be replaced. */ export declare const toHaveColumnValuesToMatchRegex: (tableData: TableData, columnHeader: string, regexPattern: string) => void; /** * toHaveColumnsValuesToMatchRegex expects tableData as processed by convertHTMLTable. * The assertion will check each column that the values in the specified column match the * given regular expression pattern. * * @example: * * | one | two | * | 1 | 3 | * | 2 | 100 | * * toHaveColumnsValuesToMatchRegex(dt, ["one", "two"], "\\d\\d") will fail because {"two":"100"} has 3 digits. * * "Write Once, Never Read" - Use sparingly, add expectations where RegExs can be replaced. */ export declare const toHaveColumnsValuesToMatchRegex: (tableData: TableData, columnHeaders: string[], regexPattern: string) => void; /** * toHaveColumnValuesToBeInRange expects tableData as processed by convertHTMLTable. * The assertion checks that the values in the specified column fall within the given range. * * @example: * * | one | two | * | 1 | 3 | * | 2 | 100 | * * toHaveColumnValuesToBeInRange(dt, "two", 0, 4) will fail because {"two":"100"} is greater than 4. */ export declare const toHaveColumnValuesToBeInRange: (tableData: TableData, columnHeader: string, minValue: number, maxValue: number) => void; /** * toHaveColumnValuesToBeNumbers expects tableData as processed by convertHTMLTable. * The assertion will check that the values in the specified column are numbers. * * Example: * * | one | two | * | 1 | 3 | * | 2 | 1e | * * toHaveColumnValuesToBeNumbers(dt, "two") will fail because {"two":"1e"} is not a number. */ export declare const toHaveColumnValuesToBeNumbers: (tableData: TableData, columnHeader: string) => void; /** * toHaveColumnToMatchWhenFilteredBy expects tableData as processed by convertHTMLTable(). * This assertion checks whether a target column/value pair exists when filtered by a specified column/value. * It also does not validate the correctness of column names. * * @example: * | col_1 | col_2 | * | ------| ----- | * | 1 | 3 | * | 2 | 1e | * * toHaveColumnToMatchWhenFilteredBy(dt, "col_1", "2", "col_2", "xyz"); * * This will fail as {"col_1":"2"} is located; however, {"col_2":"xyz"} is not found. */ export declare const toHaveColumnToMatchWhenFilteredBy: (tableData: TableData, targetColumn: string, targetValue: string, filterColumn: string, filterValue: string) => void; /** * GroupType for usage with: * - toHaveColumnToMatchGroupWhenFilteredBy */ export type GroupType = { filterColumn: string; filterValue: string | undefined; }; /** * toHaveColumnToMatchGroupWhenFilteredBy uses an array of types GroupType * to cycle through and pass the items to toHaveColumnToMatchWhenFilteredBy. * * @example: * * | col_1 | col_2 | col_3 | * | ------| ----- | ----- | * | 1 | a | b | * * const group: GroupType[] = [ * { filterColumn: "col_2", filterValue: "a" }, * { filterColumn: "col_3", filterValue: "a" }, * ]; * * toHaveColumnToMatchGroupWhenFilteredBy(dt, "col_1", "1", group); * * This will fail as {"col_2": "a"} is OK; however, {"col_3": "a"} should be "b". */ export declare const toHaveColumnToMatchGroupWhenFilteredBy: (tableData: TableData, targetColumn: string, targetValue: string, filterGroup: GroupType[]) => void; /** * toHaveColumnToNotMatch expects a tableData generated by convertHTMLTable(). * This expectation confirms that a column no longer contains a match. This * expectation is designed around checking a row is no longer available. Such * as when a record has been deleted or archived. * * @example: * | col_1 | col_2 | * | ------| ----- | * | 1 | 3 | * | 2 | 1e | * * toHaveColumnToNotMatch(dt, "col_1", "2"); * * This will fail as {"col_1":"2"} is found and should not be. */ export declare const toHaveColumnToNotMatch: (tableData: TableData, targetColumn: string, targetValue: string) => void; /** * toHaveTableRowCount expects a tableData as processed by convertHTMLTable(). * The expectation will match the row count. * * @example: * | col_1 | col_2 | * | ------| ----- | * | 1 | 3 | * | 2 | 1e | * * toHaveTableRowCount(dt, 3); * * This will fail as row count should be 2. */ export declare const toHaveTableRowCount: (tableData: TableData, expectedLength: number) => void; /** * toHaveColumnToBeValue expects only 1 table row and * the column value should match the provided value. * * @example: * | col_1 | col_2 | * | ------| ----- | * | 1 | 3 | * * toHaveColumnToBeValue(dt, "col_2", "3"); * * This will fail as the column value should be 3. */ export declare const toHaveColumnToBeValue: (tableData: TableData, column: string, value: string) => void; /** * toHaveColumnGroupToBeValue expects only 1 table row and * the column value in a group should match the provided. * Exceptions are made when the filterValue is null/undefined. * * @example: * | col_1 | col_2 | * | ------| ----- | * | 1 | 3 | * * toHaveColumnGroupToBeValue(dt, [{ filterColumn: "col_2", filterValue: "3" }]); * * This will fail as the column value should be 3. */ export declare const toHaveColumnGroupToBeValue: (tableData: TableData, filterGroup: GroupType[]) => void; /** * toHaveColumnGroupToBeValues is the multiple grouped check, * using toHaveColumnGroupToBeValue for each row. Table Data * is the same and filterGroups is an array of groups. FilterGroups * and the TableData must be the same length. * * Example: * See toHaveColumnGroupToBeValue */ export declare const toHaveColumnGroupToBeValues: (tableData: TableData, filterGroups: GroupType[][]) => void; /** * toHaveTableToNotMatch will convert the tables key/values * into a string and compares the two for equality. * * @param tableData1 * @param tableData2 * * @example: * * table1: | col_1 | col_2 | table2: | col_1 | col_2 | * | ------| ----- | | ------| ----- | * | 1 | 3 | | 1 | 3 | * * toHaveTableToNotMatch(table1, table2); * * This will fail as the two tables are the same */ export declare const toHaveTableToNotMatch: (tableData1: TableData, tableData2: TableData) => void; /** * toHaveTableToMatch will convert the tables key/values * into a string and compares the two for equality. * * @param tableData1 * @param tableData2 * * @example: * * table1: | col_1 | col_2 | table2: | col_1 | col_2 | * | ------| ----- | | ------| ----- | * | 1 | 3 | | 1 | 4 | * * toHaveTableToMatch(table1, table2); * * This will fail as the two tables are different */ export declare const toHaveTableToMatch: (tableData1: TableData, tableData2: TableData) => void; /** * toHaveColumnValuesInSet * * Asserts that all values in a specified column of table data match a set of valid values. * Throws an error if the column header does not exist in a table row. * Throws an error if any value in the column is not in the provided set. * * @param tableData - Array of rows, each represented as an object with key-value pairs. * @param columnHeader - The column header to check. Must be a key in `tableData`. * @param targetSet - A Set of valid values for the column. * * @throws Error - If the column header is not in a `tableData` row. * @throws Error - If any value in the column is not in `targetSet`. * * @example * * | col_1 | col_2 | * | ------| ----- | * | 1 | 3 | * | 2 | 1e | * * const set: Set<string> = new Set(["1", "2", "3"]); * toHaveColumnValuesInSet(dataFrame, "col_2", set); * // Throws an error because "1e" is not in the set {"1", "2", "3"} */ export declare const toHaveColumnValuesInSet: (tableData: { [key: string]: string; }[], columnHeader: string, targetSet: Set<string>) => void;