Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* global Feature, Scenario */
 
const { doDrawingAction } = require("./helpers");
 
Feature("Test Image Region Stay Selected Between Tools");
 
const OUTLINER_PANEL_WIDTH = 319;
 
const PLANET = {
  color: "#00FF00",
  rgbArray: [0, 255, 0],
};
const MOONWALKER = {
  color: "#0000FF",
  rgbArray: [0, 0, 255],
};
 
const config = `
  <View>
    <Image name="image" value="$image" crossOrigin="anonymous" />
    <Brush name="brush" toName="image" />
    <MagicWand name="magicwand" toName="image" />
    <Labels name="labels" toName="image" fillOpacity="0.5" strokeWidth="5">
      <Label value="Planet" background="${PLANET.color}"></Label>
      <Label value="Moonwalker" background="${MOONWALKER.color}"></Label>
    </Labels>
  </View>`;
 
const annotationEmpty = {
  id: "1000",
  result: [],
};
 
const data = {
  image:
    "https://htx-pub.s3.us-east-1.amazonaws.com/examples/images/nick-owuor-astro-nic-visuals-wDifg5xc9Z4-unsplash.jpg",
};
 
async function testRegion(testType, toolAccelerator, I, LabelStudio, AtImageView, AtOutliner) {
  const params = {
    config,
    data,
    annotations: [annotationEmpty],
  };
 
  I.amOnPage("/");
 
  LabelStudio.init(params);
 
  LabelStudio.waitForObjectsReady();
  await AtImageView.lookForStage();
 
  I.say(`Select ${testType} & planet class`);
  I.pressKey(toolAccelerator);
  I.pressKey("1");
 
  I.say("There should be no regions initially");
  AtOutliner.seeRegions(0);
 
  I.say(`${testType} initial region`);
  await doDrawingAction(I, {
    msg: `Initial ${testType}`,
    fromX: OUTLINER_PANEL_WIDTH + 150,
    fromY: 115,
    toX: OUTLINER_PANEL_WIDTH + 150 + 50,
    toY: 115 + 50,
  });
 
  I.say("There should now be a single region");
  AtOutliner.seeRegions(1);
 
  I.say(`Using Eraser on ${testType} region`);
  I.pressKey("E");
  I.usePlaywrightTo("Erasing", async ({ browser, browserContext, page }) => {
    await page.mouse.move(OUTLINER_PANEL_WIDTH + 150, 150);
    await page.mouse.down();
    await page.mouse.move(OUTLINER_PANEL_WIDTH + 150 + 100, 150);
    await page.mouse.up();
  });
 
  I.say(`Doing another ${testType} with same class after erasing`);
  I.pressKey(toolAccelerator);
  await doDrawingAction(I, {
    msg: `${testType} after erasing`,
    fromX: OUTLINER_PANEL_WIDTH + 280,
    fromY: 480,
    toX: OUTLINER_PANEL_WIDTH + 280 + 50,
    toY: 480 + 50,
  });
 
  I.say("There should still only be one region");
  AtOutliner.seeRegions(1);
 
  I.say("Zooming and selecting pan tool");
  I.click('button[aria-label="zoom-in"]');
  I.click('button[aria-label="zoom-in"]');
  I.pressKey("H");
 
  I.say(`Doing another ${testType} after zooming and selecting pan tool`);
  I.pressKey(toolAccelerator);
  await doDrawingAction(I, {
    msg: `${testType} after zoom and pan selected`,
    fromX: OUTLINER_PANEL_WIDTH + 400,
    fromY: 200,
    toX: OUTLINER_PANEL_WIDTH + 400 + 15,
    toY: 400 + 15,
  });
 
  I.say("There should still only be one region");
  AtOutliner.seeRegions(1);
}
 
Scenario("Selected brush region should stay between tools", async ({ I, LabelStudio, AtImageView, AtOutliner }) => {
  await testRegion("brush", "B", I, LabelStudio, AtImageView, AtOutliner);
});
 
Scenario(
  "Selected Magic Wand region should stay between tools",
  async ({ I, LabelStudio, AtImageView, AtOutliner }) => {
    await testRegion("magicwand", "W", I, LabelStudio, AtImageView, AtOutliner);
  },
);