-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: search tag reset prior annotation (#1736)
- Loading branch information
1 parent
ba5f732
commit 0f8c9d0
Showing
5 changed files
with
103 additions
and
13 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
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
77 changes: 77 additions & 0 deletions
77
...omponents/text-classifier/results/classifier-annotation/classifierExplorationArea.spec.js
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,77 @@ | ||
import { shallowMount } from "@vue/test-utils"; | ||
import ClassifierAnnotationArea from "./ClassifierAnnotationArea"; | ||
import ClassifierAnnotationButton from "../ClassifierAnnotationButton"; | ||
import { TextClassificationRecord } from "@/models/TextClassification"; | ||
|
||
let wrapper = null; | ||
const options = { | ||
propsData: { | ||
record: new TextClassificationRecord({ | ||
inputs: { text: "My text", multi_label: false }, | ||
}), | ||
dataset: { | ||
task: "TextClassification", | ||
isMultiLabel: true, | ||
viewSettings: { | ||
annotationEnabled: false, | ||
}, | ||
labels: ["label1"], // WARNING, if labels is empty then the ClassifierAnnotationButton will no be render => test 2/3/4/5 will failed | ||
}, | ||
}, | ||
}; | ||
const spyUpdateLabelsMethod = jest.spyOn( | ||
ClassifierAnnotationArea.methods, | ||
"updateLabels" | ||
); | ||
beforeEach(() => { | ||
wrapper = shallowMount(ClassifierAnnotationArea, options); | ||
}); | ||
|
||
afterEach(() => { | ||
wrapper.destroy(); | ||
}); | ||
|
||
describe("ClassifierAnnotationAreaComponent", () => { | ||
it("render the component", () => { | ||
expect(wrapper.is(ClassifierAnnotationArea)).toBe(true); | ||
}); | ||
it("render the child component if props labels is not empty", () => { | ||
const annotationButtons = wrapper.findComponent(ClassifierAnnotationButton); | ||
expect(annotationButtons.exists()).toBe(true); | ||
}); | ||
it("emit the 2 annotations selected by the user to the parent component", async () => { | ||
testIfEmittedValuesFromValidateEventIsEqualToUserSelectedAnnotations([ | ||
"label1", | ||
]); | ||
}); | ||
it("emit the 2 annotations selected by the user to the parent component", async () => { | ||
testIfEmittedValuesFromValidateEventIsEqualToUserSelectedAnnotations([ | ||
"label1", | ||
"label2", | ||
]); | ||
}); | ||
it("emit an empty list to the parent if the user have selected any annotations", async () => { | ||
testIfEmittedValuesFromValidateEventIsEqualToUserSelectedAnnotations([]); | ||
}); | ||
}); | ||
|
||
const testIfEmittedValuesFromValidateEventIsEqualToUserSelectedAnnotations = | ||
async (selectedAnnotations) => { | ||
const annotationButtons = wrapper.findComponent(ClassifierAnnotationButton); | ||
const emittedValuesFromAnnotationButtons = selectedAnnotations; | ||
annotationButtons.vm.$emit("change", emittedValuesFromAnnotationButtons); | ||
await wrapper.vm.$nextTick(); | ||
expect(spyUpdateLabelsMethod).toHaveBeenCalled(); | ||
if (selectedAnnotations.length) { | ||
selectedAnnotations.forEach((annotation) => { | ||
expect(wrapper.vm.selectedLabels).toContain(annotation); | ||
}); | ||
} | ||
expect(wrapper.vm.selectedLabels.length).toBe( | ||
emittedValuesFromAnnotationButtons.length | ||
); | ||
expect(wrapper.emitted("validate")); | ||
expect(wrapper.emitted().validate[0]).toEqual([ | ||
{ labels: emittedValuesFromAnnotationButtons }, | ||
]); | ||
}; |
2 changes: 1 addition & 1 deletion
2
frontend/specs/components/text-classification/results/ClassifierAnnotationArea.spec.js
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