Skip to content

Commit

Permalink
feat: delete formula retaining values (#1394)
Browse files Browse the repository at this point in the history
  • Loading branch information
kswenson authored Aug 11, 2024
1 parent c58678f commit aafdac8
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 127 deletions.
6 changes: 3 additions & 3 deletions v3/cypress/e2e/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ context("codap plugins", () => {
webView.clearAPITesterResponses()

cy.log("Broadcast deleteAttributes notifications")
table.deleteAttrbute("newAttr2")
table.deleteAttribute("newAttr2")
webView.confirmAPITesterResponseContains(/"operation":\s"deleteAttributes/)
webView.clearAPITesterResponses()

Expand Down Expand Up @@ -321,10 +321,10 @@ context("codap plugins", () => {
cfm.openExampleDocument("Four Seals")
cy.wait(2000)
table.getTableTile().should("contain.text", "Tracks/Measurements")
table.deleteAttrbute("species")
table.deleteAttribute("species")
openAPITester()
webView.toggleAPITesterFilter()
table.deleteAttrbute("animal_id")
table.deleteAttribute("animal_id")
webView.confirmAPITesterResponseContains(/"operation":\s"deleteCollection/)

// TODO Check for deleteCollection notifications when deleting the last attribute
Expand Down
45 changes: 45 additions & 0 deletions v3/cypress/e2e/table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,51 @@ context("case table ui", () => {
table.getColumnHeader(1).should("contain", "Animal")
table.getAttribute("Animal").should("exist")
})
it("edits, re-randomizes, and deletes formulas", () => {
// add a random() formula
table.addFormula("Height", "random()")
let random1 = 0
table.getGridCell(2, 5).then(cell => {
random1 = +cell.text()
expect(random1 >= 0).to.eq(true)
expect(random1 < 1).to.eq(true)
})
// Rerandomize
let random2 = 0
table.openAttributeMenu("Height")
table.selectMenuItemFromAttributeMenu("Rerandomize")
table.getGridCell(2, 5).then(cell => {
random2 = +cell.text()
expect(random2 >= 0).to.eq(true)
expect(random2 < 1).to.eq(true)
expect(random2).not.to.eq(random1)
})
// Delete formula, verify values remain
table.openAttributeMenu("Height")
table.selectMenuItemFromAttributeMenu("Delete Formula (Keeping Values)")
table.getGridCell(2, 5).then(cell => {
const value = +cell.text()
expect(value >= 0).to.eq(true)
expect(value < 1).to.eq(true)
expect(value).to.eq(random2)
})
// verify that formula was deleted
table.openAttributeMenu("Height")
table.getAttributeMenuItem("Rerandomize").should("be.disabled")
table.getAttributeMenuItem("Delete Formula (Keeping Values)").should("be.disabled")
// Undo formula deletion
toolbar.getUndoTool().click()
table.openAttributeMenu("Height")
table.getAttributeMenuItem("Rerandomize").should("be.enabled")
table.getAttributeMenuItem("Delete Formula (Keeping Values)").should("be.enabled")
table.getGridCell(2, 5).then(cell => {
const value = +cell.text()
expect(value >= 0).to.eq(true)
expect(value < 1).to.eq(true)
// restored formula is re-evaluated resulting in a different value
expect(value).not.to.eq(random2)
})
})
it("verify hide and showAll attribute with undo and redo", () => {

// Hide the attribute
Expand Down
4 changes: 2 additions & 2 deletions v3/cypress/support/elements/table-tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const TableTileElements = {
getAttributeInput(collectionIndex = 1) {
return this.getCollection(collectionIndex).find("[data-testid=column-name-input]")
},
getCasetableAttribute(name) {
getCaseTableAttribute(name) {
return this.getTableTile().find(`[data-testid^="codap-attribute-button ${name}"]`)
},
openAttributeMenu(name, collectionIndex = 1) {
Expand Down Expand Up @@ -342,7 +342,7 @@ export const TableTileElements = {
.click({force:true})
cy.get("[data-testid=column-name-input]").type("{enter}")
},
deleteAttrbute(attributeName, collectionIndex = 1) {
deleteAttribute(attributeName, collectionIndex = 1) {
this.openAttributeMenu(attributeName, collectionIndex)
this.selectMenuItemFromAttributeMenu("Delete Attribute")
this.getAttribute(attributeName, collectionIndex).should("not.exist")
Expand Down
2 changes: 1 addition & 1 deletion v3/cypress/support/helpers/formula-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const FormulaHelper = {
table.renameAttribute(currentAttributeName, newAttributeName, collectionIndex)
},
deleteAttribute(attributeName: string, collectionIndex = 1) {
table.deleteAttrbute(attributeName, collectionIndex)
table.deleteAttribute(attributeName, collectionIndex)
},
addFormula(attributeName: string, formula: string, collectionIndex = 1) {
table.addFormula(attributeName, formula, collectionIndex)
Expand Down
Loading

0 comments on commit aafdac8

Please sign in to comment.