image.selected-region.test.js 3.3 KB

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