From 255c6d790c598ca4cc415ce833a39010490ac7ad Mon Sep 17 00:00:00 2001 From: Mohamed Date: Fri, 1 Nov 2024 22:52:54 +0100 Subject: [PATCH 01/95] Add langchain4j support --- .../LangChain4JApplicationService.java | 20 ++++++++++ .../domain/LangChain4JModuleFactory.java | 39 +++++++++++++++++++ .../springboot/langchain4j/package-info.java | 2 + .../LangChain4JModuleConfiguration.java | 26 +++++++++++++ .../shared/slug/domain/JHLiteModuleSlug.java | 3 +- .../resources/generator/dependencies/pom.xml | 1 + 6 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4JApplicationService.java create mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java create mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/package-info.java create mode 100644 src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/primary/LangChain4JModuleConfiguration.java diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4JApplicationService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4JApplicationService.java new file mode 100644 index 00000000000..281e80dc1b5 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4JApplicationService.java @@ -0,0 +1,20 @@ +package tech.jhipster.lite.generator.server.springboot.langchain4j.application; + +import org.springframework.stereotype.Service; +import tech.jhipster.lite.generator.server.springboot.langchain4j.domain.LangChain4JModuleFactory; +import tech.jhipster.lite.module.domain.JHipsterModule; +import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; + +@Service +public class LangChain4JApplicationService { + + private final LangChain4JModuleFactory factory; + + public LangChain4JApplicationService() { + factory = new LangChain4JModuleFactory(); + } + + public JHipsterModule buildModule(JHipsterModuleProperties properties) { + return factory.buildInitializationModule(properties); + } +} diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java new file mode 100644 index 00000000000..7378ff64bdc --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java @@ -0,0 +1,39 @@ +package tech.jhipster.lite.generator.server.springboot.langchain4j.domain; + +import static tech.jhipster.lite.module.domain.JHipsterModule.*; + +import tech.jhipster.lite.module.domain.JHipsterModule; +import tech.jhipster.lite.module.domain.javabuild.GroupId; +import tech.jhipster.lite.module.domain.javabuild.VersionSlug; +import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; +import tech.jhipster.lite.shared.error.domain.Assert; + +public class LangChain4JModuleFactory { + + private static final GroupId LANGCHAIN4J_GROUP_ID = groupId("dev.langchain4j"); + private static final VersionSlug LANGCHAIN4J_VERSION_SLUG = versionSlug("langchain4j"); + + private static final String PROPERTIES = "properties"; + + public JHipsterModule buildInitializationModule(JHipsterModuleProperties properties) { + Assert.notNull(PROPERTIES, properties); + + //@formatter:off + return moduleBuilder(properties) + .javaDependencies() + .addDependency(LANGCHAIN4J_GROUP_ID, + artifactId("langchain4j-spring-boot-starter"), + LANGCHAIN4J_VERSION_SLUG) + .and() + .files() + .and() + .springMainProperties() + .set(propertyKey("langchain4j.open-ai.chat-model.api-key"), propertyValue("${OPENAI_API_KEY}")) + .set(propertyKey("langchain4j.open-ai.chat-model.model-name"), propertyValue("gpt-4o-mini")) + .set(propertyKey("langchain4j.open-ai.chat-model.log-requests"), propertyValue("true")) + .set(propertyKey("langchain4j.open-ai.chat-model.log-responses"), propertyValue("true")) + .and() + .build(); + //@formatter:on + } +} diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/package-info.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/package-info.java new file mode 100644 index 00000000000..1d7a2fab36d --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/package-info.java @@ -0,0 +1,2 @@ +@tech.jhipster.lite.BusinessContext +package tech.jhipster.lite.generator.server.springboot.langchain4j; diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/primary/LangChain4JModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/primary/LangChain4JModuleConfiguration.java new file mode 100644 index 00000000000..547e61e8249 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/primary/LangChain4JModuleConfiguration.java @@ -0,0 +1,26 @@ +package tech.jhipster.lite.generator.server.springboot.langchain4j.primary; + +import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.LANGCHAIN4J; +import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.SPRING_BOOT; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import tech.jhipster.lite.generator.server.springboot.langchain4j.application.LangChain4JApplicationService; +import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization; +import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition; +import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource; + +@Configuration +class LangChain4JModuleConfiguration { + + @Bean + JHipsterModuleResource langChain4JModule(LangChain4JApplicationService langChain4J) { + return JHipsterModuleResource.builder() + .slug(LANGCHAIN4J) + .propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addProjectBaseName().addIndentation().build()) + .apiDoc("LangChain4J", "Add LangChain4J Spring dependency") + .organization(JHipsterModuleOrganization.builder().addDependency(SPRING_BOOT).build()) + .tags("server", "spring", "spring-boot", "langchain4j") + .factory(langChain4J::buildModule); + } +} diff --git a/src/main/java/tech/jhipster/lite/shared/slug/domain/JHLiteModuleSlug.java b/src/main/java/tech/jhipster/lite/shared/slug/domain/JHLiteModuleSlug.java index e31a781e8cc..7a10ba75582 100644 --- a/src/main/java/tech/jhipster/lite/shared/slug/domain/JHLiteModuleSlug.java +++ b/src/main/java/tech/jhipster/lite/shared/slug/domain/JHLiteModuleSlug.java @@ -156,7 +156,8 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory { VUE_OAUTH2_KEYCLOAK("vue-oauth2-keycloak"), VUE_PINIA("vue-pinia"), TS_PAGINATION_DOMAIN("ts-pagination-domain"), - TS_REST_PAGINATION("ts-rest-pagination"); + TS_REST_PAGINATION("ts-rest-pagination"), + LANGCHAIN4J("langchain4j"); private static final Map moduleSlugMap = Stream.of(values()).collect( Collectors.toMap(JHLiteModuleSlug::get, Function.identity()) diff --git a/src/main/resources/generator/dependencies/pom.xml b/src/main/resources/generator/dependencies/pom.xml index 64a18b48e38..59acc4e001d 100644 --- a/src/main/resources/generator/dependencies/pom.xml +++ b/src/main/resources/generator/dependencies/pom.xml @@ -71,6 +71,7 @@ 3.0.0 0.0.21 1.0.3 + 0.35.0 From d40b77043e6109ed28003db2c02394d7596e7c4c Mon Sep 17 00:00:00 2001 From: Mohamed Date: Fri, 1 Nov 2024 23:11:48 +0100 Subject: [PATCH 02/95] Add test --- .../LangChain4JApplicationService.java | 2 +- .../domain/LangChain4JModuleFactory.java | 2 +- .../domain/LangChain4JModuleFactoryTest.java | 57 +++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4JApplicationService.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4JApplicationService.java index 281e80dc1b5..2dfcfdf8009 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4JApplicationService.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/application/LangChain4JApplicationService.java @@ -15,6 +15,6 @@ public LangChain4JApplicationService() { } public JHipsterModule buildModule(JHipsterModuleProperties properties) { - return factory.buildInitializationModule(properties); + return factory.buildModule(properties); } } diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java index 7378ff64bdc..f4b561119e9 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java @@ -15,7 +15,7 @@ public class LangChain4JModuleFactory { private static final String PROPERTIES = "properties"; - public JHipsterModule buildInitializationModule(JHipsterModuleProperties properties) { + public JHipsterModule buildModule(JHipsterModuleProperties properties) { Assert.notNull(PROPERTIES, properties); //@formatter:off diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java new file mode 100644 index 00000000000..3e65a7f68ff --- /dev/null +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java @@ -0,0 +1,57 @@ +package tech.jhipster.lite.generator.server.springboot.langchain4j.domain; + +import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModuleWithFiles; +import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.pomFile; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.junit.jupiter.MockitoExtension; +import tech.jhipster.lite.TestFileUtils; +import tech.jhipster.lite.UnitTest; +import tech.jhipster.lite.module.domain.JHipsterModule; +import tech.jhipster.lite.module.domain.JHipsterModulesFixture; +import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; + +@UnitTest +@ExtendWith(MockitoExtension.class) +public class LangChain4JModuleFactoryTest { + + @InjectMocks + private LangChain4JModuleFactory factory; + + @Test + void shouldCreateModule() { + JHipsterModuleProperties properties = JHipsterModulesFixture.propertiesBuilder(TestFileUtils.tmpDirForTest()) + .projectBaseName("myApp") + .build(); + + JHipsterModule module = factory.buildModule(properties); + + assertThatModuleWithFiles(module, pomFile()) + .hasFile("pom.xml") + .containing("") + .containing( + """ + + dev.langchain4j + langchain4j-spring-boot-starter + ${langchain4j.version} + + """ + ) + .and() + .hasFile("src/main/resources/config/application.yml") + .containing( + """ + langchain4j: + open-ai: + chat-model: + api-key: ${OPENAI_API_KEY} + log-requests: 'true' + log-responses: 'true' + model-name: gpt-4o-mini + """ + ); + } +} From 97c7eea5b2563ebb7e00090940a4b7d715a51e19 Mon Sep 17 00:00:00 2001 From: Mohamed Date: Sat, 2 Nov 2024 00:21:12 +0100 Subject: [PATCH 03/95] Fix CI --- .../primary/LangChain4JModuleConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/{ => infrastructure}/primary/LangChain4JModuleConfiguration.java (97%) diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/primary/LangChain4JModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/infrastructure/primary/LangChain4JModuleConfiguration.java similarity index 97% rename from src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/primary/LangChain4JModuleConfiguration.java rename to src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/infrastructure/primary/LangChain4JModuleConfiguration.java index 547e61e8249..a4952a1b119 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/primary/LangChain4JModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/infrastructure/primary/LangChain4JModuleConfiguration.java @@ -1,4 +1,4 @@ -package tech.jhipster.lite.generator.server.springboot.langchain4j.primary; +package tech.jhipster.lite.generator.server.springboot.langchain4j.infrastructure.primary; import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.LANGCHAIN4J; import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.SPRING_BOOT; From 7ded582ceb03ecf79e1ba08076f1cc08a0bda477 Mon Sep 17 00:00:00 2001 From: Mohamed Date: Sat, 2 Nov 2024 00:33:26 +0100 Subject: [PATCH 04/95] Fix CI --- src/main/resources/generator/dependencies/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/generator/dependencies/pom.xml b/src/main/resources/generator/dependencies/pom.xml index 59acc4e001d..4d4dff3b913 100644 --- a/src/main/resources/generator/dependencies/pom.xml +++ b/src/main/resources/generator/dependencies/pom.xml @@ -407,6 +407,11 @@ openapi-backwards-compat-maven-plugin ${openapi-backwards-compat-maven-plugin.version} + + dev.langchain4j + langchain4j-spring-boot-starter + ${langchain4j.version} + From ae576279007538f4f2698cd6eba7ba9db2f3061d Mon Sep 17 00:00:00 2001 From: Mohamed Date: Sat, 2 Nov 2024 01:04:53 +0100 Subject: [PATCH 05/95] Fix CI --- .../langchain4j/domain/LangChain4JModuleFactory.java | 3 +++ .../springboot/langchain4j/langchain4j.md.mustache | 5 +++++ .../features/server/springboot/langchain4j.feature | 10 ++++++++++ 3 files changed, 18 insertions(+) create mode 100644 src/main/resources/generator/server/springboot/langchain4j/langchain4j.md.mustache create mode 100644 src/test/features/server/springboot/langchain4j.feature diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java index f4b561119e9..3e54eb4107a 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java @@ -3,6 +3,7 @@ import static tech.jhipster.lite.module.domain.JHipsterModule.*; import tech.jhipster.lite.module.domain.JHipsterModule; +import tech.jhipster.lite.module.domain.file.JHipsterSource; import tech.jhipster.lite.module.domain.javabuild.GroupId; import tech.jhipster.lite.module.domain.javabuild.VersionSlug; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; @@ -10,6 +11,7 @@ public class LangChain4JModuleFactory { + private static final JHipsterSource SOURCE = from("server/springboot/langchain4j"); private static final GroupId LANGCHAIN4J_GROUP_ID = groupId("dev.langchain4j"); private static final VersionSlug LANGCHAIN4J_VERSION_SLUG = versionSlug("langchain4j"); @@ -20,6 +22,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) { //@formatter:off return moduleBuilder(properties) + .documentation(documentationTitle("Dev tools"), SOURCE.template("langchain4j.md")) .javaDependencies() .addDependency(LANGCHAIN4J_GROUP_ID, artifactId("langchain4j-spring-boot-starter"), diff --git a/src/main/resources/generator/server/springboot/langchain4j/langchain4j.md.mustache b/src/main/resources/generator/server/springboot/langchain4j/langchain4j.md.mustache new file mode 100644 index 00000000000..4c7d631153d --- /dev/null +++ b/src/main/resources/generator/server/springboot/langchain4j/langchain4j.md.mustache @@ -0,0 +1,5 @@ +# LangChain4J + +How to use it : + +[Official documentation](https://docs.langchain4j.dev/tutorials/spring-boot-integration/) diff --git a/src/test/features/server/springboot/langchain4j.feature b/src/test/features/server/springboot/langchain4j.feature new file mode 100644 index 00000000000..4bfefca1a8e --- /dev/null +++ b/src/test/features/server/springboot/langchain4j.feature @@ -0,0 +1,10 @@ +Feature: LangChain4J module + + Scenario: Should add Spring Boot LangChain4J Starter + When I apply modules to default project + | maven-java | + | spring-boot | + | langchain4j | + Then I should have entries in "src/main/resources/config/application.yml" + | open-ai | + | langchain4j | From f5196545b865e0c9fc778dcac5c67e1ccbbef714 Mon Sep 17 00:00:00 2001 From: Mohamed Date: Sat, 2 Nov 2024 01:13:09 +0100 Subject: [PATCH 06/95] Fix CI --- .../langchain4j/domain/LangChain4JModuleFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java index 3e65a7f68ff..0d03b8dcb81 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java @@ -15,7 +15,7 @@ @UnitTest @ExtendWith(MockitoExtension.class) -public class LangChain4JModuleFactoryTest { +class LangChain4JModuleFactoryTest { @InjectMocks private LangChain4JModuleFactory factory; From 5905e7fb70a8d0708355ede1de0d75af473f57a8 Mon Sep 17 00:00:00 2001 From: Mohamed Date: Sat, 2 Nov 2024 17:53:37 +0100 Subject: [PATCH 07/95] Add OpenAI default dependency --- .../langchain4j/domain/LangChain4JModuleFactory.java | 3 +++ src/main/resources/generator/dependencies/pom.xml | 5 +++++ .../langchain4j/domain/LangChain4JModuleFactoryTest.java | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java index 3e54eb4107a..f80d07826f0 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactory.java @@ -27,6 +27,9 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) { .addDependency(LANGCHAIN4J_GROUP_ID, artifactId("langchain4j-spring-boot-starter"), LANGCHAIN4J_VERSION_SLUG) + .addDependency(LANGCHAIN4J_GROUP_ID, + artifactId("langchain4j-open-ai-spring-boot-starter"), + LANGCHAIN4J_VERSION_SLUG) .and() .files() .and() diff --git a/src/main/resources/generator/dependencies/pom.xml b/src/main/resources/generator/dependencies/pom.xml index 4d4dff3b913..181d9012318 100644 --- a/src/main/resources/generator/dependencies/pom.xml +++ b/src/main/resources/generator/dependencies/pom.xml @@ -412,6 +412,11 @@ langchain4j-spring-boot-starter ${langchain4j.version} + + dev.langchain4j + langchain4j-open-ai-spring-boot-starter + ${langchain4j.version} + diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java index 0d03b8dcb81..adef63a3ad2 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/langchain4j/domain/LangChain4JModuleFactoryTest.java @@ -40,6 +40,15 @@ void shouldCreateModule() { """ ) + .containing( + """ + + dev.langchain4j + langchain4j-open-ai-spring-boot-starter + ${langchain4j.version} + + """ + ) .and() .hasFile("src/main/resources/config/application.yml") .containing( From 7ff392de530ee76a26231f36088bc695bffdbd2a Mon Sep 17 00:00:00 2001 From: Quentin Date: Sun, 3 Nov 2024 17:59:16 +0100 Subject: [PATCH 08/95] Vue/ESLint: add @typescript-eslint/consistent-type-imports rule --- .../generator/client/vue/core/domain/VueModulesFactory.java | 1 + .../generator/client/common/cypress/utils/Interceptor.ts | 2 +- .../client/common/playwright/common/primary/app/Home-Page.ts | 2 +- .../vue-oauth2-keycloak-authentication-components.md | 2 +- .../generator/client/vue/i18n/src/test/HomePageVue.spec.ts | 2 +- .../webapp/app/auth/application/AuthProvider.ts.mustache | 2 +- .../infrastructure/secondary/KeycloakAuthRepository.ts.mustache | 2 +- .../app/auth/infrastructure/secondary/KeycloakHttp.ts.mustache | 2 +- .../unit/auth/infrastructure/secondary/KeycloakStub.ts.mustache | 2 +- .../resources/generator/client/vue/webapp/app/env.d.ts.mustache | 2 +- .../router/infrastructure/primary/HomeRouter.spec.ts.mustache | 2 +- src/test/resources/projects/vue/HomepageVue.spec.ts.template | 2 +- ...toryTest.shouldCreateVueModule.eslint.config.js.approved.txt | 1 + src/test/webapp/unit/root/infrastructure/primary/App.spec.ts | 2 +- 14 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java b/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java index 6119d26c382..33e43d96a1e 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java @@ -149,6 +149,7 @@ private Consumer patchEslintConfig(JHipsterModuleProperti .add(eslintTypescriptVueRule("'vue/html-self-closing': 'off',", properties.indentation())) .add(eslintTypescriptVueRule("'@typescript-eslint/no-explicit-any': 'off',", properties.indentation())) .add(eslintTypescriptVueRule("'@typescript-eslint/no-empty-object-type': 'off',", properties.indentation())) + .add(eslintTypescriptVueRule("'@typescript-eslint/consistent-type-imports': 'error',", properties.indentation())) .and() .and(); //@formatter:on diff --git a/src/main/resources/generator/client/common/cypress/utils/Interceptor.ts b/src/main/resources/generator/client/common/cypress/utils/Interceptor.ts index da9e9663799..07602571751 100755 --- a/src/main/resources/generator/client/common/cypress/utils/Interceptor.ts +++ b/src/main/resources/generator/client/common/cypress/utils/Interceptor.ts @@ -1,4 +1,4 @@ -import { HttpResponseInterceptor, RouteMatcher, StaticResponse } from 'cypress/types/net-stubbing'; +import type { HttpResponseInterceptor, RouteMatcher, StaticResponse } from 'cypress/types/net-stubbing'; type ResponseSender = { send: () => void; diff --git a/src/main/resources/generator/client/common/playwright/common/primary/app/Home-Page.ts b/src/main/resources/generator/client/common/playwright/common/primary/app/Home-Page.ts index 8d61573c7f2..8dbc0591176 100644 --- a/src/main/resources/generator/client/common/playwright/common/primary/app/Home-Page.ts +++ b/src/main/resources/generator/client/common/playwright/common/primary/app/Home-Page.ts @@ -1,4 +1,4 @@ -import { Page } from '@playwright/test'; +import { type Page } from '@playwright/test'; export class HomePage { readonly page: Page; diff --git a/src/main/resources/generator/client/vue/documentation/vue-oauth2-keycloak-authentication-components.md b/src/main/resources/generator/client/vue/documentation/vue-oauth2-keycloak-authentication-components.md index 49384df281d..e376bf8e119 100644 --- a/src/main/resources/generator/client/vue/documentation/vue-oauth2-keycloak-authentication-components.md +++ b/src/main/resources/generator/client/vue/documentation/vue-oauth2-keycloak-authentication-components.md @@ -423,7 +423,7 @@ Location: `src/test/webapp/unit/auth/infrastructure/secondary/KeycloakStub.ts` This file provides a stub for Keycloak to be used in tests. ```typescript -import Keycloak from 'keycloak-js'; +import type Keycloak from 'keycloak-js'; import sinon from 'sinon'; import type { SinonStub } from 'sinon'; diff --git a/src/main/resources/generator/client/vue/i18n/src/test/HomePageVue.spec.ts b/src/main/resources/generator/client/vue/i18n/src/test/HomePageVue.spec.ts index b082d640bb7..536fa9cff77 100644 --- a/src/main/resources/generator/client/vue/i18n/src/test/HomePageVue.spec.ts +++ b/src/main/resources/generator/client/vue/i18n/src/test/HomePageVue.spec.ts @@ -1,5 +1,5 @@ import HomepageVue from '@/home/infrastructure/primary/HomepageVue.vue'; -import { shallowMount, VueWrapper } from '@vue/test-utils'; +import { shallowMount, type VueWrapper } from '@vue/test-utils'; import { describe, expect, it } from 'vitest'; let wrapper: VueWrapper; diff --git a/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/application/AuthProvider.ts.mustache b/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/application/AuthProvider.ts.mustache index 9ccdb2992a3..8bc094212d5 100644 --- a/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/application/AuthProvider.ts.mustache +++ b/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/application/AuthProvider.ts.mustache @@ -1,6 +1,6 @@ import type { AuthRepository } from '@/auth/domain/AuthRepository'; import { KeycloakAuthRepository } from '@/auth/infrastructure/secondary/KeycloakAuthRepository'; -import { KeycloakHttp } from '@/auth/infrastructure/secondary/KeycloakHttp'; +import { type KeycloakHttp } from '@/auth/infrastructure/secondary/KeycloakHttp'; import { provide } from '@/injections'; import { key } from 'piqure'; diff --git a/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/infrastructure/secondary/KeycloakAuthRepository.ts.mustache b/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/infrastructure/secondary/KeycloakAuthRepository.ts.mustache index 6d9613b07dc..920ecbe6fb8 100644 --- a/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/infrastructure/secondary/KeycloakAuthRepository.ts.mustache +++ b/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/infrastructure/secondary/KeycloakAuthRepository.ts.mustache @@ -1,6 +1,6 @@ import type { AuthRepository } from '@/auth/domain/AuthRepository'; import type { AuthenticatedUser } from '@/auth/domain/AuthenticatedUser'; -import { KeycloakHttp } from './KeycloakHttp'; +import { type KeycloakHttp } from './KeycloakHttp'; export class KeycloakAuthRepository implements AuthRepository { constructor(private readonly keycloakHttp: KeycloakHttp) {} diff --git a/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/infrastructure/secondary/KeycloakHttp.ts.mustache b/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/infrastructure/secondary/KeycloakHttp.ts.mustache index e21618f1ab4..7a7a9651a63 100644 --- a/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/infrastructure/secondary/KeycloakHttp.ts.mustache +++ b/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/auth/infrastructure/secondary/KeycloakHttp.ts.mustache @@ -1,5 +1,5 @@ import type { AuthenticatedUser } from '@/auth/domain/AuthenticatedUser'; -import Keycloak from 'keycloak-js'; +import type Keycloak from 'keycloak-js'; export class KeycloakHttp { private initialized: boolean = false; diff --git a/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/test/webapp/unit/auth/infrastructure/secondary/KeycloakStub.ts.mustache b/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/test/webapp/unit/auth/infrastructure/secondary/KeycloakStub.ts.mustache index d49fdea7498..c8a8ff8cff0 100644 --- a/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/test/webapp/unit/auth/infrastructure/secondary/KeycloakStub.ts.mustache +++ b/src/main/resources/generator/client/vue/security/oauth2_keycloak/webapp/app/test/webapp/unit/auth/infrastructure/secondary/KeycloakStub.ts.mustache @@ -1,4 +1,4 @@ -import Keycloak from 'keycloak-js'; +import type Keycloak from 'keycloak-js'; import type { SinonStub } from 'sinon'; import sinon from 'sinon'; diff --git a/src/main/resources/generator/client/vue/webapp/app/env.d.ts.mustache b/src/main/resources/generator/client/vue/webapp/app/env.d.ts.mustache index 025ac41ec43..2435bff5c02 100644 --- a/src/main/resources/generator/client/vue/webapp/app/env.d.ts.mustache +++ b/src/main/resources/generator/client/vue/webapp/app/env.d.ts.mustache @@ -1,7 +1,7 @@ /// declare module '*.vue' { - import { DefineComponent } from 'vue'; + import type DefineComponent from 'vue'; const component: DefineComponent<{}, {}, any>; export default component; } diff --git a/src/main/resources/generator/client/vue/webapp/app/test/webapp/unit/router/infrastructure/primary/HomeRouter.spec.ts.mustache b/src/main/resources/generator/client/vue/webapp/app/test/webapp/unit/router/infrastructure/primary/HomeRouter.spec.ts.mustache index b40d2e636ff..340d6a158d5 100644 --- a/src/main/resources/generator/client/vue/webapp/app/test/webapp/unit/router/infrastructure/primary/HomeRouter.spec.ts.mustache +++ b/src/main/resources/generator/client/vue/webapp/app/test/webapp/unit/router/infrastructure/primary/HomeRouter.spec.ts.mustache @@ -1,6 +1,6 @@ import HomepageVue from '@/home/infrastructure/primary/HomepageVue.vue'; import { routes } from '@/router'; -import { mount, VueWrapper } from '@vue/test-utils'; +import { mount, type VueWrapper } from '@vue/test-utils'; import { beforeEach, describe, expect, it } from 'vitest'; import { createRouter, createWebHistory, type Router } from 'vue-router'; diff --git a/src/test/resources/projects/vue/HomepageVue.spec.ts.template b/src/test/resources/projects/vue/HomepageVue.spec.ts.template index b082d640bb7..536fa9cff77 100644 --- a/src/test/resources/projects/vue/HomepageVue.spec.ts.template +++ b/src/test/resources/projects/vue/HomepageVue.spec.ts.template @@ -1,5 +1,5 @@ import HomepageVue from '@/home/infrastructure/primary/HomepageVue.vue'; -import { shallowMount, VueWrapper } from '@vue/test-utils'; +import { shallowMount, type VueWrapper } from '@vue/test-utils'; import { describe, expect, it } from 'vitest'; let wrapper: VueWrapper; diff --git a/src/test/resources/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.shouldCreateVueModule.eslint.config.js.approved.txt b/src/test/resources/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.shouldCreateVueModule.eslint.config.js.approved.txt index a45582a4a09..275694c9617 100644 --- a/src/test/resources/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.shouldCreateVueModule.eslint.config.js.approved.txt +++ b/src/test/resources/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.shouldCreateVueModule.eslint.config.js.approved.txt @@ -31,6 +31,7 @@ export default typescript.config( }, rules: { quotes: ['error', 'single', { avoidEscape: true }], + '@typescript-eslint/consistent-type-imports': 'error', '@typescript-eslint/no-empty-object-type': 'off', '@typescript-eslint/no-explicit-any': 'off', 'vue/html-self-closing': 'off', diff --git a/src/test/webapp/unit/root/infrastructure/primary/App.spec.ts b/src/test/webapp/unit/root/infrastructure/primary/App.spec.ts index 24f572233a8..2af6cdb3f8c 100644 --- a/src/test/webapp/unit/root/infrastructure/primary/App.spec.ts +++ b/src/test/webapp/unit/root/infrastructure/primary/App.spec.ts @@ -1,5 +1,5 @@ import { AppVue } from '@/root/infrastructure/primary'; -import { shallowMount, VueWrapper } from '@vue/test-utils'; +import { shallowMount, type VueWrapper } from '@vue/test-utils'; import { describe, expect, it } from 'vitest'; let wrapper: VueWrapper; From cf3ad1e9a2543d2ef47c0cf23ba26f60b3b80c01 Mon Sep 17 00:00:00 2001 From: Quentin Date: Mon, 4 Nov 2024 22:17:21 +0100 Subject: [PATCH 09/95] Cypress: Best practices for selectors --- .../common/cypress/utils/DataSelector.ts | 2 +- .../landscape-loader/LandscapeLoader.html | 2 +- .../LandscapeMiniMap.component.ts | 2 +- .../landscape-minimap/LandscapeMiniMap.html | 10 ++++---- .../landscape-module/LandscapeModule.html | 4 ++-- .../LandscapePresetConfiguration.html | 4 ++-- .../module/primary/landscape/Landscape.html | 18 +++++++------- .../module-parameters/ModuleParameters.html | 6 ++--- .../ModulePropertiesForm.html | 14 +++++------ .../ModulesPatchLoader.html | 2 +- .../primary/modules-patch/ModulesPatch.html | 24 ++++++------------- .../project-actions/ProjectActions.html | 4 ++-- .../module/primary/tag-filter/TagFilter.html | 2 +- .../infrastructure/primary/ThemeButton.vue | 2 +- .../toast/infrastructure/primary/Toast.vue | 4 ++-- src/test/webapp/component/support/selector.ts | 2 +- src/test/webapp/e2e/support/selector.ts | 2 +- src/test/webapp/unit/WrappedElement.ts | 2 +- .../unit/common/primary/toast/Toast.spec.ts | 6 ++--- 19 files changed, 49 insertions(+), 63 deletions(-) diff --git a/src/main/resources/generator/client/common/cypress/utils/DataSelector.ts b/src/main/resources/generator/client/common/cypress/utils/DataSelector.ts index e0d3e7c69cd..01059fdfe89 100755 --- a/src/main/resources/generator/client/common/cypress/utils/DataSelector.ts +++ b/src/main/resources/generator/client/common/cypress/utils/DataSelector.ts @@ -1 +1 @@ -export const dataSelector = (selector: string): string => `[data-selector="${selector}"]`; +export const dataSelector = (selector: string): string => `[data-cy="${selector}"], [data-test="${selector}"], [data-testid="${selector}"]`; diff --git a/src/main/webapp/app/module/primary/landscape-loader/LandscapeLoader.html b/src/main/webapp/app/module/primary/landscape-loader/LandscapeLoader.html index c40c708c0c7..af15b705996 100644 --- a/src/main/webapp/app/module/primary/landscape-loader/LandscapeLoader.html +++ b/src/main/webapp/app/module/primary/landscape-loader/LandscapeLoader.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/main/webapp/app/module/primary/landscape-minimap/LandscapeMiniMap.component.ts b/src/main/webapp/app/module/primary/landscape-minimap/LandscapeMiniMap.component.ts index a73ea1be2a0..686b596741b 100644 --- a/src/main/webapp/app/module/primary/landscape-minimap/LandscapeMiniMap.component.ts +++ b/src/main/webapp/app/module/primary/landscape-minimap/LandscapeMiniMap.component.ts @@ -42,7 +42,7 @@ export default defineComponent({ }); const removeDataSelectorAttrs = (data: string): string => { - const regex = /data-selector="[^"]*"/g; + const regex = /data-test="[^"]*"/g; return data.replace(regex, ''); }; diff --git a/src/main/webapp/app/module/primary/landscape-minimap/LandscapeMiniMap.html b/src/main/webapp/app/module/primary/landscape-minimap/LandscapeMiniMap.html index c590d0b5bff..46db1bd0e6f 100644 --- a/src/main/webapp/app/module/primary/landscape-minimap/LandscapeMiniMap.html +++ b/src/main/webapp/app/module/primary/landscape-minimap/LandscapeMiniMap.html @@ -1,13 +1,11 @@
- + @@ -19,8 +17,8 @@ @mousemove="grabbing" @mouseup="stopGrabbing" @mouseleave="stopGrabbing" - data-selector="minimap-viewer" + data-test="minimap-viewer" >
-
+
diff --git a/src/main/webapp/app/module/primary/landscape-module/LandscapeModule.html b/src/main/webapp/app/module/primary/landscape-module/LandscapeModule.html index 7c75b929063..93c30f5941f 100644 --- a/src/main/webapp/app/module/primary/landscape-module/LandscapeModule.html +++ b/src/main/webapp/app/module/primary/landscape-module/LandscapeModule.html @@ -2,7 +2,7 @@ class="jhlite-chip" :class="moduleClass()" :ref="el => landscapeElements.set(module.slugString(), el)" - :data-selector="`${module.slugString()}-module`" + :data-test="`${module.slugString()}-module`" @mouseover="emphasizeModule()" @mouseleave="deEmphasizeModule()" @click="clickedModule()" @@ -15,7 +15,7 @@ name="ccw" aria-label="Reapply" title="Re-apply module" - :data-selector="`module-${module.slug}-application-icon`" + :data-test="`module-${module.slug}-application-icon`" />
{{ module.operation() }}
diff --git a/src/main/webapp/app/module/primary/landscape-preset-configuration/LandscapePresetConfiguration.html b/src/main/webapp/app/module/primary/landscape-preset-configuration/LandscapePresetConfiguration.html index 159c485cc1d..9f560354b42 100644 --- a/src/main/webapp/app/module/primary/landscape-preset-configuration/LandscapePresetConfiguration.html +++ b/src/main/webapp/app/module/primary/landscape-preset-configuration/LandscapePresetConfiguration.html @@ -4,7 +4,7 @@ class="jhlite-button-main -small" @click="openPresetConfiguration" title="Show presets configurations" - data-selector="show-preset-configuration-btn" + data-test="show-preset-configuration-btn" > @@ -13,7 +13,7 @@ v-if="isPresetConfigurationOpen" @click="closePresetConfiguration" title="Hide presets configurations" - data-selector="hide-preset-configuration-btn" + data-test="hide-preset-configuration-btn" > diff --git a/src/main/webapp/app/module/primary/landscape/Landscape.html b/src/main/webapp/app/module/primary/landscape/Landscape.html index b3cd7bcd310..7fada78a0c9 100644 --- a/src/main/webapp/app/module/primary/landscape/Landscape.html +++ b/src/main/webapp/app/module/primary/landscape/Landscape.html @@ -1,5 +1,5 @@ -
+
@@ -7,7 +7,7 @@ class="jhlite-button-switch" :class="modeSwitchClass('COMPACTED')" @click="selectMode('COMPACTED')" - data-selector="compacted-mode-button" + data-test="compacted-mode-button" > Compacted @@ -15,7 +15,7 @@ class="jhlite-button-switch" :class="modeSwitchClass('EXTENDED')" @click="selectMode('EXTENDED')" - data-selector="extended-mode-button" + data-test="extended-mode-button" > Extended @@ -36,7 +36,7 @@ class="jhlite-input-text" placeholder="Search modules..." @input="performSearch($event.target.value)" - data-selector="landscape-search-input" + data-test="landscape-search-input" />
@@ -46,7 +46,7 @@
@@ -95,7 +95,7 @@

{{ element.sl {{ element.sl

:placeholder="property.defaultValue" @input="setNumberProperty(property.key, $event.target.value)" :value="parameters.get(property.key)" - :data-selector="`parameter-${property.key}-field`" + :data-test="`parameter-${property.key}-field`" v-if="property.type === 'INTEGER'" />
-
- Optional -
+
Optional
@@ -70,7 +68,7 @@

Properties

type="checkbox" id="commit-modules" @click="updateModuleCommit($event.target.checked)" - data-selector="commit-module-application" + data-test="commit-module-application" checked="checked" /> diff --git a/src/main/webapp/app/module/primary/modules-patch-loader/ModulesPatchLoader.html b/src/main/webapp/app/module/primary/modules-patch-loader/ModulesPatchLoader.html index 947d1c2d4d3..8aa27134194 100644 --- a/src/main/webapp/app/module/primary/modules-patch-loader/ModulesPatchLoader.html +++ b/src/main/webapp/app/module/primary/modules-patch-loader/ModulesPatchLoader.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/main/webapp/app/module/primary/modules-patch/ModulesPatch.html b/src/main/webapp/app/module/primary/modules-patch/ModulesPatch.html index b4e37804d5a..cd793756d52 100644 --- a/src/main/webapp/app/module/primary/modules-patch/ModulesPatch.html +++ b/src/main/webapp/app/module/primary/modules-patch/ModulesPatch.html @@ -1,5 +1,5 @@ -
+
@@ -12,11 +12,11 @@ type="text" class="jhipster-modules-filters--filter" placeholder="Filter" - data-selector="modules-filter-field" + data-test="modules-filter-field" @input="updateSearch($event.target.value)" /> -
+
{{ displayedModulesCount() }} / {{ totalModulesCount() }}
@@ -31,7 +31,7 @@

{{ category.name }}

:class="moduleClass(module.slug)" @click="toggleModule(module.slug)" @keyup.enter="toggleModule(module.slug)" - :data-selector="`${module.slug}-module-content`" + :data-test="`${module.slug}-module-content`" >
{{ tag }}
@@ -61,23 +61,13 @@

{{ category.name }}

:class="moduleClass(module.slug)" :disabled="disabledApplication(module.slug)" @click="applyModule(module.slug)" - :data-selector="`module-${module.slug}-application-button`" + :data-test="`module-${module.slug}-application-button`" > - + - +
diff --git a/src/main/webapp/app/module/primary/project-actions/ProjectActions.html b/src/main/webapp/app/module/primary/project-actions/ProjectActions.html index 2e3dc33cbbc..d1c1377231f 100644 --- a/src/main/webapp/app/module/primary/project-actions/ProjectActions.html +++ b/src/main/webapp/app/module/primary/project-actions/ProjectActions.html @@ -3,13 +3,13 @@
-
- diff --git a/src/main/webapp/app/module/primary/tag-filter/TagFilter.html b/src/main/webapp/app/module/primary/tag-filter/TagFilter.html index a4133b194b5..b6a03f453f2 100644 --- a/src/main/webapp/app/module/primary/tag-filter/TagFilter.html +++ b/src/main/webapp/app/module/primary/tag-filter/TagFilter.html @@ -1 +1 @@ - + diff --git a/src/main/webapp/app/shared/theme-button/infrastructure/primary/ThemeButton.vue b/src/main/webapp/app/shared/theme-button/infrastructure/primary/ThemeButton.vue index 43480fbe9c1..2004b530b97 100644 --- a/src/main/webapp/app/shared/theme-button/infrastructure/primary/ThemeButton.vue +++ b/src/main/webapp/app/shared/theme-button/infrastructure/primary/ThemeButton.vue @@ -6,7 +6,7 @@ type="checkbox" name="mode" :checked="!isDarkTheme" - data-selector="theme-switch-button" + data-test="theme-switch-button" @change="toggleTheme" />