|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2025 Obeo. |
| 3 | + * This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v2.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * Obeo - initial API and implementation |
| 12 | + *******************************************************************************/ |
| 13 | +package org.eclipse.syson.application.controllers.details.view; |
| 14 | + |
| 15 | +import static org.assertj.core.api.Assertions.assertThat; |
| 16 | +import static org.assertj.core.api.Assertions.fail; |
| 17 | + |
| 18 | +import java.time.Duration; |
| 19 | +import java.util.List; |
| 20 | +import java.util.Optional; |
| 21 | +import java.util.UUID; |
| 22 | +import java.util.function.Consumer; |
| 23 | + |
| 24 | +import org.eclipse.sirius.components.collaborative.forms.dto.FormRefreshedEventPayload; |
| 25 | +import org.eclipse.sirius.components.forms.LabelWidget; |
| 26 | +import org.eclipse.sirius.components.forms.Textfield; |
| 27 | +import org.eclipse.sirius.components.forms.tests.navigation.FormNavigator; |
| 28 | +import org.eclipse.sirius.web.application.views.details.dto.DetailsEventInput; |
| 29 | +import org.eclipse.sirius.web.tests.graphql.DetailsEventSubscriptionRunner; |
| 30 | +import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; |
| 31 | +import org.eclipse.sirius.web.tests.services.representation.RepresentationIdBuilder; |
| 32 | +import org.eclipse.syson.AbstractIntegrationTests; |
| 33 | +import org.eclipse.syson.application.data.SimpleProjectElementsTestProjectData; |
| 34 | +import org.junit.jupiter.api.BeforeEach; |
| 35 | +import org.junit.jupiter.api.DisplayName; |
| 36 | +import org.junit.jupiter.api.Test; |
| 37 | +import org.springframework.beans.factory.annotation.Autowired; |
| 38 | +import org.springframework.boot.test.context.SpringBootTest; |
| 39 | +import org.springframework.test.context.jdbc.Sql; |
| 40 | +import org.springframework.test.context.jdbc.SqlConfig; |
| 41 | +import org.springframework.transaction.annotation.Transactional; |
| 42 | + |
| 43 | +import graphql.execution.DataFetcherResult; |
| 44 | +import reactor.test.StepVerifier; |
| 45 | + |
| 46 | +/** |
| 47 | + * Integration tests of the details view. |
| 48 | + * |
| 49 | + * @author gdaniel |
| 50 | + */ |
| 51 | +@Transactional |
| 52 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
| 53 | +public class DetailsViewControllerIntegrationTests extends AbstractIntegrationTests { |
| 54 | + |
| 55 | + @Autowired |
| 56 | + private IGivenInitialServerState givenInitialServerState; |
| 57 | + |
| 58 | + @Autowired |
| 59 | + private DetailsEventSubscriptionRunner detailsEventSubscriptionRunner; |
| 60 | + |
| 61 | + @Autowired |
| 62 | + private RepresentationIdBuilder representationIdBuilder; |
| 63 | + |
| 64 | + @BeforeEach |
| 65 | + public void beforeEach() { |
| 66 | + this.givenInitialServerState.initialize(); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + @DisplayName("Given a PartUsage, when we subscribe to its properties events, then the form is sent") |
| 71 | + @Sql(scripts = { SimpleProjectElementsTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) |
| 72 | + @Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) |
| 73 | + public void givenAPartUsageWhenWeSubscribeToItsPropertiesEventThenTheFormIsSent() { |
| 74 | + var detailsRepresentationId = this.representationIdBuilder.buildDetailsRepresentationId(List.of(SimpleProjectElementsTestProjectData.SemanticIds.PART_ID)); |
| 75 | + var input = new DetailsEventInput(UUID.randomUUID(), SimpleProjectElementsTestProjectData.EDITING_CONTEXT_ID, detailsRepresentationId); |
| 76 | + var flux = this.detailsEventSubscriptionRunner.run(input); |
| 77 | + |
| 78 | + Consumer<Object> formContentConsumer = object -> Optional.of(object) |
| 79 | + .filter(DataFetcherResult.class::isInstance) |
| 80 | + .map(DataFetcherResult.class::cast) |
| 81 | + .map(DataFetcherResult::getData) |
| 82 | + .filter(FormRefreshedEventPayload.class::isInstance) |
| 83 | + .map(FormRefreshedEventPayload.class::cast) |
| 84 | + .map(FormRefreshedEventPayload::form) |
| 85 | + .ifPresentOrElse(form -> { |
| 86 | + assertThat(form.getPages()) |
| 87 | + .hasSize(2) |
| 88 | + .satisfiesExactly(page1 -> assertThat(page1.getLabel()).isEqualTo("Core"), |
| 89 | + page2 -> assertThat(page2.getLabel()).isEqualTo("Advanced")); |
| 90 | + var coreGroupNavigator = new FormNavigator(form).page("Core").group("Part Properties"); |
| 91 | + var declaredNameTextfield = coreGroupNavigator.findWidget("Declared Name", Textfield.class); |
| 92 | + assertThat(declaredNameTextfield.getValue()).isEqualTo("p"); |
| 93 | + var qualifiedNameLabel = coreGroupNavigator.findWidget("Qualified Name", LabelWidget.class); |
| 94 | + assertThat(qualifiedNameLabel.getValue()).isEqualTo("Package1::p"); |
| 95 | + var advancedGroupNavigator = new FormNavigator(form).page("Advanced").group("Part Properties"); |
| 96 | + var nameLabel = advancedGroupNavigator.findWidget("Name", LabelWidget.class); |
| 97 | + assertThat(nameLabel.getValue()).isEqualTo("p"); |
| 98 | + }, () -> fail("Missing form")); |
| 99 | + |
| 100 | + StepVerifier.create(flux) |
| 101 | + .consumeNextWith(formContentConsumer) |
| 102 | + .thenCancel() |
| 103 | + .verify(Duration.ofSeconds(10)); |
| 104 | + |
| 105 | + } |
| 106 | + |
| 107 | +} |
0 commit comments