Skip to content

Commit

Permalink
[781] Update the tests for multiline label
Browse files Browse the repository at this point in the history
Bug: #781
Signed-off-by: Laurent Fasani <[email protected]>
  • Loading branch information
lfasani committed Mar 8, 2022
1 parent 4053982 commit 49212bc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
import org.eclipse.sirius.components.diagrams.description.DiagramDescription;
import org.eclipse.sirius.components.diagrams.events.IDiagramEvent;
import org.eclipse.sirius.components.diagrams.events.SinglePositionEvent;
import org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter;
import org.eclipse.sirius.components.diagrams.layout.ELKLayoutedDiagramProvider;
import org.eclipse.sirius.components.diagrams.layout.IELKDiagramConverter;
import org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry;
import org.eclipse.sirius.components.diagrams.layout.LayoutService;
import org.eclipse.sirius.components.diagrams.layout.TextBoundsService;
import org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider;
import org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider;
import org.eclipse.sirius.components.diagrams.layout.services.DefaultTestDiagramDescriptionProvider;
Expand Down Expand Up @@ -90,8 +91,8 @@ public Optional<IRepresentationDescription> findById(IEditingContext editingCont
NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(new ImageSizeProvider());
IncrementalLayoutEngine incrementalLayoutEngine = new IncrementalLayoutEngine(nodeSizeProvider);

LayoutService layoutService = new LayoutService(new IELKDiagramConverter.NoOp(), new IncrementalLayoutDiagramConverter(), new LayoutConfiguratorRegistry(List.of()),
new ELKLayoutedDiagramProvider(), new IncrementalLayoutedDiagramProvider(), representationDescriptionSearchService, incrementalLayoutEngine);
LayoutService layoutService = new LayoutService(new ELKDiagramConverter(new TextBoundsService(), new ImageSizeProvider()), new IncrementalLayoutDiagramConverter(),
new LayoutConfiguratorRegistry(List.of()), new ELKLayoutedDiagramProvider(), new IncrementalLayoutedDiagramProvider(), representationDescriptionSearchService, incrementalLayoutEngine);

return new TestDiagramCreationService(this.objectService, representationDescriptionSearchService, layoutService);
}
Expand Down Expand Up @@ -159,4 +160,40 @@ public void testSimpleDiagramLayout() throws IOException {
Node layoutedThirdParent = optionalLayoutedThirdParent.get();
assertThat(layoutedThirdParent.getPosition()).isEqualTo(Position.at(301, 101));
}

@Test
public void testNodeLayoutWithMultilineLabel() throws IOException {
String nodeLabelWithMultiple = "First LineAAAAAAAA\nSecond LineBBBBBBBBB"; //$NON-NLS-1$
String firstChildTargetObjectId = "First child"; //$NON-NLS-1$

// @formatter:off
Diagram diagram = TestLayoutDiagramBuilder.diagram("Root") //$NON-NLS-1$
.nodes()
.rectangleNode(nodeLabelWithMultiple).at(10, 10).of(10, 10)
.childNodes()
.rectangleNode(firstChildTargetObjectId).at(10, 10).of(50, 50).and()
.and()
.and()
.and()
.build();
// @formatter:on

Path path = Paths.get("src", "test", "resources", "editing-contexts", "testSimpleDiagramLayout"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$
JsonBasedEditingContext editingContext = new JsonBasedEditingContext(path);

TestDiagramCreationService diagramCreationService = this.createDiagramCreationService(diagram);

Diagram layoutedDiagram = diagramCreationService.performElKLayout(editingContext, diagram);

Optional<Node> optionalFirstParent = this.getNode(layoutedDiagram.getNodes(), nodeLabelWithMultiple);
assertThat(optionalFirstParent).isPresent();
Node firstParent = optionalFirstParent.get();

// Check that the parent node and the label have the right size
assertThat(firstParent.getSize()).isEqualTo(Size.of(195.8818359375, 131.197265625));
assertThat(firstParent.getLabel().getSize()).isEqualTo(Size.of(161.8818359375, 32.197265625));

// Check that the inner node is under the multi line label area
assertThat(firstParent.getChildNodes().get(0).getPosition()).isEqualTo(Position.at(12, 49.197265625));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testNodeImageLabelBoundsPosition() {
LabelLayoutData labelLayoutData = this.createLabelLayoutData();

Position position = labelBoundsProvider.getPosition(nodeLayoutData, labelLayoutData);
assertThat(position).extracting(Position::getX).isEqualTo(Double.valueOf(42.5390625));
assertThat(position).extracting(Position::getX).isEqualTo(Double.valueOf(DEFAULT_NODE_SIZE.getWidth() / 2));
assertThat(position).extracting(Position::getY).isEqualTo(Double.valueOf(-23.3984375));
}

Expand All @@ -73,7 +73,7 @@ public void testNodeRectangleLabelBoundsPosition() {
NodeLabelPositionProvider labelBoundsProvider = new NodeLabelPositionProvider(new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator());
LabelLayoutData labelLayoutData = this.createLabelLayoutData();
Position position = labelBoundsProvider.getPosition(nodeLayoutData, labelLayoutData);
assertThat(position).extracting(Position::getX).isEqualTo(Double.valueOf(42.5390625));
assertThat(position).extracting(Position::getX).isEqualTo(Double.valueOf(DEFAULT_NODE_SIZE.getWidth() / 2));
assertThat(position).extracting(Position::getY).isEqualTo(Double.valueOf(5));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ public Diagram performLayout(IEditingContext editingContext, Diagram diagram, ID
return this.layoutService.incrementalLayout(editingContext, diagram, Optional.of(diagramEvent));
}

public Diagram performElKLayout(IEditingContext editingContext, Diagram diagram) {
return this.layoutService.layout(editingContext, diagram);
}

}

0 comments on commit 49212bc

Please sign in to comment.