forked from eclipse-sirius/sirius-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4095] Add conditional tree item label element description
Bug: eclipse-sirius#4095 Signed-off-by: Jerome Gout <[email protected]>
- Loading branch information
1 parent
75f2a22
commit c223237
Showing
37 changed files
with
2,389 additions
and
1,481 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
...pse/sirius/web/application/controllers/trees/TreeItemLabelDescriptionControllerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.controllers.trees; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
import com.jayway.jsonpath.JsonPath; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.Consumer; | ||
|
||
import org.eclipse.sirius.components.collaborative.trees.dto.TreeRefreshedEventPayload; | ||
import org.eclipse.sirius.components.core.api.labels.StyledString; | ||
import org.eclipse.sirius.components.trees.Tree; | ||
import org.eclipse.sirius.components.trees.TreeItem; | ||
import org.eclipse.sirius.web.AbstractIntegrationTests; | ||
import org.eclipse.sirius.web.application.views.explorer.ExplorerEventInput; | ||
import org.eclipse.sirius.web.application.views.explorer.services.ExplorerDescriptionProvider; | ||
import org.eclipse.sirius.web.data.StudioIdentifiers; | ||
import org.eclipse.sirius.web.tests.graphql.ExplorerDescriptionsQueryRunner; | ||
import org.eclipse.sirius.web.tests.graphql.FetchTreeItemContextMenuEntryDataQueryRunner; | ||
import org.eclipse.sirius.web.tests.graphql.SingleClickTreeItemContextMenuEntryMutationRunner; | ||
import org.eclipse.sirius.web.tests.graphql.TreeItemContextMenuQueryRunner; | ||
import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; | ||
import org.eclipse.sirius.web.tests.services.explorer.ExplorerEventSubscriptionRunner; | ||
import org.eclipse.sirius.web.tests.services.representation.RepresentationIdBuilder; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import org.springframework.test.context.jdbc.SqlConfig; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import graphql.execution.DataFetcherResult; | ||
import reactor.test.StepVerifier; | ||
|
||
/** | ||
* Integration tests of the tree item label description controllers. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@Transactional | ||
@SuppressWarnings("checkstyle:MultipleStringLiterals") | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "sirius.web.test.enabled=studio" }) | ||
public class TreeItemLabelDescriptionControllerTests extends AbstractIntegrationTests { | ||
|
||
private static final String ROOT_ENTITY_ID = "c341bf91-d315-4264-9787-c51b121a6375"; | ||
|
||
@Autowired | ||
private IGivenInitialServerState givenInitialServerState; | ||
|
||
@Autowired | ||
private TreeItemContextMenuQueryRunner treeItemContextMenuQueryRunner; | ||
|
||
@Autowired | ||
private FetchTreeItemContextMenuEntryDataQueryRunner treeItemFetchContextActionDataQueryRunner; | ||
|
||
@Autowired | ||
private SingleClickTreeItemContextMenuEntryMutationRunner singleClickTreeItemContexteMenuEntryMutationRunner; | ||
|
||
@Autowired | ||
private RepresentationIdBuilder representationIdBuilder; | ||
|
||
@Autowired | ||
private ExplorerEventSubscriptionRunner explorerEventSubscriptionRunner; | ||
|
||
@Autowired | ||
private ExplorerDescriptionsQueryRunner explorerDescriptionsQueryRunner; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
this.givenInitialServerState.initialize(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Given a studio, when the tree item labels are requested, then the correct styles are returned") | ||
@Sql(scripts = { "/scripts/studio.sql" }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) | ||
public void givenAStudioWhenTheTreeItemLabelsAreRequestedThenTheCorrectStylesAreReturned() { | ||
|
||
// 1- retrieve the tree description id of the DSL Domain explorer example | ||
var explorerDescriptionId = new AtomicReference<String>(); | ||
|
||
Map<String, Object> explorerVariables = Map.of( | ||
"editingContextId", StudioIdentifiers.SAMPLE_STUDIO_PROJECT.toString() | ||
); | ||
var explorerResult = TreeItemLabelDescriptionControllerTests.this.explorerDescriptionsQueryRunner.run(explorerVariables); | ||
List<String> explorerIds = JsonPath.read(explorerResult, "$.data.viewer.editingContext.explorerDescriptions[*].id"); | ||
assertThat(explorerIds).isNotEmpty() | ||
.hasSize(2); | ||
assertThat(explorerIds.get(0)).isEqualTo(ExplorerDescriptionProvider.DESCRIPTION_ID); | ||
assertThat(explorerIds.get(1)).startsWith("siriusComponents://representationDescription?kind=treeDescription"); | ||
explorerDescriptionId.set(explorerIds.get(1)); | ||
|
||
var explorerRepresentationId = this.representationIdBuilder.buildExplorerRepresentationId(explorerDescriptionId.get(), | ||
List.of(StudioIdentifiers.DOMAIN_DOCUMENT.toString(), StudioIdentifiers.DOMAIN_OBJECT.toString(), ROOT_ENTITY_ID), List.of()); | ||
|
||
// 2- check that styles are properly applied | ||
// - check that the ROOT entity has not the abstract style applied. | ||
// - check that the NamedElement entity has the abstract style (if style) | ||
var inputStyle = new ExplorerEventInput(UUID.randomUUID(), StudioIdentifiers.SAMPLE_STUDIO_PROJECT.toString(), explorerRepresentationId); | ||
var fluxStyle = this.explorerEventSubscriptionRunner.run(inputStyle); | ||
|
||
Consumer<Object> styleTreeContentConsumer = this.getTreeSubscriptionConsumer(tree -> { | ||
assertThat(tree).isNotNull(); | ||
List<TreeItem> domainChildren = tree.getChildren() | ||
.get(0) | ||
.getChildren() | ||
.get(0) | ||
.getChildren(); | ||
StyledString rootLabel = domainChildren.get(0).getLabel(); | ||
StyledString namedElementLabel = domainChildren.get(1).getLabel(); | ||
assertThat(rootLabel.styledStringFragments()).hasSize(2); | ||
assertThat(namedElementLabel.styledStringFragments()).hasSize(3); | ||
assertThat(namedElementLabel.toString()).isEqualTo("[Entity] NamedElement [abstract]"); | ||
}); | ||
|
||
StepVerifier.create(fluxStyle) | ||
.consumeNextWith(styleTreeContentConsumer) | ||
.thenCancel() | ||
.verify(Duration.ofSeconds(30)); | ||
} | ||
|
||
private Consumer<Object> getTreeSubscriptionConsumer(Consumer<Tree> treeConsumer) { | ||
return object -> Optional.of(object) | ||
.filter(DataFetcherResult.class::isInstance) | ||
.map(DataFetcherResult.class::cast) | ||
.map(DataFetcherResult::getData) | ||
.filter(TreeRefreshedEventPayload.class::isInstance) | ||
.map(TreeRefreshedEventPayload.class::cast) | ||
.map(TreeRefreshedEventPayload::tree) | ||
.ifPresentOrElse(treeConsumer, () -> fail("Missing tree")); | ||
} | ||
} |
Oops, something went wrong.