Skip to content

Commit

Permalink
add classifications test
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp committed Dec 17, 2024
1 parent 4c47584 commit d339401
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 92 deletions.
93 changes: 93 additions & 0 deletions client/cypress/e2e/SettingsPanel/classifications.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
describe("Classifications test", function () {
it("add classifications to activity", () => {
cy.loginAsTestUser();

cy.createActivity("Hello!", "Initial content").then((activityId) => {
cy.visit(`/activityEditor/${activityId}`);

cy.get('[data-test="Settings Button"]').click();

cy.get('[data-test="Classifications"]').click();

cy.get('[data-test="Classifications"]').should(
"have.text",
"Classifications (0)",
);

cy.get('[data-test="Search Terms"]').type("factor quadratic{enter}");

cy.get('[data-test="Add 9.2.4.1"]').click();
cy.get('[data-test="Add A.REI.4 b."]').click();

cy.get('[data-test="Classifications"]').should(
"have.text",
"Classifications (2)",
);

cy.get('[data-test="Existing Classification 1"]').should(
"have.text",
"A.REI.4 b.",
);
cy.get('[data-test="Existing Classification 2"]').should(
"have.text",
"9.2.4.1",
);

cy.get('[data-test="Remove A.REI.4 b."]').click();
cy.get('[data-test="Classifications"]').should(
"have.text",
"Classifications (1)",
);
cy.get('[data-test="Existing Classification 1"]').should(
"have.text",
"9.2.4.1",
);

cy.get('[data-test="Filter By System').select("Common Core");
cy.get('[data-test="Add A.REI.4 b."]').should("be.visible");

cy.get('[data-test="Filter By Category').select("Grade 6");
cy.get('[data-test="Add A.REI.4 b."]').should("not.exist");

cy.get('[data-test="Filter By Subcategory').select(2);
cy.get('[data-test="Matching Classifications').should(
"contain.text",
"No matching classifications",
);

cy.get('[data-test="Stop Filter By Subcategory').click();

cy.get('[data-test="Add 6.EE.2 b."]').click();
cy.get('[data-test="Classifications"]').should(
"have.text",
"Classifications (2)",
);
cy.get('[data-test="Existing Classification 1"]').should(
"have.text",
"6.EE.2 b.",
);
cy.get('[data-test="Existing Classification 2"]').should(
"have.text",
"9.2.4.1",
);

cy.get('[data-test="Remove Existing 6.EE.2 b."]').click();
cy.get('[data-test="Classifications"]').should(
"have.text",
"Classifications (1)",
);
cy.get('[data-test="Existing Classification 1"]').should(
"have.text",
"9.2.4.1",
);

cy.get('[data-test="Add A.REI.4 b."]').should("not.exist");
cy.get('[data-test="Stop Filter By Category').click();
cy.get('[data-test="Add A.REI.4 b."]').should("be.visible");

cy.get('[data-test="Add 9.2.3.3"]').should("not.exist");
cy.get('[data-test="Stop Filter By System').click();
cy.get('[data-test="Add 9.2.3.3"]').should("be.visible");
});
});
});
204 changes: 112 additions & 92 deletions client/src/Tools/_framework/ToolPanels/ClassificationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ export function ClassificationSettings({
<h2>
<AccordionButton>
<HStack flex="1" textAlign="left" direction={"row"}>
;<Text as="b">{classification.code}</Text>
<Text
as="b"
data-test={`Existing Classification ${i + 1}`}
>
{classification.code}
</Text>
<Text fontSize={"small"} pt="2px">
{classification.subCategory.category.system.name}
</Text>
Expand All @@ -207,6 +212,7 @@ export function ClassificationSettings({
>
<CloseButton
aria-label={`Remove classification ${classification.code}`}
data-test={`Remove Existing ${classification.code}`}
hidden={
classifyItemRemoveSpinner === classification.id
}
Expand Down Expand Up @@ -281,6 +287,7 @@ export function ClassificationSettings({
<Select
value={categoryFilter.systemTreeIndex ?? ""}
placeholder="Filter by system"
data-test="Filter By System"
onChange={(event) => {
if (event.target.value) {
let treeIndex = Number(event.target.value);
Expand All @@ -299,6 +306,7 @@ export function ClassificationSettings({
</Select>
<CloseButton
aria-label={`Stop filtering by system`}
data-test="Stop Filter By System"
disabled={selectedClassification === null}
onClick={() => {
setCategoryFilter({});
Expand All @@ -314,6 +322,7 @@ export function ClassificationSettings({
? "-"
: `Filter by ${selectedClassification.categoryLabel}`
}
data-test="Filter By Category"
isDisabled={categoryFilter.systemId === undefined}
onChange={(event) => {
if (event.target.value) {
Expand Down Expand Up @@ -347,6 +356,7 @@ export function ClassificationSettings({
</Select>
<CloseButton
aria-label={`Stop filtering by ${selectedClassification?.categoryLabel}`}
data-test="Stop Filter By Category"
disabled={categoryFilter.categoryId === undefined}
onClick={() => {
setCategoryFilter((was) => {
Expand All @@ -369,6 +379,7 @@ export function ClassificationSettings({
? "-"
: `Filter by ${selectedClassification!.subCategoryLabel}`
}
data-test="Filter By Subcategory"
isDisabled={categoryFilter.categoryId === undefined}
onChange={(event) => {
if (event.target.value) {
Expand Down Expand Up @@ -402,6 +413,7 @@ export function ClassificationSettings({
</Select>
<CloseButton
aria-label={`Stop filtering by ${selectedClassification?.subCategoryLabel}`}
data-test="Stop Filter By Subcategory"
disabled={categoryFilter.categoryId === undefined}
onClick={() => {
setCategoryFilter((was) => {
Expand All @@ -416,6 +428,7 @@ export function ClassificationSettings({

<Input
type="search"
data-test="Search Terms"
placeholder="Filter by search terms"
onInput={updateSearchTerms}
onKeyDown={(e) => {
Expand All @@ -427,101 +440,108 @@ export function ClassificationSettings({
marginTop={4}
/>

{classificationOptions.length === 0 ? (
<p>No matching classifications</p>
) : null}
<Box data-test="Matching Classifications">
{classificationOptions.length === 0 ? (
<p>No matching classifications</p>
) : null}

{classificationOptions.map((classification) => {
let added = contentData.classifications
.map((c) => c.id)
.includes(classification.id);
let buttonText = added ? "Remove" : "Add";
let action =
(added ? "remove" : "add") + " content classification";
{classificationOptions.map((classification) => {
let added = contentData.classifications
.map((c) => c.id)
.includes(classification.id);
let buttonText = added ? "Remove" : "Add";
let action =
(added ? "remove" : "add") + " content classification";

return (
<Card backgroundColor={added ? "lightGray" : "var(--canvas)"}>
<CardBody paddingLeft={2}>
<Flex>
<Heading size="sm">
{classification.code} (
{classification.subCategory.category.system.name})
</Heading>
<Spacer />
return (
<Card
backgroundColor={added ? "lightGray" : "var(--canvas)"}
>
<CardBody paddingLeft={2}>
<HStack>
<Heading size="sm">
{classification.code} (
{classification.subCategory.category.system.name})
</Heading>
<Spacer />

<Button
size="sm"
isDisabled={
dropdownWaitingForChange === classification.id
}
onClick={() => {
setDropdownWaitingForChange(classification.id);
fetcher.submit(
<Button
size="sm"
isDisabled={
dropdownWaitingForChange === classification.id
}
onClick={() => {
setDropdownWaitingForChange(classification.id);
fetcher.submit(
{
_action: action,
activityId: id,
classificationId: classification.id,
},
{ method: "post" },
);
}}
data-test={`${buttonText} ${classification.code}`}
>
{dropdownWaitingForChange === classification.id ? (
<Spinner />
) : (
buttonText
)}
</Button>
</HStack>
<Box>
<Text>
<Text as="i">
{
_action: action,
activityId: id,
classificationId: classification.id,
},
{ method: "post" },
);
}}
>
{dropdownWaitingForChange === classification.id ? (
<Spinner />
) : (
buttonText
)}
</Button>
</Flex>
<Text>
<Text as="i">
{
classification.subCategory.category.system
.categoryLabel
}
:
</Text>{" "}
<Highlight
query={queryFilter?.split(" ") || ""}
styles={{ fontWeight: "bold" }}
>
{classification.subCategory.category.category}
</Highlight>
</Text>
<Text>
<Text as="i">
{
classification.subCategory.category.system
.subCategoryLabel
}
:
</Text>{" "}
<Highlight
query={queryFilter?.split(" ") || ""}
styles={{ fontWeight: "bold" }}
>
{classification.subCategory.subCategory}
</Highlight>
</Text>
<Text>
<Text as="i">
{
classification.subCategory.category.system
.descriptionLabel
}
:
</Text>{" "}
<Highlight
query={(queryFilter || "").split(" ")}
styles={{ fontWeight: "bold" }}
>
{classification.description}
</Highlight>
</Text>
</CardBody>
</Card>
);
})}
classification.subCategory.category.system
.categoryLabel
}
:
</Text>{" "}
<Highlight
query={queryFilter?.split(" ") || ""}
styles={{ fontWeight: "bold" }}
>
{classification.subCategory.category.category}
</Highlight>
</Text>
<Text>
<Text as="i">
{
classification.subCategory.category.system
.subCategoryLabel
}
:
</Text>{" "}
<Highlight
query={queryFilter?.split(" ") || ""}
styles={{ fontWeight: "bold" }}
>
{classification.subCategory.subCategory}
</Highlight>
</Text>
<Text>
<Text as="i">
{
classification.subCategory.category.system
.descriptionLabel
}
:
</Text>{" "}
<Highlight
query={(queryFilter || "").split(" ")}
styles={{ fontWeight: "bold" }}
>
{classification.description}
</Highlight>
</Text>
</Box>
</CardBody>
</Card>
);
})}
</Box>
</Box>
</Flex>
</Flex>
Expand Down

0 comments on commit d339401

Please sign in to comment.