Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

188497528 case tile filter formula editor #1617

Merged
merged 11 commits into from
Nov 15, 2024
114 changes: 58 additions & 56 deletions v3/cypress/e2e/formula/formula-component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,81 @@
import { FormulaHelper as fh } from "../../support/helpers/formula-helper"
import { TableTileElements as table } from "../../support/elements/table-tile"
import { SliderTileElements as slider } from "../../support/elements/slider-tile"

context("Formula Engine", () => {
describe("Component Formula Tests", () => {
it("Add and edit formula for a new attribute", () => {
fh.visitURL("?sample=four&dashboard")
fh.addNewAttribute()
fh.renameAttribute("newAttr", "Formula")
fh.addFormula("Formula", "a+1")
fh.verifyValues("Formula", [2, 3, 4, 4, 1])
fh.checkFormulaExists("Formula", "a+1")
fh.editFormula("Formula", "a+2")
fh.verifyValues("Formula", [3, 4, 5, 5, 2])
table.addNewAttribute()
table.renameAttribute("newAttr", "Formula")
table.addFormula("Formula", "a+1")
table.verifyFormulaValues("Formula", [2, 3, 4, 4, 1])
table.checkFormulaExists("Formula", "a+1")
table.editFormula("Formula", "a+2")
table.verifyFormulaValues("Formula", [3, 4, 5, 5, 2])
})
it("Add and edit formula for an existing attribute", () => {
fh.visitURL("?sample=four&dashboard")
fh.addFormula("b", "count(a)")
fh.verifyValues("b", [4, 4, 4, 4, 4])
fh.checkFormulaExists("b", "count(a)")
fh.editFormula("b", "mean(a)")
fh.verifyValues("b", [2.25, 2.25, 2.25, 2.25, 2.25])
table.addFormula("b", "count(a)")
table.verifyFormulaValues("b", [4, 4, 4, 4, 4])
table.checkFormulaExists("b", "count(a)")
table.editFormula("b", "mean(a)")
table.verifyFormulaValues("b", [2.25, 2.25, 2.25, 2.25, 2.25])
})
it("Rename attribute and make sure formula updates", () => {
fh.visitURL("?sample=four&dashboard")
fh.addNewAttribute()
fh.renameAttribute("newAttr", "Formula")
fh.addFormula("Formula", "count(a)")
fh.verifyValues("Formula", [4, 4, 4, 4, 4])
fh.renameAttribute("a", "x")
fh.checkFormulaExists("Formula", "count(x)")
fh.verifyValues("Formula", [4, 4, 4, 4, 4])
fh.editFormula("Formula", "mean(x)")
fh.verifyValues("Formula", [2.25, 2.25, 2.25, 2.25, 2.25])
table.addNewAttribute()
table.renameAttribute("newAttr", "Formula")
table.addFormula("Formula", "count(a)")
table.verifyFormulaValues("Formula", [4, 4, 4, 4, 4])
table.renameAttribute("a", "x")
table.checkFormulaExists("Formula", "count(x)")
table.verifyFormulaValues("Formula", [4, 4, 4, 4, 4])
table.editFormula("Formula", "mean(x)")
table.verifyFormulaValues("Formula", [2.25, 2.25, 2.25, 2.25, 2.25])
})
it("Delete attribute that a formula uses", () => {
fh.visitURL("?sample=four&dashboard")
fh.addFormula("b", "count(a)")
fh.deleteAttribute("a")
fh.checkFormulaExists("b", "count(a)")
fh.verifyValues("b", [
table.addFormula("b", "count(a)")
table.deleteAttribute("a")
table.checkFormulaExists("b", "count(a)")
table.verifyFormulaValues("b", [
"❌ Undefined symbol a",
"❌ Undefined symbol a",
"❌ Undefined symbol a",
"❌ Undefined symbol a",
"❌ Undefined symbol a"
])
fh.editFormula("b", "5")
fh.verifyValues("b", [5, 5, 5, 5, 5])
table.editFormula("b", "5")
table.verifyFormulaValues("b", [5, 5, 5, 5, 5])
})
it("Use slider variable with formula", () => {
fh.visitURL("?sample=four&dashboard")
fh.addFormula("b", "count(a) + v1")
fh.verifyValues("b", [4.5, 4.5, 4.5, 4.5, 4.5])
fh.changeSliderVariableName("v2")
fh.checkFormulaExists("b", "count(a) + v2")
fh.verifyValues("b", [4.5, 4.5, 4.5, 4.5, 4.5])
fh.changeSliderValue("10")
fh.verifyValues("b", [14, 14, 14, 14, 14])
fh.deleteSlider()
fh.checkFormulaExists("b", "count(a) + v2")
table.addFormula("b", "count(a) + v1")
table.verifyFormulaValues("b", [4.5, 4.5, 4.5, 4.5, 4.5])
slider.changeVariableName("v2")
table.checkFormulaExists("b", "count(a) + v2")
table.verifyFormulaValues("b", [4.5, 4.5, 4.5, 4.5, 4.5])
slider.changeVariableValue("10")
table.verifyFormulaValues("b", [14, 14, 14, 14, 14])
slider.deleteSlider()
table.checkFormulaExists("b", "count(a) + v2")
})
it("Add slider after using it in formula", () => {
fh.visitURL("?sample=four")
fh.addFormula("b", "count(a) + v1")
fh.verifyValues("b", [
table.addFormula("b", "count(a) + v1")
table.verifyFormulaValues("b", [
"❌ Undefined symbol v1",
"❌ Undefined symbol v1",
"❌ Undefined symbol v1",
"❌ Undefined symbol v1",
"❌ Undefined symbol v1"
])
fh.addSlider()
fh.checkFormulaExists("b", "count(a) + v1")
fh.verifyValues("b", [4.5, 4.5, 4.5, 4.5, 4.5])
fh.deleteSlider()
fh.verifyValues("b", [
slider.addSlider()
table.checkFormulaExists("b", "count(a) + v1")
table.verifyFormulaValues("b", [4.5, 4.5, 4.5, 4.5, 4.5])
slider.deleteSlider()
table.verifyFormulaValues("b", [
"❌ Undefined symbol v1",
"❌ Undefined symbol v1",
"❌ Undefined symbol v1",
Expand All @@ -84,22 +85,23 @@ context("Formula Engine", () => {
})
it("Formula in a new dataset", () => {
fh.visitURL("")
fh.createNewDataset()
fh.insertCases(2, 4)
fh.addFormula("AttributeName", "10*10")
fh.verifyValues("AttributeName", [100, 100, 100, 100, 100])
fh.addNewAttribute()
fh.addFormula("newAttr", "AttributeName+2")
fh.verifyValues("newAttr", [102, 102, 102, 102, 102])
table.createNewTableFromToolShelf()
table.openIndexMenuForRow(2)
table.insertCases(4, "after")
table.addFormula("AttributeName", "10*10")
table.verifyFormulaValues("AttributeName", [100, 100, 100, 100, 100])
table.addNewAttribute()
table.addFormula("newAttr", "AttributeName+2")
table.verifyFormulaValues("newAttr", [102, 102, 102, 102, 102])
})
})
describe("Add functions and values from Insert buttons", () => {
it("Navigate functions browser", () => {
const func = "abs"
const funcCategory = "Arithmetic"
fh.visitURL("?sample=four&dashboard")
fh.addNewAttribute()
fh.renameAttribute("newAttr", "Formula")
table.addNewAttribute()
table.renameAttribute("newAttr", "Formula")
table.openAttributeMenu("Formula")
table.selectMenuItemFromAttributeMenu("Edit Formula...")
cy.get("[data-testid=formula-insert-function-button]").click()
Expand All @@ -121,8 +123,8 @@ context("Formula Engine", () => {
const func = "abs"
const funcCategory = "Arithmetic"
fh.visitURL("?sample=four&dashboard")
fh.addNewAttribute()
fh.renameAttribute("newAttr", "Formula")
table.addNewAttribute()
table.renameAttribute("newAttr", "Formula")
table.openAttributeMenu("Formula")
table.selectMenuItemFromAttributeMenu("Edit Formula...")
cy.get("[data-testid=formula-insert-function-button]").click()
Expand All @@ -139,8 +141,8 @@ context("Formula Engine", () => {
it("Insert value into formula", () => {
const value = "b"
fh.visitURL("?sample=four&dashboard")
fh.addNewAttribute()
fh.renameAttribute("newAttr", "Formula")
table.addNewAttribute()
table.renameAttribute("newAttr", "Formula")
table.openAttributeMenu("Formula")
table.selectMenuItemFromAttributeMenu("Edit Formula...")
cy.get("[data-testid=formula-insert-value-button]").click()
Expand Down
21 changes: 11 additions & 10 deletions v3/cypress/e2e/formula/formula-errors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
import { FormulaHelper as fh } from "../../support/helpers/formula-helper"
import { TableTileElements as table } from "../../support/elements/table-tile"

context("Formula Engine", () => {
describe("Errors Formula Tests", () => {
it("Check invalid functions", () => {
fh.visitURL("?sample=four")
fh.addNewAttribute()
fh.renameAttribute("newAttr", "Formula")
fh.addFormula("Formula", "count(aaa)")
fh.verifyValues("Formula", [
table.addNewAttribute()
table.renameAttribute("newAttr", "Formula")
table.addFormula("Formula", "count(aaa)")
table.verifyFormulaValues("Formula", [
"❌ Undefined symbol aaa",
"❌ Undefined symbol aaa",
"❌ Undefined symbol aaa",
"❌ Undefined symbol aaa",
"❌ Undefined symbol aaa"
])
fh.editFormula("Formula", "c(aaa)")
fh.verifyValues("Formula", [
table.editFormula("Formula", "c(aaa)")
table.verifyFormulaValues("Formula", [
"❌ Undefined function c",
"❌ Undefined function c",
"❌ Undefined function c",
"❌ Undefined function c",
"❌ Undefined function c"
])
// need to add {del} because CodeMirror auto-matches parentheses
fh.editFormula("Formula", "count(a{del}")
fh.verifyValues("Formula", [
table.editFormula("Formula", "count(a{del}")
table.verifyFormulaValues("Formula", [
"❌ Syntax error: 'Parenthesis ) expected (char 8)'",
"❌ Syntax error: 'Parenthesis ) expected (char 8)'",
"❌ Syntax error: 'Parenthesis ) expected (char 8)'",
"❌ Syntax error: 'Parenthesis ) expected (char 8)'",
"❌ Syntax error: 'Parenthesis ) expected (char 8)'"
])
fh.editFormula("Formula", "count(a)")
fh.verifyValues("Formula", [4, 4, 4, 4, 4])
table.editFormula("Formula", "count(a)")
table.verifyFormulaValues("Formula", [4, 4, 4, 4, 4])
})
})
})
Loading
Loading