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

test: LEAP-1141: Add test for concurrent saving annotation and draft #6022

Merged
merged 9 commits into from
Jul 1, 2024
69 changes: 69 additions & 0 deletions web/libs/editor/tests/integration/e2e/drafts/submit.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Choices, LabelStudio, ToolBar } from "@humansignal/frontend-test/helpers/LSF";
import { FF_CUSTOM_SCRIPT, FF_DEV_3873, FF_REVIEWER_FLOW } from "../../../../src/utils/feature-flags";

enum RESPONSE_TYPE {
DRAFT = "draft",
SUBMIT = "submit",
}
const RESPONSE_DELAY = 100;
const WAITING_FOR_EVENTS_DELAY = 200;

describe("Annotation submitting process", () => {
it("should not create a duplicate annotation if the annotation and draft are saved concurrently", () => {
LabelStudio.addFeatureFlagsOnPageLoad({
[FF_DEV_3873]: true,
[FF_REVIEWER_FLOW]: true,
[FF_CUSTOM_SCRIPT]: true,
});
// here will be stored an order of completed saving action
// it consists of strings: "draft" and "submit"
const callApi = cy.spy().as("callApi");

LabelStudio.params()
.data({
text: "Some words",
})
.config(`<View>
<Text name="text" value="$text" />
<Choices toName="text" name="choice">
<Choice value="ClickMe"/>
</Choices>
</View>`)
// To have "new" annotation we need to use userGenerate
.withAnnotation({ userGenerate: true, result: [] })
.withEventListener("submitAnnotation", () => {
callApi(RESPONSE_TYPE.SUBMIT);
})
.withEventListener("submitDraft", () => {
return new Promise<void>((resolve) => {
// initialize saving annotation exactly when request of saving draft should be sent to the server
ToolBar.submitBtn.click();

// this emulates server response delay
setTimeout(() => {
callApi(RESPONSE_TYPE.DRAFT);
resolve();
}, RESPONSE_DELAY);
});
})
.init();

// just to have something to save
Choices.findChoice("ClickMe").click();

// Preventing waiting for autosave. It will save time.
cy.window().then(async (win) => {
win.Htx.annotationStore.selected.saveDraftImmediately();
});

// Wait for all submit events to be invoked, to have `callOrder` ready to check
cy.wait(WAITING_FOR_EVENTS_DELAY);

// Check order
cy.window().then((win) => {
expect(callApi).to.be.calledTwice;
expect(callApi.firstCall).to.be.calledWith(RESPONSE_TYPE.DRAFT);
expect(callApi.secondCall).to.be.calledWith(RESPONSE_TYPE.SUBMIT);
});
});
});
12 changes: 11 additions & 1 deletion web/libs/frontend-test/src/helpers/LSF/ToolBar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { FF_DEV_1170 } from "@humansignal/frontend-test/feature-flags";
import { LabelStudio } from "@humansignal/frontend-test/helpers/LSF/LabelStudio";
import { FF_DEV_3873 } from "../../../../editor/src/utils/feature-flags";

export const ToolBar = {
get root() {
return cy.get(".lsf-topbar");
return LabelStudio.getFeatureFlag(FF_DEV_3873).then((isFFDEV3873) => {
hlomzik marked this conversation as resolved.
Show resolved Hide resolved
if (isFFDEV3873) {
return cy.get(".lsf-bottombar");
}

return cy.get(".lsf-topbar");
});
},

get submitBtn() {
Expand Down
Loading