|
17 | 17 |
|
18 | 18 | import java.text.MessageFormat; |
19 | 19 | import java.time.Duration; |
| 20 | +import java.util.List; |
20 | 21 | import java.util.Objects; |
21 | 22 | import java.util.Optional; |
22 | 23 | import java.util.UUID; |
|
28 | 29 | import org.eclipse.sirius.components.diagrams.Diagram; |
29 | 30 | import org.eclipse.sirius.components.diagrams.Node; |
30 | 31 | import org.eclipse.sirius.components.diagrams.ViewModifier; |
| 32 | +import org.eclipse.sirius.components.diagrams.tests.navigation.DiagramNavigator; |
31 | 33 | import org.eclipse.sirius.components.view.emf.diagram.IDiagramIdProvider; |
32 | 34 | import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; |
33 | 35 | import org.eclipse.syson.AbstractIntegrationTests; |
34 | 36 | import org.eclipse.syson.GivenSysONServer; |
35 | 37 | import org.eclipse.syson.application.controllers.diagrams.testers.ToolTester; |
| 38 | +import org.eclipse.syson.application.data.GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData; |
36 | 39 | import org.eclipse.syson.application.data.GeneralViewAddExistingElementsTestProjectData; |
37 | 40 | import org.eclipse.syson.services.diagrams.DiagramDescriptionIdProvider; |
38 | 41 | import org.eclipse.syson.services.diagrams.api.IGivenDiagramDescription; |
39 | 42 | import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription; |
| 43 | +import org.eclipse.syson.standard.diagrams.view.SDVDescriptionNameGenerator; |
| 44 | +import org.eclipse.syson.sysml.SysmlPackage; |
| 45 | +import org.eclipse.syson.sysml.helper.LabelConstants; |
| 46 | +import org.eclipse.syson.util.IDescriptionNameGenerator; |
40 | 47 | import org.eclipse.syson.util.SysONRepresentationDescriptionIdentifiers; |
41 | 48 | import org.junit.jupiter.api.BeforeEach; |
| 49 | +import org.junit.jupiter.api.DisplayName; |
42 | 50 | import org.junit.jupiter.api.Test; |
43 | 51 | import org.springframework.beans.factory.annotation.Autowired; |
44 | 52 | import org.springframework.boot.test.context.SpringBootTest; |
@@ -87,6 +95,8 @@ public class GVAddExistingElementsTests extends AbstractIntegrationTests { |
87 | 95 | @Autowired |
88 | 96 | private ToolTester nodeCreationTester; |
89 | 97 |
|
| 98 | + private final IDescriptionNameGenerator descriptionNameGenerator = new SDVDescriptionNameGenerator(); |
| 99 | + |
90 | 100 | private Flux<DiagramRefreshedEventPayload> givenSubscriptionToDiagram() { |
91 | 101 | var diagramEventInput = new DiagramEventInput(UUID.randomUUID(), |
92 | 102 | GeneralViewAddExistingElementsTestProjectData.EDITING_CONTEXT_ID, |
@@ -153,10 +163,10 @@ public void addExistingElementsRecursiveOnDiagram() { |
153 | 163 |
|
154 | 164 | Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(diagram::set); |
155 | 165 |
|
156 | | - String creationToolId = diagramDescriptionIdProvider.getDiagramCreationToolId("Add existing elements (recursive)"); |
157 | | - assertThat(creationToolId).as("The tool 'Add existing elements (recursive)' should exist on the diagram").isNotNull(); |
| 166 | + String addExistingElementToolId = diagramDescriptionIdProvider.getDiagramCreationToolId("Add existing elements (recursive)"); |
| 167 | + assertThat(addExistingElementToolId).as("The tool 'Add existing elements (recursive)' should exist on the diagram").isNotNull(); |
158 | 168 |
|
159 | | - Runnable nodeCreationRunner = () -> this.nodeCreationTester.invokeTool(GeneralViewAddExistingElementsTestProjectData.EDITING_CONTEXT_ID, diagram, creationToolId); |
| 169 | + Runnable addExistingElementTool = () -> this.nodeCreationTester.invokeTool(GeneralViewAddExistingElementsTestProjectData.EDITING_CONTEXT_ID, diagram, addExistingElementToolId); |
160 | 170 |
|
161 | 171 | Consumer<Object> updatedDiagramConsumer = assertRefreshedDiagramThat(newDiagram -> { |
162 | 172 | assertThat(newDiagram.getNodes()).as("6 nodes should be visible on the diagram").hasSize(7); |
@@ -196,7 +206,56 @@ public void addExistingElementsRecursiveOnDiagram() { |
196 | 206 |
|
197 | 207 | StepVerifier.create(flux) |
198 | 208 | .consumeNextWith(initialDiagramContentConsumer) |
199 | | - .then(nodeCreationRunner) |
| 209 | + .then(addExistingElementTool) |
| 210 | + .consumeNextWith(updatedDiagramConsumer) |
| 211 | + .thenCancel() |
| 212 | + .verify(Duration.ofSeconds(10)); |
| 213 | + } |
| 214 | + |
| 215 | + @DisplayName("GIVEN an ActionUsage with its action flow compartment displayed and a nested ActionUsage in it, WHEN Delete from diagram the nested ActionUsage then use the Add existing element tool on the action flow compartment, THEN the nested ActionUsage should only be displayed in the action flow compartment") |
| 216 | + @GivenSysONServer({ GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData.SCRIPT_PATH }) |
| 217 | + @Test |
| 218 | + public void addExistingElementsOnActionFlowCompartment() { |
| 219 | + var flux = this.givenSubscriptionToDiagram(); |
| 220 | + |
| 221 | + var diagramDescription = this.givenDiagramDescription.getDiagramDescription(GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData.EDITING_CONTEXT_ID, |
| 222 | + SysONRepresentationDescriptionIdentifiers.GENERAL_VIEW_DIAGRAM_DESCRIPTION_ID); |
| 223 | + var diagramDescriptionIdProvider = new DiagramDescriptionIdProvider(diagramDescription, this.diagramIdProvider); |
| 224 | + |
| 225 | + AtomicReference<Diagram> diagram = new AtomicReference<>(); |
| 226 | + |
| 227 | + Consumer<Object> initialDiagramContentConsumer = assertRefreshedDiagramThat(initialDiagram -> { |
| 228 | + diagram.set(initialDiagram); |
| 229 | + |
| 230 | + assertThat(initialDiagram.getNodes()).hasSize(1); |
| 231 | + |
| 232 | + var action1ActionFlowCompartmentNode = new DiagramNavigator(initialDiagram).nodeWithLabel(LabelConstants.OPEN_QUOTE + "action" + LabelConstants.CLOSE_QUOTE + LabelConstants.CR + "action1") |
| 233 | + .childNodeWithLabel("action flow").getNode(); |
| 234 | + assertThat(action1ActionFlowCompartmentNode.getChildNodes()).isEmpty(); |
| 235 | + }); |
| 236 | + |
| 237 | + String addExistingElementToolId = diagramDescriptionIdProvider.getNodeToolId( |
| 238 | + this.descriptionNameGenerator.getFreeFormCompartmentName(SysmlPackage.eINSTANCE.getActionUsage(), SysmlPackage.eINSTANCE.getUsage_NestedAction()), "Add existing elements"); |
| 239 | + |
| 240 | + Runnable addExistingElementTool = () -> this.nodeCreationTester.invokeTool(GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData.EDITING_CONTEXT_ID, diagram.get().getId(), |
| 241 | + GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData.GraphicalIds.ACTION_1_ACTIONFLOW_COMPARTMENT_NODE_ID, addExistingElementToolId, List.of()); |
| 242 | + |
| 243 | + Consumer<Object> updatedDiagramConsumer = assertRefreshedDiagramThat(newDiagram -> { |
| 244 | + assertThat(newDiagram.getNodes()).hasSize(2); |
| 245 | + |
| 246 | + var action1ActionFlowCompartmentNode = new DiagramNavigator(newDiagram).nodeWithLabel(LabelConstants.OPEN_QUOTE + "action" + LabelConstants.CLOSE_QUOTE + LabelConstants.CR + "action1") |
| 247 | + .childNodeWithLabel("action flow").getNode(); |
| 248 | + var childNodes = action1ActionFlowCompartmentNode.getChildNodes(); |
| 249 | + assertThat(childNodes).hasSize(1); |
| 250 | + assertThat(childNodes.get(0).getTargetObjectId()).isEqualTo(GeneralViewAddExistingElementsActionFlowCompartmentTestProjectData.SemanticIds.ACTION_2_ID); |
| 251 | + |
| 252 | + var action2HiddenNode = new DiagramNavigator(newDiagram).nodeWithLabel(LabelConstants.OPEN_QUOTE + "action" + LabelConstants.CLOSE_QUOTE + LabelConstants.CR + "action2").getNode(); |
| 253 | + assertThat(action2HiddenNode.getModifiers()).contains(ViewModifier.Hidden); |
| 254 | + }); |
| 255 | + |
| 256 | + StepVerifier.create(flux) |
| 257 | + .consumeNextWith(initialDiagramContentConsumer) |
| 258 | + .then(addExistingElementTool) |
200 | 259 | .consumeNextWith(updatedDiagramConsumer) |
201 | 260 | .thenCancel() |
202 | 261 | .verify(Duration.ofSeconds(10)); |
|
0 commit comments