Skip to content

Commit

Permalink
test: Add region index tests and enhance LSF test helpers
Browse files Browse the repository at this point in the history
Added new utility methods for handling regions, labels, and localStorage in LSF helpers. Introduced customizable callbacks for `init` and improved functionality for ordering and deleting regions in the Sidebar.
  • Loading branch information
Gondragos committed Jan 23, 2025
1 parent ace6705 commit 66e8b69
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
21 changes: 18 additions & 3 deletions web/libs/frontend-test/src/helpers/LSF/LabelStudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ class LSParamsBuilder {
predictions: [],
},
};
private _localStorageItems: Record<string, any> = {};
private ls: typeof LabelStudio = null;

constructor(ls: typeof LabelStudio) {
this.ls = ls;
}

init() {
this.ls.init(this.params);
init(beforeLoadCallback?: (win: Cypress.AUTWindow) => void) {
this.ls.init(this.params, (win) => {
Object.entries(this._localStorageItems).forEach(([key, value]) => {
win.localStorage.setItem(key, JSON.stringify(value));
});
beforeLoadCallback?.(win);
});
}

private get _task() {
Expand Down Expand Up @@ -125,13 +131,21 @@ class LSParamsBuilder {
this.params[paramName] = paramValue;
return this;
}
localStorageItems(items) {
this._localStorageItems = items;
return this;
}
withLocalStorageItem(key, value) {
this._localStorageItems[key] = value;
return this;
}
}

export const LabelStudio = {
/**
* Initializes LabelStudio instance with given configuration
*/
init(params: LSParams) {
init(params: LSParams, beforeLoadCallback?: (win: Cypress.AUTWindow) => void) {
cy.log("Initialize LSF");
const windowLoadCallback = (win: Cypress.AUTWindow) => {
win.DEFAULT_LSF_INIT = false;
Expand Down Expand Up @@ -160,6 +174,7 @@ export const LabelStudio = {
],
...params,
};
beforeLoadCallback?.(win);

Cypress.off("window:before:load", windowLoadCallback);
};
Expand Down
6 changes: 6 additions & 0 deletions web/libs/frontend-test/src/helpers/LSF/Relations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export const Relations = {

return cy.wrap(relationList);
},
get relationItems() {
return this.relations.find(".lsf-relations__item");
},
get relationRegions() {
return this.relationItems.find(".lsf-detailed-region");
},
get hideAllRelationsButton() {
return cy.get('[aria-label="Hide all"]');
},
Expand Down
11 changes: 10 additions & 1 deletion web/libs/frontend-test/src/helpers/LSF/RichText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,17 @@ class RichTextHelper {
});
});
}
findRegionWithText(text) {
return this.content.find(".htx-highlight").contains(text);
}
hasRegionWithText(text) {
this.content.find(".htx-highlight").contains(text).should("exist");
this.findRegionWithText(text).should("exist");
}
findRegionWithLabel(label) {
return this.content.find(`.htx-highlight[data-label='${label}']`);
}
hasRegionWithLabel(label) {
this.findRegionWithLabel(label).should("exist");
}
}

Expand Down
19 changes: 19 additions & 0 deletions web/libs/frontend-test/src/helpers/LSF/Sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export const Sidebar = {
get showAllRegionsButton() {
return this.toolBar.get('[aria-label="Show all regions"]');
},
get orderRegionsButton() {
return this.toolBar.get(".lsf-view-controls__sort button");
},
toggleOrderByTime() {
this.orderRegionsButton.click();
cy.get(".lsf-dropdown").contains("Order by Time").parent().click();
// Cypress is bad at events emitting, so this is a hack to close the panel that
// would be closed if the same action is done by a real person
this.orderRegionsButton.click();
},
get regions() {
return LabelStudio.getFeatureFlag(FF_DEV_1170).then((isFFDEV1170) => {
if (isFFDEV1170) {
Expand All @@ -34,6 +44,12 @@ export const Sidebar = {
findRegionByIndex(idx: number) {
return this.findRegion(`:eq(${idx})`);
},
findByRegionIndex(idx: number) {
return this.regions
.find(".lsf-outliner-item__index")
.filter(`:contains("${idx}")`)
.parents(".lsf-tree-node-content-wrapper");
},
get hiddenRegions() {
return this.outliner.should("be.visible").get(".lsf-tree__node_hidden .lsf-tree-node-content-wrapper");
},
Expand Down Expand Up @@ -77,4 +93,7 @@ export const Sidebar = {
expandDetailsRightPanel() {
cy.get(".lsf-sidepanels__wrapper_align_right .lsf-panel__header").should("be.visible").click();
},
deleteSelectedRegionsWithHotkey() {
cy.get("body").type("{backspace}");
},
};

0 comments on commit 66e8b69

Please sign in to comment.