-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Classify data category dropdown (#1110)
* Refactor DataCategoryInput so it can be reused * Initial ClassifiedDataCategoryInput * Handle change from classified select * Add remove logic * Add playground * Rename ClassifiedDataCategoryInput --> ClassifiedDataCategoryDropdown * Update changelog * Render fides_key instead of name * Pull DataCategoryInput into its own file It is getting big, and it avoids circular dependencies * Wrap cypress component testing in redux provider wrapper so that components accessing the store will still work * Update tests for DataCategoryInput to handle classified version * Enable rendering ClassifiedDataCategoryDropdown when plus is available * Allow categories without confidences to show up in select box * Fixed confidence precision in category dropdown * sq merg Co-authored-by: Sebastian Sangervasi <sebastian@ethyca.com>
- Loading branch information
1 parent
e82fe92
commit ac92cb6
Showing
8 changed files
with
504 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
clients/ctl/admin-ui/cypress/components/ClassifiedDataCategoryInput.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import * as React from "react"; | ||
|
||
import ClassifiedDataCategoryDropdown from "~/features/dataset/ClassifiedDataCategoryDropdown"; | ||
import { MOCK_DATA_CATEGORIES } from "~/mocks/data"; | ||
import { DataCategory } from "~/types/api"; | ||
|
||
const CATEGORIES_WITH_CONFIDENCE = MOCK_DATA_CATEGORIES.map((dc) => ({ | ||
...dc, | ||
confidence: Math.floor(Math.random() * 100), | ||
})); | ||
const MOST_LIKELY_CATEGORIES = CATEGORIES_WITH_CONFIDENCE.slice(0, 5); | ||
|
||
describe("ClassifiedDataCategoryDropdown", () => { | ||
it("can render checked categories", () => { | ||
const onCheckedSpy = cy.spy().as("onCheckedSpy"); | ||
const selectedClassifiedCategory = MOST_LIKELY_CATEGORIES[0]; | ||
cy.mount( | ||
<ClassifiedDataCategoryDropdown | ||
dataCategories={MOCK_DATA_CATEGORIES as DataCategory[]} | ||
// check one "most likely" and one regular one | ||
checked={[ | ||
selectedClassifiedCategory.fides_key, | ||
"system.authentication", | ||
]} | ||
onChecked={onCheckedSpy} | ||
mostLikelyCategories={MOST_LIKELY_CATEGORIES} | ||
/> | ||
); | ||
|
||
// check that the classified one is selected | ||
cy.getByTestId("classified-select").should( | ||
"contain", | ||
selectedClassifiedCategory.fides_key | ||
); | ||
// check that the regular one is selected | ||
cy.getByTestId("data-category-dropdown").click(); | ||
cy.get("[data-testid='checkbox-Authentication Data'] > span").should( | ||
"have.attr", | ||
"data-checked" | ||
); | ||
cy.get( | ||
`[data-testid='checkbox-${selectedClassifiedCategory.name}'] > span` | ||
).should("have.attr", "data-checked"); | ||
}); | ||
|
||
it("can render all categories even if not recommended", () => { | ||
const onCheckedSpy = cy.spy().as("onCheckedSpy"); | ||
const selectedClassifiedCategory = MOST_LIKELY_CATEGORIES[0]; | ||
const otherCategory = MOCK_DATA_CATEGORIES[6]; | ||
cy.mount( | ||
<ClassifiedDataCategoryDropdown | ||
dataCategories={MOCK_DATA_CATEGORIES as DataCategory[]} | ||
// check one "most likely" and one regular one | ||
checked={[ | ||
selectedClassifiedCategory.fides_key, | ||
"system.authentication", | ||
]} | ||
onChecked={onCheckedSpy} | ||
mostLikelyCategories={MOST_LIKELY_CATEGORIES} | ||
/> | ||
); | ||
cy.getByTestId("classified-select").contains("system.authentication (N/A)"); | ||
cy.getByTestId("classified-select") | ||
.click() | ||
.within(() => { | ||
cy.contains(`${otherCategory.fides_key} (N/A)`); | ||
}); | ||
}); | ||
|
||
it("can select from classified select without overriding taxonomy dropdown", () => { | ||
const onCheckedSpy = cy.spy().as("onCheckedSpy"); | ||
const toSelect = MOST_LIKELY_CATEGORIES[0]; | ||
cy.mount( | ||
<ClassifiedDataCategoryDropdown | ||
dataCategories={MOCK_DATA_CATEGORIES as DataCategory[]} | ||
checked={["system.authentication"]} | ||
onChecked={onCheckedSpy} | ||
mostLikelyCategories={MOST_LIKELY_CATEGORIES} | ||
/> | ||
); | ||
cy.getByTestId("classified-select") | ||
.click() | ||
.type(`${toSelect.fides_key}{enter}`); | ||
cy.get("@onCheckedSpy").should("have.been.calledWith", [ | ||
"system.authentication", | ||
toSelect.fides_key, | ||
]); | ||
}); | ||
|
||
it("can select from taxonomy dropdown without overriding classified select", () => { | ||
const onCheckedSpy = cy.spy().as("onCheckedSpy"); | ||
const selectedClassifiedCategory = MOST_LIKELY_CATEGORIES[0]; | ||
cy.mount( | ||
<ClassifiedDataCategoryDropdown | ||
dataCategories={MOCK_DATA_CATEGORIES as DataCategory[]} | ||
checked={[selectedClassifiedCategory.fides_key]} | ||
onChecked={onCheckedSpy} | ||
mostLikelyCategories={MOST_LIKELY_CATEGORIES} | ||
/> | ||
); | ||
cy.getByTestId("data-category-dropdown").click(); | ||
cy.getByTestId("expand-System Data").click(); | ||
cy.getByTestId("checkbox-Authentication Data").click(); | ||
cy.get("@onCheckedSpy").should("have.been.calledWith", [ | ||
selectedClassifiedCategory.fides_key, | ||
"system.authentication", | ||
]); | ||
}); | ||
|
||
it("can remove items from classified select", () => { | ||
const onCheckedSpy = cy.spy().as("onCheckedSpy"); | ||
const selectedClassifiedCategory = MOST_LIKELY_CATEGORIES[0]; | ||
cy.mount( | ||
<ClassifiedDataCategoryDropdown | ||
dataCategories={MOCK_DATA_CATEGORIES as DataCategory[]} | ||
checked={[ | ||
selectedClassifiedCategory.fides_key, | ||
"system.authentication", | ||
]} | ||
onChecked={onCheckedSpy} | ||
mostLikelyCategories={MOST_LIKELY_CATEGORIES} | ||
/> | ||
); | ||
// delete the selected category | ||
cy.getByTestId("classified-select").click().type("{backspace}"); | ||
cy.get("@onCheckedSpy").should("have.been.calledWith", [ | ||
selectedClassifiedCategory.fides_key, | ||
]); | ||
}); | ||
|
||
it("can remove items from taxonomy select", () => { | ||
const onCheckedSpy = cy.spy().as("onCheckedSpy"); | ||
const selectedClassifiedCategory = MOST_LIKELY_CATEGORIES[0]; | ||
cy.mount( | ||
<ClassifiedDataCategoryDropdown | ||
dataCategories={MOCK_DATA_CATEGORIES as DataCategory[]} | ||
checked={[ | ||
selectedClassifiedCategory.fides_key, | ||
"system.authentication", | ||
]} | ||
onChecked={onCheckedSpy} | ||
mostLikelyCategories={MOST_LIKELY_CATEGORIES} | ||
/> | ||
); | ||
// uncheck system authentication | ||
cy.getByTestId("data-category-dropdown").click(); | ||
cy.getByTestId("checkbox-Authentication Data").click(); | ||
cy.get("@onCheckedSpy").should("have.been.calledWith", [ | ||
selectedClassifiedCategory.fides_key, | ||
]); | ||
}); | ||
|
||
it("playground", () => { | ||
// it's useful when developing to be able to play with the component with actual react state | ||
const ClassifiedDataCategoryDropdownWithState = () => { | ||
const [checked, setChecked] = React.useState([]); | ||
return ( | ||
<ClassifiedDataCategoryDropdown | ||
dataCategories={MOCK_DATA_CATEGORIES as DataCategory[]} | ||
checked={checked} | ||
onChecked={setChecked} | ||
mostLikelyCategories={MOST_LIKELY_CATEGORIES} | ||
/> | ||
); | ||
}; | ||
cy.mount(<ClassifiedDataCategoryDropdownWithState />); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.