Skip to content

Commit

Permalink
Merge pull request #108 from TeselaGen/fixEditableCellTableTests
Browse files Browse the repository at this point in the history
Fix editable cell table tests
  • Loading branch information
tnrich authored Nov 19, 2024
2 parents f464235 + dfab13b commit cf0db74
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 205 deletions.
17 changes: 9 additions & 8 deletions packages/ui/cypress/e2e/EditableCellTable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe("EditableCellTable.spec", () => {
).should("contain", "NaN"); //should lowercase "Tom"
cy.get(`[data-test="tgCell_howMany"]:first`).dblclick();
cy.focused().type("11{enter}");
cy.get(`[data-test="tgCell_howMany"]:first`).should("contain", "12"); //should have 12 post format
cy.get(`[data-test="tgCell_howMany"]:first`).should("contain", "11"); //should have 12 post format
cy.get(
`[data-tip="Must be a number"] [data-test="tgCell_howMany"]:first`
).should("not.exist");
Expand All @@ -148,10 +148,11 @@ describe("EditableCellTable.spec", () => {
cy.get(
`.rt-td.isSelectedCell.isPrimarySelected [data-test="tgCell_name"]`
).should("not.exist");
cy.get(`[data-test="tgCell_name"]`).eq(3).click({ force: true });
cy.get(`[data-test="tgCell_name"]`).eq(3).click();
cy.get(`.rt-td.isSelectedCell.isPrimarySelected [data-test="tgCell_name"]`);
cy.get(`[data-test="tgCell_name"]`).eq(3).dblclick({ force: true });
cy.focused().type(`haha`).typeTab();
cy.get(`[data-test="tgCell_name"]`).eq(3).dblclick();
cy.focused().type("haha{enter}");
cy.focused().typeTab();
cy.get(
`.rt-td.isSelectedCell.isPrimarySelected [data-test="tgCell_name"]`
).should("not.exist");
Expand Down Expand Up @@ -301,10 +302,10 @@ describe("EditableCellTable.spec", () => {
cy.visit("#/DataTable%20-%20EditableCellTable");
cy.get(`[data-test="tgCell_name"]:last`).click();
cy.get(`[data-index="52"]`).should("not.exist");
cy.focused().paste(`hettie mclaughlin new cloudy 6 True
laura stevens new HOT 6 Yes
lucas jensen old rainy 4 false
todd ross old snowy 4 no`);
cy.focused().paste(`william warren new HOT 5 True
verna francis old cloudy 2 True
nora morris new HOT 2 True
miguel fitzgerald old snowy 2 False`);
cy.get(`[data-test="tgCell_isProtein"]:last[data-copy-text="False"]`);
cy.get(`[data-test="tgCell_weather"]:last`).closest(`.hasCellError`);

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/cypress/e2e/upload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("upload", () => {
true
);

cy.contains("type must be .zip or .json");
cy.contains("type must be .json");
cy.uploadBlobFiles(
".fileUploadLimitAndType.tg-dropzone",
[
Expand Down
46 changes: 24 additions & 22 deletions packages/ui/demo/src/examples/EditableCellTable.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Chance } from "chance";
import { times } from "lodash-es";
import { nanoid } from "nanoid";
import React, { useMemo, useRef, useState } from "react";
import React, { useMemo, useState } from "react";
import DataTable from "../../../src/DataTable";
import DemoWrapper from "../DemoWrapper";
import { useToggle } from "../useToggle";
Expand Down Expand Up @@ -31,26 +31,32 @@ const getEnts = num =>
i === 0 ? "WAY TOO HOT" : chance.pickone(["rainy", "cloudy", "HOT"])
}));

export default function EditableCellTable(props) {
const key = useRef(0);
const defaultValAsFuncOptions = {
type: "defaultValAsFunc"
};

export default function EditableCellTable(props) {
const [entities, setEnts] = useState([]);
const [, numComp] = useToggle({
type: "num",
label: "Number of Entities",
isSelect: true,
defaultValue: 50,
controlledValue: props.entities?.length,
setControlledValue: v => {
key.current++;
setEnts(getEnts(toNumber(v)));
},
options: [20, 50, 100]
});
const toggleOptions = useMemo(
() => ({
type: "num",
label: "Number of Entities",
isSelect: true,
defaultValue: 50,
controlledValue: props.entities?.length,
setControlledValue: v => {
setEnts(getEnts(toNumber(v)));
},
options: [20, 50, 100]
}),
[props.entities?.length]
);

const [defaultValAsFunc, defaultValAsFuncComp] = useToggle({
type: "defaultValAsFunc"
});
const [, numComp] = useToggle(toggleOptions);

const [defaultValAsFunc, defaultValAsFuncComp] = useToggle(
defaultValAsFuncOptions
);

const schema = useMemo(
() => ({
Expand Down Expand Up @@ -93,9 +99,6 @@ export default function EditableCellTable(props) {
//should be able to pass additional validation/formatting
validate: newVal => {
if (newVal > 20) return "This val is toooo high";
},
format: newVal => {
return toNumber(newVal) + 1;
}
},
{
Expand All @@ -118,7 +121,6 @@ export default function EditableCellTable(props) {
<DemoWrapper>
<DataTable
{...props}
key={key.current}
formName="editableCellTable"
isSimple
isCellEditable
Expand Down
Loading

0 comments on commit cf0db74

Please sign in to comment.