|
| 1 | +import { ImageView, LabelStudio, Relations, Sidebar } from '@heartexlabs/ls-test/helpers/LSF'; |
| 2 | + |
| 3 | +const config = ` |
| 4 | + <View> |
| 5 | + <Image name="img" value="$image"></Image> |
| 6 | + <RectangleLabels name="tag" toName="img"> |
| 7 | + <Label value="Planet"></Label> |
| 8 | + <Label value="Moonwalker" background="blue"></Label> |
| 9 | + <Label value="Moonwalker 1" background="red"></Label> |
| 10 | + <Label value="Moonwalker 2" background="pink"></Label> |
| 11 | + <Label value="Moonwalker 3" background="yellow"></Label> |
| 12 | + </RectangleLabels> |
| 13 | + </View> |
| 14 | +`; |
| 15 | + |
| 16 | +const image = |
| 17 | + 'https://htx-misc.s3.amazonaws.com/opensource/label-studio/examples/images/nick-owuor-astro-nic-visuals-wDifg5xc9Z4-unsplash.jpg'; |
| 18 | + |
| 19 | +const task = { |
| 20 | + id: 1, |
| 21 | + annotations: [ |
| 22 | + { |
| 23 | + id: 1001, |
| 24 | + result: [ |
| 25 | + { |
| 26 | + id: 'Dx_aB91ISN', |
| 27 | + source: '$image', |
| 28 | + from_name: 'tag', |
| 29 | + to_name: 'img', |
| 30 | + type: 'rectanglelabels', |
| 31 | + origin: 'manual', |
| 32 | + value: { |
| 33 | + height: 10.458911419423693, |
| 34 | + rotation: 0, |
| 35 | + width: 12.4, |
| 36 | + x: 50.8, |
| 37 | + y: 5.866, |
| 38 | + rectanglelabels: ['Moonwalker'], |
| 39 | + }, |
| 40 | + }, |
| 41 | + { |
| 42 | + id: 'Dx_aB91INs', |
| 43 | + source: '$image', |
| 44 | + from_name: 'tag', |
| 45 | + to_name: 'img', |
| 46 | + type: 'rectanglelabels', |
| 47 | + origin: 'manual', |
| 48 | + value: { |
| 49 | + height: 10.458911419423693, |
| 50 | + rotation: 0, |
| 51 | + width: 12.4, |
| 52 | + x: 50.8, |
| 53 | + y: 25.866, |
| 54 | + rectanglelabels: ['Moonwalker 2'], |
| 55 | + }, |
| 56 | + }, |
| 57 | + { |
| 58 | + id: 'Dx_aB91ANs', |
| 59 | + source: '$image', |
| 60 | + from_name: 'tag', |
| 61 | + to_name: 'img', |
| 62 | + type: 'rectanglelabels', |
| 63 | + origin: 'manual', |
| 64 | + value: { |
| 65 | + height: 10.458911419423693, |
| 66 | + rotation: 0, |
| 67 | + width: 12.4, |
| 68 | + x: 50.8, |
| 69 | + y: 45.866, |
| 70 | + rectanglelabels: ['Moonwalker 3'], |
| 71 | + }, |
| 72 | + }, |
| 73 | + { |
| 74 | + id: 'Dx_aB19ISN', |
| 75 | + source: '$image', |
| 76 | + from_name: 'tag', |
| 77 | + to_name: 'img', |
| 78 | + type: 'rectanglelabels', |
| 79 | + origin: 'manual', |
| 80 | + value: { |
| 81 | + height: 10.458911419423693, |
| 82 | + rotation: 0, |
| 83 | + width: 12.4, |
| 84 | + x: 50.8, |
| 85 | + y: 65.866, |
| 86 | + rectanglelabels: ['Planet'], |
| 87 | + }, |
| 88 | + }, |
| 89 | + ], |
| 90 | + }, |
| 91 | + ], |
| 92 | + predictions: [], |
| 93 | + data: { image }, |
| 94 | +}; |
| 95 | + |
| 96 | +describe('Relations: Image Rectangle Regions', () => { |
| 97 | + it('Check hotkeys work with the relations action button visible', () => { |
| 98 | + LabelStudio.init({ |
| 99 | + config, |
| 100 | + task, |
| 101 | + }); |
| 102 | + |
| 103 | + Relations.hasRelations(0); |
| 104 | + |
| 105 | + // Select the first region |
| 106 | + Sidebar.toggleRegionSelection(0); |
| 107 | + |
| 108 | + // Check that the hotkeys work |
| 109 | + Relations.toggleCreationWithHotkey(); |
| 110 | + |
| 111 | + // Select the second region |
| 112 | + ImageView.clickAtRelative(0.51, 0.26); |
| 113 | + |
| 114 | + // Check that the region is created in the relations panel |
| 115 | + Relations.hasRelations(1); |
| 116 | + Relations.hasRelation('Moonwalker', 'Moonwalker 2'); |
| 117 | + |
| 118 | + // Reslect the first region and create a relation with the third region |
| 119 | + ImageView.clickAtRelative(0.51, 0.06); |
| 120 | + |
| 121 | + Relations.toggleCreation(); |
| 122 | + |
| 123 | + // Select the third region |
| 124 | + ImageView.clickAtRelative(0.51, 0.46); |
| 125 | + |
| 126 | + // Check that the region is created in the relations panel |
| 127 | + Relations.hasRelations(2); |
| 128 | + Relations.hasRelation('Moonwalker', 'Moonwalker 3'); |
| 129 | + |
| 130 | + // Create a relation between the last region and the first |
| 131 | + ImageView.clickAtRelative(0.51, 0.66); |
| 132 | + |
| 133 | + Relations.toggleCreation(); |
| 134 | + |
| 135 | + ImageView.clickAtRelative(0.51, 0.06); |
| 136 | + |
| 137 | + // Check that the region is created in the relations panel |
| 138 | + Relations.hasRelations(3); |
| 139 | + Relations.hasRelation('Planet', 'Moonwalker'); |
| 140 | + }); |
| 141 | + |
| 142 | + it('Check hotkeys work without the relations action button visible', () => { |
| 143 | + LabelStudio.init({ |
| 144 | + config, |
| 145 | + task, |
| 146 | + }); |
| 147 | + |
| 148 | + Relations.hasRelations(0); |
| 149 | + |
| 150 | + // With the relations action button not visible |
| 151 | + Sidebar.collapseDetailsRightPanel(); |
| 152 | + |
| 153 | + // Select the first region |
| 154 | + Sidebar.toggleRegionSelection(0); |
| 155 | + |
| 156 | + // Check that the hotkeys work |
| 157 | + Relations.toggleCreationWithHotkey(); |
| 158 | + |
| 159 | + // Select the second region |
| 160 | + ImageView.clickAtRelative(0.51, 0.26); |
| 161 | + |
| 162 | + // Check that the region is created in the relations panel |
| 163 | + Sidebar.expandDetailsRightPanel(); |
| 164 | + Relations.hasRelations(1); |
| 165 | + Relations.hasRelation('Moonwalker', 'Moonwalker 2'); |
| 166 | + |
| 167 | + // Reslect the first region and create a relation with the third region |
| 168 | + ImageView.clickAtRelative(0.51, 0.06); |
| 169 | + |
| 170 | + Relations.toggleCreation(); |
| 171 | + |
| 172 | + // Select the third region |
| 173 | + ImageView.clickAtRelative(0.51, 0.46); |
| 174 | + |
| 175 | + // Check that the region is created in the relations panel |
| 176 | + Relations.hasRelations(2); |
| 177 | + Relations.hasRelation('Moonwalker', 'Moonwalker 3'); |
| 178 | + |
| 179 | + // Create a relation between the last region and the first |
| 180 | + ImageView.clickAtRelative(0.51, 0.66); |
| 181 | + |
| 182 | + Relations.toggleCreation(); |
| 183 | + |
| 184 | + ImageView.clickAtRelative(0.51, 0.06); |
| 185 | + |
| 186 | + // Check that the region is created in the relations panel |
| 187 | + Relations.hasRelations(3); |
| 188 | + Relations.hasRelation('Planet', 'Moonwalker'); |
| 189 | + }); |
| 190 | +}); |
0 commit comments