Skip to content

Commit

Permalink
Prevent duplicate tools from being created
Browse files Browse the repository at this point in the history
  • Loading branch information
surchs committed Oct 12, 2023
1 parent 8fb4cd3 commit 7e54fcb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
6 changes: 5 additions & 1 deletion components/category-toolgroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
label="Select a tool"
:options="toolGroups"
outlined
@input="selectTool" />
@input="selectTool"
:selectable="(option) => !selectedTools.some(el => el.tool.includes(option))" />

<b-table
v-if="selectedTools.length > 0"
Expand Down Expand Up @@ -55,7 +56,10 @@
},
methods: {
selectTool(selectedTool) {
this.selectedTools.push({ tool: selectedTool});
console.log('selected', selectedTool);
console.log('list', this.selectedTools);
}
}
Expand Down
31 changes: 28 additions & 3 deletions cypress/component/category-toolgroup.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("Tool Group component", () => {
cy.get("[data-cy='toolgroup-select']").should("contain", "MOCA");
});

it("checks tool table functionality", () => {
it("lets me create new tools and shows them in a table", () => {
cy.mount(categoryToolGroup, {
mocks: {
$store: store
Expand All @@ -107,8 +107,33 @@ describe("Tool Group component", () => {
cy.get("[data-cy='assessment-tool-table']").should("be.visible");
cy.get("[data-cy='assessment-tool-table']").contains("MOCA");


});


it("if I have already made a tool, I cannot make another one ", () => {
cy.mount(categoryToolGroup, {
mocks: {
$store: store
}
});
// Do it the first time
cy.get("[data-cy='toolgroup-select']").click();
cy.get("[data-cy='toolgroup-select']").type("MOCA{enter}");
cy.get("[data-cy='toolgroup-select']").click();
cy.get("[data-cy='toolgroup-select']").type("SomeOtherThing{enter}");
// I hope nobody asks me to explain this
cy.get("[data-cy='assessment-tool-table']")
.find("tr:contains('MOCA')")
.filter((index, element) => Cypress.$(element).text() === "MOCA")
.should("have.length", 1);

// Do it again
cy.get("[data-cy='toolgroup-select']").click();
// The reason this is expected to fail is because the dropdown will not permit the
// user to type and enter again. Maybe we should make the assert more explicit
cy.get("[data-cy='toolgroup-select']").type("MOCA{enter}");
cy.get("[data-cy='assessment-tool-table']")
.find("tr:contains('MOCA')")
.filter((index, element) => Cypress.$(element).text() === "MOCA")
.should("have.length", 1);
});
});

0 comments on commit 7e54fcb

Please sign in to comment.