import { getOriginalRowIndex, selectRowIndex, selectRowIndices, } from "./utilities"; describe("getOriginalRowIndex", () => { it("With no previous data ", () => { const oldTableData = [ { step: "#1", task: " a fetch_users wih the Mock DB", status: "--", }, { step: "#2", task: " a fetch_users wih the Mock DB", status: "--", }, { step: "#3", task: "Bind the query => fetch_users.data", status: "--", }, ]; const newTableData: Record[] = []; const selectedRowIndex = 1; const result = getOriginalRowIndex( oldTableData, newTableData, selectedRowIndex, ); const expected = undefined; expect(result).toStrictEqual(expected); }); it("With no new data", () => { const oldTableData: Record[] = []; const newTableData = [ { step: "#1", task: " a fetch_users wih the Mock DB", status: "--", }, { step: "#2", task: " a fetch_users wih the Mock DB", status: "--", }, { step: "#3", task: "Bind the query => fetch_users.data", status: "--", }, ]; const selectedRowIndex = 1; const result = getOriginalRowIndex( oldTableData, newTableData, selectedRowIndex, ); const expected = undefined; expect(result).toStrictEqual(expected); }); it("With no selectedRowIndex", () => { const oldTableData = [ { step: "#1", task: "fetch_users with the Mock DB", status: "--", __originalIndex__: 0, __primaryKey__: "1", }, { step: "#2", task: "fetch_users with the Mock DB", status: "--", __originalIndex__: 1, __primaryKey__: "", }, { step: "#3", task: "Bind the query => fetch_users.data", status: "--", __originalIndex__: 2, __primaryKey__: "2", }, ]; const newTableData = [ { step: "#1", task: " a fetch_users with the Mock DB", status: "--", __originalIndex__: 0, __primaryKey__: "1", }, { step: "#2", task: "fetch_users with the Mock DB", status: "--", __originalIndex__: 1, __primaryKey__: "", }, { step: "#3", task: "Bind the query => fetch_users.data", status: "--", __originalIndex__: 2, __primaryKey__: "2", }, ]; const result = getOriginalRowIndex(oldTableData, newTableData, undefined); const expected = undefined; expect(result).toStrictEqual(expected); }); it("With no data", () => { const oldTableData = undefined; const newTableData = undefined; const selectedRowIndex = 1; const result = getOriginalRowIndex( (oldTableData as any) as Array>, (newTableData as any) as Array>, selectedRowIndex, ); const expected = undefined; expect(result).toStrictEqual(expected); }); }); describe("selectRowIndex", () => { it("With new Data", () => { const oldTableData = [ { step: "#1", task: "fetch_users with the Mock DB", status: "--", __originalIndex__: 0, __primaryKey__: "1", }, { step: "#2", task: "fetch_users with the Mock DB", status: "--", __originalIndex__: 1, __primaryKey__: "", }, { step: "#3", task: "Bind the query => fetch_users.data", status: "--", __originalIndex__: 2, __primaryKey__: "2", }, ]; const newTableData = [ { step: "#1", task: " a fetch_users with the Mock DB", status: "--", __originalIndex__: 0, __primaryKey__: "1", }, { step: "#2", task: "fetch_users with the Mock DB", status: "--", __originalIndex__: 1, __primaryKey__: "", }, { step: "#3", task: "Bind the query => fetch_users.data", status: "--", __originalIndex__: 2, __primaryKey__: "2", }, ]; const selectedRowIndexProp = 0; const defaultSelectedRow = 0; const result = selectRowIndex( oldTableData, newTableData, defaultSelectedRow, selectedRowIndexProp, "step", ); expect(result).toStrictEqual(0); }); }); describe("selectRowIndices", () => { it("With no selected index", () => { const oldTableData = [ { step: "#1", task: "fetch_users with the Mock DB", status: "--", __originalIndex__: 0, __primaryKey__: "1", }, { step: "#2", task: "fetch_users with the Mock DB", status: "--", __originalIndex__: 1, __primaryKey__: "", }, { step: "#3", task: "Bind the query => fetch_users.data", status: "--", __originalIndex__: 2, __primaryKey__: "2", }, ]; const newTableData = [ { step: "#1", task: " a fetch_users with the Mock DB", status: "--", __originalIndex__: 0, __primaryKey__: "1", }, { step: "#2", task: "fetch_users with the Mock DB", status: "--", __originalIndex__: 1, __primaryKey__: "", }, { step: "#3", task: "Bind the query => fetch_users.data", status: "--", __originalIndex__: 2, __primaryKey__: "2", }, ]; const defaultSelectedRow = [0]; const result = selectRowIndices( oldTableData, newTableData, defaultSelectedRow, [], undefined, ); expect(result).toEqual([0]); }); });