forked from HumanSignal/label-studio-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: LEAP-240: Prevent creating region on clicking outside selected o…
…ne (HumanSignal#1667) * fix: LEAP-240: Prevent creating region on clicking outside selected one * Add tests for clicking outside selected region * Ensure that unselecting labels and regions was initiated only by click. Updated the handleDeferredMouseDown method to accept a boolean argument that represents whether the mouse was clicked or not. This modification prevents unwanted deselection of regions and labels by ensuring that this event occurs only when the mouse was clicked and deselection is intentional. * Add tests for checking labels behaviour --------- Co-authored-by: Gondragos <[email protected]>
- Loading branch information
1 parent
85598e1
commit 01a12b4
Showing
3 changed files
with
161 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export const rectangleToolAndLabelsConfig = `<View> | ||
<Image name="img" value="$image" /> | ||
<Rectangle name="rect" toName="img" /> | ||
<Labels name="labels" toName="img"> | ||
<Label value="Label 1" background="blue" /> | ||
<Label value="Label 2" background="red" /> | ||
</Labels> | ||
</View>`; | ||
|
||
export const simpleImageData = { | ||
image: 'https://htx-misc.s3.amazonaws.com/opensource/label-studio/examples/images/nick-owuor-astro-nic-visuals-wDifg5xc9Z4-unsplash.jpg', | ||
}; | ||
|
||
export const simpleRectangleResult = [ | ||
{ | ||
'id': 'rect_1', | ||
'original_width': 2242, | ||
'original_height': 2802, | ||
'image_rotation': 0, | ||
'value': { | ||
'x': 20, | ||
'y': 20, | ||
'width': 20, | ||
'height': 20, | ||
'rotation': 0, | ||
}, | ||
'from_name': 'rect', | ||
'to_name': 'img', | ||
'type': 'rectangle', | ||
'origin': 'manual', | ||
}, | ||
]; |
99 changes: 99 additions & 0 deletions
99
tests/functional/specs/image_segmentation/tools/rect.cy.ts
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,99 @@ | ||
import { ImageView, Labels, LabelStudio, Sidebar } from '@heartexlabs/ls-test/helpers/LSF'; | ||
import { | ||
rectangleToolAndLabelsConfig, | ||
simpleImageData, | ||
simpleRectangleResult | ||
} from 'data/image_segmentation/tools/rect'; | ||
import { FF_DEV_1442 } from '../../../../../src/utils/feature-flags'; | ||
|
||
describe('Rectangle tool', () => { | ||
it('should not draw rectangle when clicking outside to unselect (FF_DEV_1442 = true)', () => { | ||
LabelStudio.addFeatureFlagsOnPageLoad({ | ||
[FF_DEV_1442]: true, | ||
}); | ||
|
||
LabelStudio.params() | ||
.config(rectangleToolAndLabelsConfig) | ||
.data(simpleImageData) | ||
.withResult(simpleRectangleResult) | ||
.init(); | ||
|
||
LabelStudio.waitForObjectsReady(); | ||
|
||
Sidebar.hasRegions(1); | ||
Sidebar.toggleRegionSelection(0); | ||
Labels.select('Label 1'); | ||
|
||
ImageView.clickAtRelative(0.5, 0.5); | ||
ImageView.clickAtRelative(0.7, 0.7); | ||
Sidebar.hasRegions(1); | ||
Labels.selectedLabel.should('have.length', 0); | ||
}); | ||
|
||
it('should draw rectangle by dragging (FF_DEV_1442 = true)', () => { | ||
LabelStudio.addFeatureFlagsOnPageLoad({ | ||
[FF_DEV_1442]: true, | ||
}); | ||
|
||
LabelStudio.params() | ||
.config(rectangleToolAndLabelsConfig) | ||
.data(simpleImageData) | ||
.withResult(simpleRectangleResult) | ||
.init(); | ||
|
||
LabelStudio.waitForObjectsReady(); | ||
|
||
Sidebar.hasRegions(1); | ||
Sidebar.toggleRegionSelection(0); | ||
Labels.select('Label 1'); | ||
|
||
ImageView.drawRectRelative(0.5, 0.5, 0.2, 0.2); | ||
Sidebar.hasRegions(2); | ||
Labels.selectedLabel.should('contain.text', 'Label 1'); | ||
}); | ||
|
||
it('should draw rectangle when clicking outside (FF_DEV_1442 = false)', () => { | ||
LabelStudio.addFeatureFlagsOnPageLoad({ | ||
[FF_DEV_1442]: false, | ||
}); | ||
|
||
LabelStudio.params() | ||
.config(rectangleToolAndLabelsConfig) | ||
.data(simpleImageData) | ||
.withResult(simpleRectangleResult) | ||
.init(); | ||
|
||
LabelStudio.waitForObjectsReady(); | ||
|
||
Sidebar.hasRegions(1); | ||
Sidebar.toggleRegionSelection(0); | ||
Labels.select('Label 1'); | ||
|
||
ImageView.clickAtRelative(0.5, 0.5); | ||
ImageView.clickAtRelative(0.7, 0.7); | ||
Sidebar.hasRegions(2); | ||
Labels.selectedLabel.should('contain.text', 'Label 1'); | ||
}); | ||
|
||
it('should draw rectangle by dragging (FF_DEV_1442 = false)', () => { | ||
LabelStudio.addFeatureFlagsOnPageLoad({ | ||
[FF_DEV_1442]: false, | ||
}); | ||
|
||
LabelStudio.params() | ||
.config(rectangleToolAndLabelsConfig) | ||
.data(simpleImageData) | ||
.withResult(simpleRectangleResult) | ||
.init(); | ||
|
||
LabelStudio.waitForObjectsReady(); | ||
|
||
Sidebar.hasRegions(1); | ||
Sidebar.toggleRegionSelection(0); | ||
Labels.select('Label 1'); | ||
|
||
ImageView.drawRectRelative(0.5, 0.5, 0.2, 0.2); | ||
Sidebar.hasRegions(2); | ||
Labels.selectedLabel.should('contain.text', 'Label 1'); | ||
}); | ||
}); |