From 01fa410c6ef109e17aff58d422ce0bcfb0576eed Mon Sep 17 00:00:00 2001 From: Quentin France Date: Sat, 30 Apr 2022 16:16:34 +0200 Subject: [PATCH 1/3] Frontend: Refactor Project Generator tab --- .../default-button/DefaultButton.component.ts | 4 + .../primary/default-button/DefaultButton.vue | 2 +- .../springboot/primary/Generator.component.ts | 80 +-- .../app/springboot/primary/Generator.vue | 60 +-- .../ProjectGenerator.component.ts | 111 ++++ .../project-generator/ProjectGenerator.vue | 58 +++ .../primary/project-generator/index.ts | 4 + .../cypress/integration/Generator.spec.ts | 19 +- .../spec/springboot/primary/Generator.spec.ts | 489 +----------------- .../ProjectGenerator.spec.ts | 457 ++++++++++++++++ 10 files changed, 652 insertions(+), 632 deletions(-) create mode 100644 src/main/webapp/app/springboot/primary/project-generator/ProjectGenerator.component.ts create mode 100644 src/main/webapp/app/springboot/primary/project-generator/ProjectGenerator.vue create mode 100644 src/main/webapp/app/springboot/primary/project-generator/index.ts create mode 100644 src/test/javascript/spec/springboot/primary/project-generator/ProjectGenerator.spec.ts diff --git a/src/main/webapp/app/common/primary/default-button/DefaultButton.component.ts b/src/main/webapp/app/common/primary/default-button/DefaultButton.component.ts index a9fff27802f..559ba3f00cb 100644 --- a/src/main/webapp/app/common/primary/default-button/DefaultButton.component.ts +++ b/src/main/webapp/app/common/primary/default-button/DefaultButton.component.ts @@ -17,6 +17,10 @@ export default defineComponent({ type: Boolean, default: false, }, + outlined: { + type: Boolean, + default: false, + }, icon: { type: String, default: undefined, diff --git a/src/main/webapp/app/common/primary/default-button/DefaultButton.vue b/src/main/webapp/app/common/primary/default-button/DefaultButton.vue index 895a3857ef4..2d777be4dba 100644 --- a/src/main/webapp/app/common/primary/default-button/DefaultButton.vue +++ b/src/main/webapp/app/common/primary/default-button/DefaultButton.vue @@ -1,5 +1,5 @@ diff --git a/src/main/webapp/app/springboot/primary/vue-generator/index.ts b/src/main/webapp/app/springboot/primary/generator/vue-generator/index.ts similarity index 100% rename from src/main/webapp/app/springboot/primary/vue-generator/index.ts rename to src/main/webapp/app/springboot/primary/generator/vue-generator/index.ts diff --git a/src/main/webapp/app/springboot/primary/project-generator/ProjectGenerator.vue b/src/main/webapp/app/springboot/primary/project-generator/ProjectGenerator.vue deleted file mode 100644 index a66827ad460..00000000000 --- a/src/main/webapp/app/springboot/primary/project-generator/ProjectGenerator.vue +++ /dev/null @@ -1,58 +0,0 @@ - - - diff --git a/src/main/webapp/app/springboot/primary/spring-boot-generator/SpringbootGenerator.vue b/src/main/webapp/app/springboot/primary/spring-boot-generator/SpringbootGenerator.vue index b46dc31df66..e69de29bb2d 100644 --- a/src/main/webapp/app/springboot/primary/spring-boot-generator/SpringbootGenerator.vue +++ b/src/main/webapp/app/springboot/primary/spring-boot-generator/SpringbootGenerator.vue @@ -1,96 +0,0 @@ - - - diff --git a/src/test/javascript/cypress/integration/Generator.spec.ts b/src/test/javascript/cypress/integration/Generator.spec.ts index 44b0d85e4cd..f1063934f06 100644 --- a/src/test/javascript/cypress/integration/Generator.spec.ts +++ b/src/test/javascript/cypress/integration/Generator.spec.ts @@ -21,34 +21,35 @@ describe('Generator', () => { it('should display generator page', () => { cy.get(headerSelector('title')).contains('JHipster lite'); - cy.get(projectGeneratorSelector('init-button')).contains('Init'); - cy.get(projectGeneratorSelector('add-maven-button')).contains('Maven'); - cy.get(projectGeneratorSelector('add-jacoco-button')).contains('JaCoCo'); - cy.get(projectGeneratorSelector('add-sonar-backend-button')).contains('Sonar Backend'); - cy.get(projectGeneratorSelector('add-sonar-backend-frontend-button')).contains('Sonar Backend+Frontend'); + cy.get(projectGeneratorSelector('add-initialization-button')).contains('Init'); + cy.get(projectGeneratorSelector('add-maven-java-button')).contains('Maven'); + cy.get(projectGeneratorSelector('add-jacoco-check-minimal-coverage-button')).contains('JaCoCo'); + cy.get(projectGeneratorSelector('add-sonar-java-backend-button')).contains('Sonar Backend'); + cy.get(projectGeneratorSelector('add-sonar-java-backend-and-frontend-button')).contains('Sonar Backend+Frontend'); cy.get(projectGeneratorSelector('add-java-base-button')).contains('Java Base'); cy.get(projectGeneratorSelector('add-frontend-maven-plugin-button')).contains('Frontend Maven Plugin'); - cy.get(projectGeneratorSelector('download-button')).should('not.exist'); + cy.get(projectGeneratorSelector('add-download-button')).should('not.exist'); }); it('should display spring boot', () => { cy.get(generatorSelector('option-springboot')).check(); + cy.get(springBootGeneratorSelector('add-spring-boot-button')).contains('Spring Boot'); - cy.get(springBootGeneratorSelector('add-spring-boot-mvc-tomcat-button')).contains('Spring MVC Tomcat'); + cy.get(springBootGeneratorSelector('add-spring-boot-mvc-with-tomcat-button')).contains('Spring MVC Tomcat'); cy.get(springBootGeneratorSelector('add-spring-boot-webflux-netty-button')).contains('Spring Webflux Netty'); cy.get(springBootGeneratorSelector('add-spring-boot-actuator-button')).contains('Spring Boot Actuator'); - cy.get(springBootGeneratorSelector('add-spring-boot-aop-button')).contains('AOP Logging'); - cy.get(springBootGeneratorSelector('add-spring-boot-logstash-button')).contains('Logstash'); + cy.get(springBootGeneratorSelector('add-aop-logging-button')).contains('AOP Logging'); + cy.get(springBootGeneratorSelector('add-logstash-button')).contains('Logstash'); cy.get(springBootGeneratorSelector('add-spring-boot-jwt-button')).contains('Security JWT'); - cy.get(springBootGeneratorSelector('add-spring-boot-jwt-basic-auth-button')).contains('Security JWT Basic Auth'); + cy.get(springBootGeneratorSelector('add-spring-boot-jwt-with-basic-authentication-button')).contains('Security JWT Basic Auth'); - cy.get(springBootGeneratorSelector('add-spring-boot-database-postgresql-button')).contains('PostgreSQL'); - cy.get(springBootGeneratorSelector('add-spring-boot-database-mysql-button')).contains('MySQL'); - cy.get(springBootGeneratorSelector('add-spring-boot-database-mariadb-button')).contains('MariaDB'); - cy.get(springBootGeneratorSelector('add-spring-boot-database-mongodb-button')).contains('MongoDB'); - cy.get(springBootGeneratorSelector('add-spring-boot-database-migration-mongock-button')).contains('Mongock'); + cy.get(springBootGeneratorSelector('add-postgresql-button')).contains('PostgreSQL'); + cy.get(springBootGeneratorSelector('add-mysql-button')).contains('MySQL'); + cy.get(springBootGeneratorSelector('add-mariadb-button')).contains('MariaDB'); + cy.get(springBootGeneratorSelector('add-mongodb-button')).contains('MongoDB'); + cy.get(springBootGeneratorSelector('add-mongock-button')).contains('Mongock'); }); it('should display angular', () => { @@ -73,6 +74,6 @@ describe('Generator', () => { it('should display download button when project path is filled', () => { cy.get('#path').type('/tmp/jhlite'); - cy.get(projectGeneratorSelector('download-button')).contains('Download'); + cy.get(projectGeneratorSelector('add-download-button')).contains('Download'); }); }); diff --git a/src/test/javascript/spec/common/primary/HistoryStore.spec.ts b/src/test/javascript/spec/common/primary/HistoryStore.spec.ts index b76ee54cbef..d36e0c1b6dc 100644 --- a/src/test/javascript/spec/common/primary/HistoryStore.spec.ts +++ b/src/test/javascript/spec/common/primary/HistoryStore.spec.ts @@ -2,6 +2,7 @@ import { createPinia, setActivePinia } from 'pinia'; import { useHistoryStore } from '@/common/primary/HistoryStore'; import { History } from '@/common/domain/History'; import { createHistory } from '../domain/History.fixture'; +import { Service } from '../../../../../main/webapp/app/common/domain/Service'; describe('HistoryStore', () => { beforeEach(() => { @@ -32,4 +33,24 @@ describe('HistoryStore', () => { expect(historyStore.getHistory).toEqual(history); }); + + it('should have called service', () => { + const historyStore = useHistoryStore(); + const history = createHistory({ + services: [Service.INITIALIZATION], + }); + historyStore.setHistory(history); + + expect(historyStore.hasCalledService(Service.INITIALIZATION)).toBe(true); + }); + + it('should not have called service', () => { + const historyStore = useHistoryStore(); + const history = createHistory({ + services: [Service.INITIALIZATION], + }); + historyStore.setHistory(history); + + expect(historyStore.hasCalledService(Service.JAVA_BASE)).toBe(false); + }); }); diff --git a/src/test/javascript/spec/common/secondary/RestServiceId.spec.ts b/src/test/javascript/spec/common/secondary/RestServiceId.spec.ts index c05bfa6c6a1..060dd4185fa 100644 --- a/src/test/javascript/spec/common/secondary/RestServiceId.spec.ts +++ b/src/test/javascript/spec/common/secondary/RestServiceId.spec.ts @@ -14,6 +14,7 @@ describe('RestServiceId', () => { expect(toService('mariadb')).toEqual(Service.MARIADB); expect(toService('maven-java')).toEqual(Service.MAVEN_JAVA); expect(toService('mongodb')).toEqual(Service.MONGODB); + expect(toService('mongock')).toEqual(Service.MONGOCK); expect(toService('mysql')).toEqual(Service.MYSQL); expect(toService('postgresql')).toEqual(Service.POSTGRESQL); expect(toService('sonar-java-backend')).toEqual(Service.SONAR_JAVA_BACKEND); diff --git a/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts b/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts new file mode 100644 index 00000000000..b78e376d0a6 --- /dev/null +++ b/src/test/javascript/spec/springboot/primary/generator/ServiceProjection.spec.ts @@ -0,0 +1,68 @@ +import { Service } from '@/common/domain/Service'; +import { fromServiceProjection, ServiceProjection, toServiceProjection } from '@/springboot/primary/generator/ServiceProjection'; + +describe('ServiceProjection', () => { + it('should convert from Service to ServiceProjection', () => { + expect(toServiceProjection(Service.AOP_LOGGING)).toEqual('aop-logging'); + expect(toServiceProjection(Service.ANGULAR)).toEqual('angular'); + expect(toServiceProjection(Service.DOWNLOAD)).toEqual('download'); + expect(toServiceProjection(Service.INITIALIZATION)).toEqual('initialization'); + expect(toServiceProjection(Service.FRONTEND_MAVEN_PLUGIN)).toEqual('frontend-maven-plugin'); + expect(toServiceProjection(Service.JACOCO_CHECK_MINIMAL_COVERAGE)).toEqual('jacoco-check-minimal-coverage'); + expect(toServiceProjection(Service.JAVA_BASE)).toEqual('java-base'); + expect(toServiceProjection(Service.LOGSTASH)).toEqual('logstash'); + expect(toServiceProjection(Service.MAVEN_JAVA)).toEqual('maven-java'); + expect(toServiceProjection(Service.MARIADB)).toEqual('mariadb'); + expect(toServiceProjection(Service.MYSQL)).toEqual('mysql'); + expect(toServiceProjection(Service.MONGODB)).toEqual('mongodb'); + expect(toServiceProjection(Service.MONGOCK)).toEqual('mongock'); + expect(toServiceProjection(Service.POSTGRESQL)).toEqual('postgresql'); + expect(toServiceProjection(Service.SONAR_JAVA_BACKEND)).toEqual('sonar-java-backend'); + expect(toServiceProjection(Service.SONAR_JAVA_BACKEND_AND_FRONTEND)).toEqual('sonar-java-backend-and-frontend'); + expect(toServiceProjection(Service.SPRINGBOOT)).toEqual('spring-boot'); + expect(toServiceProjection(Service.SPRINGBOOT_ACTUATOR)).toEqual('spring-boot-actuator'); + expect(toServiceProjection(Service.SPRINGBOOT_JWT)).toEqual('spring-boot-jwt'); + expect(toServiceProjection(Service.SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION)).toEqual( + 'spring-boot-jwt-with-basic-authentication' + ); + expect(toServiceProjection(Service.SPRINGBOOT_MVC_WITH_TOMCAT)).toEqual('spring-boot-mvc-with-tomcat'); + expect(toServiceProjection(Service.SPRINGBOOT_WEBFLUX_NETTY)).toEqual('spring-boot-webflux-netty'); + expect(toServiceProjection(Service.REACT)).toEqual('react'); + expect(toServiceProjection(Service.REACT_STYLED)).toEqual('react-styled'); + expect(toServiceProjection(Service.VUE)).toEqual('vue'); + expect(toServiceProjection(Service.VUE_STYLED)).toEqual('vue-styled'); + expect(toServiceProjection(Service.UNKNOWN)).toEqual('unknown'); + }); + + it('should convert from ServiceProjection to Service', () => { + expect(fromServiceProjection('aop-logging')).toEqual(Service.AOP_LOGGING); + expect(fromServiceProjection('angular')).toEqual(Service.ANGULAR); + expect(fromServiceProjection('download')).toEqual(Service.DOWNLOAD); + expect(fromServiceProjection('initialization')).toEqual(Service.INITIALIZATION); + expect(fromServiceProjection('frontend-maven-plugin')).toEqual(Service.FRONTEND_MAVEN_PLUGIN); + expect(fromServiceProjection('jacoco-check-minimal-coverage')).toEqual(Service.JACOCO_CHECK_MINIMAL_COVERAGE); + expect(fromServiceProjection('java-base')).toEqual(Service.JAVA_BASE); + expect(fromServiceProjection('logstash')).toEqual(Service.LOGSTASH); + expect(fromServiceProjection('maven-java')).toEqual(Service.MAVEN_JAVA); + expect(fromServiceProjection('mariadb')).toEqual(Service.MARIADB); + expect(fromServiceProjection('mysql')).toEqual(Service.MYSQL); + expect(fromServiceProjection('mongodb')).toEqual(Service.MONGODB); + expect(fromServiceProjection('mongock')).toEqual(Service.MONGOCK); + expect(fromServiceProjection('postgresql')).toEqual(Service.POSTGRESQL); + expect(fromServiceProjection('sonar-java-backend')).toEqual(Service.SONAR_JAVA_BACKEND); + expect(fromServiceProjection('sonar-java-backend-and-frontend')).toEqual(Service.SONAR_JAVA_BACKEND_AND_FRONTEND); + expect(fromServiceProjection('spring-boot')).toEqual(Service.SPRINGBOOT); + expect(fromServiceProjection('spring-boot-actuator')).toEqual(Service.SPRINGBOOT_ACTUATOR); + expect(fromServiceProjection('spring-boot-jwt')).toEqual(Service.SPRINGBOOT_JWT); + expect(fromServiceProjection('spring-boot-jwt-with-basic-authentication')).toEqual( + Service.SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION + ); + expect(fromServiceProjection('spring-boot-mvc-with-tomcat')).toEqual(Service.SPRINGBOOT_MVC_WITH_TOMCAT); + expect(fromServiceProjection('spring-boot-webflux-netty')).toEqual(Service.SPRINGBOOT_WEBFLUX_NETTY); + expect(fromServiceProjection('react')).toEqual(Service.REACT); + expect(fromServiceProjection('react-styled')).toEqual(Service.REACT_STYLED); + expect(fromServiceProjection('vue')).toEqual(Service.VUE); + expect(fromServiceProjection('vue-styled')).toEqual(Service.VUE_STYLED); + expect(fromServiceProjection('unknown')).toEqual(Service.UNKNOWN); + }); +}); diff --git a/src/test/javascript/spec/springboot/primary/angular-generator/AngularGenerator.spec.ts b/src/test/javascript/spec/springboot/primary/generator/angular-generator/AngularGenerator.spec.ts similarity index 80% rename from src/test/javascript/spec/springboot/primary/angular-generator/AngularGenerator.spec.ts rename to src/test/javascript/spec/springboot/primary/generator/angular-generator/AngularGenerator.spec.ts index d3e805c7c5a..6f29a3d7ea3 100644 --- a/src/test/javascript/spec/springboot/primary/angular-generator/AngularGenerator.spec.ts +++ b/src/test/javascript/spec/springboot/primary/generator/angular-generator/AngularGenerator.spec.ts @@ -1,13 +1,14 @@ import { shallowMount, VueWrapper } from '@vue/test-utils'; -import { stubAngularService } from '../../domain/client/AngularService.fixture'; +import { stubAngularService } from '../../../domain/client/AngularService.fixture'; import { ProjectToUpdate } from '@/springboot/primary/ProjectToUpdate'; -import { createProjectToUpdate } from '../ProjectToUpdate.fixture'; -import { stubLogger } from '../../../common/domain/Logger.fixture'; +import { createProjectToUpdate } from '../../ProjectToUpdate.fixture'; +import { stubLogger } from '../../../../common/domain/Logger.fixture'; import { AngularService } from '@/springboot/domain/client/AngularService'; import { Logger } from '@/common/domain/Logger'; -import { AngularGeneratorVue } from '@/springboot/primary/angular-generator'; +import { AngularGeneratorVue } from '@/springboot/primary/generator/angular-generator'; let wrapper: VueWrapper; +let component: any; interface WrapperOptions { angularService: AngularService; @@ -33,6 +34,7 @@ const wrap = (wrapperOptions?: Partial) => { }, }, }); + component = wrapper.vm; }; describe('AngularGenerator', () => { @@ -47,8 +49,7 @@ describe('AngularGenerator', () => { angularService.add.resolves({}); await wrap({ angularService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#angular'); - await button.trigger('click'); + await component.addAngular(); expect(angularService.add.called).toBe(false); }); @@ -58,8 +59,7 @@ describe('AngularGenerator', () => { angularService.add.resolves({}); await wrap({ angularService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#angular'); - await button.trigger('click'); + await component.addAngular(); const args = angularService.add.getCall(0).args[0]; expect(args).toEqual({ @@ -77,8 +77,7 @@ describe('AngularGenerator', () => { angularService.add.rejects({}); await wrap({ angularService, logger, project: createProjectToUpdate({ folder: 'path' }) }); - const initButton = wrapper.find('#angular'); - await initButton.trigger('click'); + await component.addAngular(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding Angular to project failed'); diff --git a/src/test/javascript/spec/springboot/primary/generator/generator-button/GeneratorButton.spec.ts b/src/test/javascript/spec/springboot/primary/generator/generator-button/GeneratorButton.spec.ts new file mode 100644 index 00000000000..fb0a9710f7c --- /dev/null +++ b/src/test/javascript/spec/springboot/primary/generator/generator-button/GeneratorButton.spec.ts @@ -0,0 +1,80 @@ +import { shallowMount, VueWrapper } from '@vue/test-utils'; +import { GeneratorButtonVue } from '@/springboot/primary/generator/generator-button'; +import { setActivePinia, StoreGeneric } from 'pinia'; +import { useHistoryStore } from '@/common/primary/HistoryStore'; +import { createTestingPinia } from '@pinia/testing'; +import { createHistory } from '../../../../common/domain/History.fixture'; +import { Service } from '@/common/domain/Service'; +import { ServiceProjection } from '@/springboot/primary/generator/ServiceProjection'; + +let wrapper: VueWrapper; +let component: any; + +interface WrapperOptions { + historyStore: StoreGeneric; + service: ServiceProjection; +} + +const wrap = (wrapperOptions?: Partial) => { + const { historyStore, service }: WrapperOptions = { + historyStore: useHistoryStore(), + service: 'initialization', + ...wrapperOptions, + }; + wrapper = shallowMount(GeneratorButtonVue, { + props: { + label: 'Init', + service: service, + selectorPrefix: 'prefix', + }, + global: { + provide: { + historyStore, + }, + }, + }); + component = wrapper.vm; +}; + +describe('GeneratorButton', () => { + beforeEach(() => { + const pinia = createTestingPinia(); + setActivePinia(pinia); + }); + + it('should exist', () => { + wrap(); + + expect(wrapper.exists()).toBe(true); + }); + + it('should have called service', () => { + const historyStore = useHistoryStore(); + historyStore.setHistory( + createHistory({ + services: [Service.INITIALIZATION], + }) + ); + wrap({ + historyStore, + service: 'initialization', + }); + + expect(component.hasCalledService).toBe(true); + }); + + it('should not have called service', () => { + const historyStore = useHistoryStore(); + historyStore.setHistory( + createHistory({ + services: [Service.INITIALIZATION], + }) + ); + wrap({ + historyStore, + service: 'java-base', + }); + + expect(component.hasCalledService).toBe(false); + }); +}); diff --git a/src/test/javascript/spec/springboot/primary/project-generator/ProjectGenerator.spec.ts b/src/test/javascript/spec/springboot/primary/generator/project-generator/ProjectGenerator.spec.ts similarity index 84% rename from src/test/javascript/spec/springboot/primary/project-generator/ProjectGenerator.spec.ts rename to src/test/javascript/spec/springboot/primary/generator/project-generator/ProjectGenerator.spec.ts index 7e898fd5093..062e02b343c 100644 --- a/src/test/javascript/spec/springboot/primary/project-generator/ProjectGenerator.spec.ts +++ b/src/test/javascript/spec/springboot/primary/generator/project-generator/ProjectGenerator.spec.ts @@ -1,15 +1,16 @@ import { shallowMount, VueWrapper } from '@vue/test-utils'; import { ProjectToUpdate } from '@/springboot/primary/ProjectToUpdate'; -import { createProjectToUpdate } from '../ProjectToUpdate.fixture'; -import { stubLogger } from '../../../common/domain/Logger.fixture'; +import { createProjectToUpdate } from '../../ProjectToUpdate.fixture'; +import { stubLogger } from '../../../../common/domain/Logger.fixture'; import { Logger } from '@/common/domain/Logger'; import { ProjectService } from '@/springboot/domain/ProjectService'; -import { stubProjectService } from '../../domain/ProjectService.fixture'; -import { ProjectGeneratorVue } from '@/springboot/primary/project-generator'; +import { stubProjectService } from '../../../domain/ProjectService.fixture'; +import { ProjectGeneratorVue } from '@/springboot/primary/generator/project-generator'; import { FileDownloader } from '@/common/primary/FileDownloader'; -import { stubFileDownloader } from '../../../common/primary/FileDownloader.fixture'; +import { stubFileDownloader } from '../../../../common/primary/FileDownloader.fixture'; let wrapper: VueWrapper; +let component: any; interface WrapperOptions { projectService: ProjectService; @@ -39,6 +40,7 @@ const wrap = (wrapperOptions?: Partial) => { }, }, }); + component = wrapper.vm; }; describe('ProjectGenerator', () => { @@ -53,8 +55,7 @@ describe('ProjectGenerator', () => { projectService.init.resolves({}); await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); - const initButton = wrapper.find('#init'); - await initButton.trigger('click'); + await component.initProject(); expect(projectService.init.called).toBe(false); }); @@ -71,8 +72,7 @@ describe('ProjectGenerator', () => { }); await wrap({ projectService, project: projectToUpdate }); - const initButton = wrapper.find('#init'); - await initButton.trigger('click'); + await component.initProject(); const args = projectService.init.getCall(0).args[0]; expect(args).toEqual({ @@ -90,8 +90,7 @@ describe('ProjectGenerator', () => { projectService.init.rejects({}); await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#init'); - await initButton.trigger('click'); + await component.initProject(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Project initialization failed'); @@ -102,8 +101,7 @@ describe('ProjectGenerator', () => { projectService.addMaven.resolves({}); await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#maven'); - await button.trigger('click'); + await component.addMaven(); expect(projectService.addMaven.called).toBe(false); }); @@ -120,8 +118,7 @@ describe('ProjectGenerator', () => { }); await wrap({ projectService, project: projectToUpdate }); - const button = wrapper.find('#maven'); - await button.trigger('click'); + await component.addMaven(); const args = projectService.addMaven.getCall(0).args[0]; expect(args).toEqual({ @@ -139,8 +136,7 @@ describe('ProjectGenerator', () => { projectService.addMaven.rejects({}); await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#maven'); - await initButton.trigger('click'); + await component.addMaven(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding Maven to project failed'); @@ -151,8 +147,7 @@ describe('ProjectGenerator', () => { projectService.addJaCoCo.resolves({}); await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#jacoco'); - await button.trigger('click'); + await component.addJaCoCo(); expect(projectService.addJaCoCo.called).toBe(false); }); @@ -169,8 +164,7 @@ describe('ProjectGenerator', () => { }); await wrap({ projectService, project: projectToUpdate }); - const button = wrapper.find('#jacoco'); - await button.trigger('click'); + await component.addJaCoCo(); const args = projectService.addJaCoCo.getCall(0).args[0]; expect(args).toEqual({ @@ -188,8 +182,7 @@ describe('ProjectGenerator', () => { projectService.addJaCoCo.rejects({}); await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#jacoco'); - await initButton.trigger('click'); + await component.addJaCoCo(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding JaCoCo to project failed'); @@ -200,8 +193,7 @@ describe('ProjectGenerator', () => { projectService.addSonarBackend.resolves({}); await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#sonar-backend'); - await button.trigger('click'); + await component.addSonarBackend(); expect(projectService.addSonarBackend.called).toBe(false); }); @@ -218,8 +210,7 @@ describe('ProjectGenerator', () => { }); await wrap({ projectService, project: projectToUpdate }); - const button = wrapper.find('#sonar-backend'); - await button.trigger('click'); + await component.addSonarBackend(); const args = projectService.addSonarBackend.getCall(0).args[0]; expect(args).toEqual({ @@ -237,8 +228,7 @@ describe('ProjectGenerator', () => { projectService.addSonarBackend.rejects({}); await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#sonar-backend'); - await initButton.trigger('click'); + await component.addSonarBackend(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding Sonar Backend to project failed'); @@ -249,8 +239,7 @@ describe('ProjectGenerator', () => { projectService.addSonarBackendFrontend.resolves({}); await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#sonar-backend-frontend'); - await button.trigger('click'); + await component.addSonarBackendFrontend(); expect(projectService.addSonarBackendFrontend.called).toBe(false); }); @@ -267,8 +256,7 @@ describe('ProjectGenerator', () => { }); await wrap({ projectService, project: projectToUpdate }); - const button = wrapper.find('#sonar-backend-frontend'); - await button.trigger('click'); + await component.addSonarBackendFrontend(); const args = projectService.addSonarBackendFrontend.getCall(0).args[0]; expect(args).toEqual({ @@ -286,8 +274,7 @@ describe('ProjectGenerator', () => { projectService.addSonarBackendFrontend.rejects({}); await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#sonar-backend-frontend'); - await initButton.trigger('click'); + await component.addSonarBackendFrontend(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding Sonar Backend+Frontend to project failed'); @@ -298,8 +285,7 @@ describe('ProjectGenerator', () => { projectService.addJavaBase.resolves({}); await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#javabase'); - await button.trigger('click'); + await component.addJavaBase(); expect(projectService.addJavaBase.called).toBe(false); }); @@ -316,8 +302,7 @@ describe('ProjectGenerator', () => { }); await wrap({ projectService, project: projectToUpdate }); - const button = wrapper.find('#javabase'); - await button.trigger('click'); + await component.addJavaBase(); const args = projectService.addJavaBase.getCall(0).args[0]; expect(args).toEqual({ @@ -335,8 +320,7 @@ describe('ProjectGenerator', () => { projectService.addJavaBase.rejects({}); await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#javabase'); - await initButton.trigger('click'); + await component.addJavaBase(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding Java Base to project failed'); @@ -347,8 +331,7 @@ describe('ProjectGenerator', () => { projectService.addFrontendMavenPlugin.resolves({}); await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#frontend-maven-plugin'); - await button.trigger('click'); + await component.addFrontendMavenPlugin(); expect(projectService.addFrontendMavenPlugin.called).toBe(false); }); @@ -365,8 +348,7 @@ describe('ProjectGenerator', () => { }); await wrap({ projectService, project: projectToUpdate }); - const button = wrapper.find('#frontend-maven-plugin'); - await button.trigger('click'); + await component.addFrontendMavenPlugin(); const args = projectService.addFrontendMavenPlugin.getCall(0).args[0]; expect(args).toEqual({ @@ -384,8 +366,7 @@ describe('ProjectGenerator', () => { projectService.addFrontendMavenPlugin.rejects({}); await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#frontend-maven-plugin'); - await initButton.trigger('click'); + await component.addFrontendMavenPlugin(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding Frontend Maven Plugin to project failed'); @@ -403,8 +384,7 @@ describe('ProjectGenerator', () => { }); await wrap({ projectService, project: projectToUpdate }); - const button = wrapper.find('#download'); - await button.trigger('click'); + await component.download(); const args = projectService.download.getCall(0).args[0]; expect(args).toEqual({ @@ -428,8 +408,7 @@ describe('ProjectGenerator', () => { }); await wrap({ projectService, project: projectToUpdate }); - const button = wrapper.find('#download'); - await button.trigger('click'); + await component.download(); const args = projectService.download.getCall(0).args[0]; expect(args).toEqual({ @@ -447,8 +426,7 @@ describe('ProjectGenerator', () => { projectService.download.rejects(new Error('foo')); await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const downloadButton = wrapper.find('#download'); - await downloadButton.trigger('click'); + await component.download(); const [message, error] = logger.error.getCall(0).args; expect(message).toBe('Downloading project failed'); diff --git a/src/test/javascript/spec/springboot/primary/react-generator/ReactGenerator.spec.ts b/src/test/javascript/spec/springboot/primary/generator/react-generator/ReactGenerator.spec.ts similarity index 82% rename from src/test/javascript/spec/springboot/primary/react-generator/ReactGenerator.spec.ts rename to src/test/javascript/spec/springboot/primary/generator/react-generator/ReactGenerator.spec.ts index 60095c8c663..f0a5fbdf242 100644 --- a/src/test/javascript/spec/springboot/primary/react-generator/ReactGenerator.spec.ts +++ b/src/test/javascript/spec/springboot/primary/generator/react-generator/ReactGenerator.spec.ts @@ -1,13 +1,14 @@ import { shallowMount, VueWrapper } from '@vue/test-utils'; import { ProjectToUpdate } from '@/springboot/primary/ProjectToUpdate'; -import { createProjectToUpdate } from '../ProjectToUpdate.fixture'; -import { stubLogger } from '../../../common/domain/Logger.fixture'; +import { createProjectToUpdate } from '../../ProjectToUpdate.fixture'; +import { stubLogger } from '../../../../common/domain/Logger.fixture'; import { Logger } from '@/common/domain/Logger'; import { ReactService } from '@/springboot/domain/client/ReactService'; -import { stubReactService } from '../../domain/client/ReactService.fixture'; -import { ReactGeneratorVue } from '@/springboot/primary/react-generator'; +import { stubReactService } from '../../../domain/client/ReactService.fixture'; +import { ReactGeneratorVue } from '@/springboot/primary/generator/react-generator'; let wrapper: VueWrapper; +let component: any; interface WrapperOptions { reactService: ReactService; @@ -33,6 +34,7 @@ const wrap = (wrapperOptions?: Partial) => { }, }, }); + component = wrapper.vm; }; describe('ReactGenerator', () => { @@ -47,8 +49,7 @@ describe('ReactGenerator', () => { reactService.add.resolves({}); await wrap({ reactService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#react'); - await button.trigger('click'); + await component.addReact(); expect(reactService.add.called).toBe(false); }); @@ -58,8 +59,7 @@ describe('ReactGenerator', () => { reactService.add.resolves({}); await wrap({ reactService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#react'); - await button.trigger('click'); + await component.addReact(); const args = reactService.add.getCall(0).args[0]; expect(args).toEqual({ @@ -78,8 +78,7 @@ describe('ReactGenerator', () => { const checkbox = wrapper.find('#react-with-style'); await checkbox.setValue(true); - const button = wrapper.find('#react'); - await button.trigger('click'); + await component.addReact(); const args = reactService.addWithStyle.getCall(0).args[0]; expect(args).toEqual({ @@ -97,8 +96,7 @@ describe('ReactGenerator', () => { reactService.add.rejects({}); await wrap({ reactService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#react'); - await initButton.trigger('click'); + await component.addReact(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding React to project failed'); @@ -112,8 +110,7 @@ describe('ReactGenerator', () => { const checkbox = wrapper.find('#react-with-style'); await checkbox.setValue(true); - const initButton = wrapper.find('#react'); - await initButton.trigger('click'); + await component.addReact(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding React with style to project failed'); diff --git a/src/test/javascript/spec/springboot/primary/spring-boot-generator/SpringBootGenerator.spec.ts b/src/test/javascript/spec/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.spec.ts similarity index 82% rename from src/test/javascript/spec/springboot/primary/spring-boot-generator/SpringBootGenerator.spec.ts rename to src/test/javascript/spec/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.spec.ts index 6de7f1b286d..473ac9ca613 100644 --- a/src/test/javascript/spec/springboot/primary/spring-boot-generator/SpringBootGenerator.spec.ts +++ b/src/test/javascript/spec/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.spec.ts @@ -1,13 +1,14 @@ import { shallowMount, VueWrapper } from '@vue/test-utils'; import { ProjectToUpdate } from '@/springboot/primary/ProjectToUpdate'; -import { createProjectToUpdate } from '../ProjectToUpdate.fixture'; -import { stubLogger } from '../../../common/domain/Logger.fixture'; +import { createProjectToUpdate } from '../../ProjectToUpdate.fixture'; +import { stubLogger } from '../../../../common/domain/Logger.fixture'; import { Logger } from '@/common/domain/Logger'; import { SpringBootService } from '@/springboot/domain/SpringBootService'; -import { stubSpringBootService } from '../../domain/SpringBootService.fixture'; -import { SpringBootGeneratorVue } from '@/springboot/primary/spring-boot-generator'; +import { stubSpringBootService } from '../../../domain/SpringBootService.fixture'; +import { SpringBootGeneratorVue } from '@/springboot/primary/generator/spring-boot-generator'; let wrapper: VueWrapper; +let component: any; interface WrapperOptions { springBootService: SpringBootService; @@ -33,6 +34,7 @@ const wrap = (wrapperOptions?: Partial) => { }, }, }); + component = wrapper.vm; }; describe('SpringBootGenerator', () => { @@ -47,8 +49,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBoot.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springboot'); - await button.trigger('click'); + await component.addSpringBoot(); expect(springBootService.addSpringBoot.called).toBe(false); }); @@ -58,8 +59,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBoot.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springboot'); - await button.trigger('click'); + await component.addSpringBoot(); const args = springBootService.addSpringBoot.getCall(0).args[0]; expect(args).toEqual({ @@ -77,8 +77,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBoot.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springboot'); - await initButton.trigger('click'); + await component.addSpringBoot(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot to project failed'); @@ -89,8 +88,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootMvcTomcat.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springbootmvctomcat'); - await button.trigger('click'); + await component.addSpringBootMvcTomcat(); expect(springBootService.addSpringBootMvcTomcat.called).toBe(false); }); @@ -100,8 +98,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootMvcTomcat.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springbootmvctomcat'); - await button.trigger('click'); + await component.addSpringBootMvcTomcat(); const args = springBootService.addSpringBootMvcTomcat.getCall(0).args[0]; expect(args).toEqual({ @@ -119,8 +116,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootMvcTomcat.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springbootmvctomcat'); - await initButton.trigger('click'); + await component.addSpringBootMvcTomcat(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot MVC with Tomcat to project failed'); @@ -131,8 +127,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootWebfluxNetty.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springbootwebfluxnetty'); - await button.trigger('click'); + await component.addSpringBootWebfluxNetty(); expect(springBootService.addSpringBootWebfluxNetty.called).toBe(false); }); @@ -142,8 +137,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootWebfluxNetty.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springbootwebfluxnetty'); - await button.trigger('click'); + await component.addSpringBootWebfluxNetty(); const args = springBootService.addSpringBootWebfluxNetty.getCall(0).args[0]; expect(args).toEqual({ @@ -161,8 +155,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootWebfluxNetty.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springbootwebfluxnetty'); - await initButton.trigger('click'); + await component.addSpringBootWebfluxNetty(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot Webflux with Netty to project failed'); @@ -173,8 +166,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootActuator.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springboot-actuator'); - await button.trigger('click'); + await component.addSpringBootActuator(); expect(springBootService.addSpringBootActuator.called).toBe(false); }); @@ -184,8 +176,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootActuator.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springboot-actuator'); - await button.trigger('click'); + await component.addSpringBootActuator(); const args = springBootService.addSpringBootActuator.getCall(0).args[0]; expect(args).toEqual({ @@ -203,8 +194,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootActuator.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springboot-actuator'); - await initButton.trigger('click'); + await component.addSpringBootActuator(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot Actuator to project failed'); @@ -217,8 +207,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootAopLogging.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springboot-aop'); - await button.trigger('click'); + await component.addSpringBootAopLogging(); expect(springBootService.addSpringBootAopLogging.called).toBe(false); }); @@ -228,8 +217,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootAopLogging.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springboot-aop'); - await button.trigger('click'); + await component.addSpringBootAopLogging(); const args = springBootService.addSpringBootAopLogging.getCall(0).args[0]; expect(args).toEqual({ @@ -247,8 +235,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootAopLogging.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springboot-aop'); - await initButton.trigger('click'); + await component.addSpringBootAopLogging(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot AOP Logging to project failed'); @@ -261,8 +248,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootLogstash.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springboot-logstash'); - await button.trigger('click'); + await component.addSpringBootLogstash(); expect(springBootService.addSpringBootLogstash.called).toBe(false); }); @@ -272,8 +258,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootLogstash.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springboot-logstash'); - await button.trigger('click'); + await component.addSpringBootLogstash(); const args = springBootService.addSpringBootLogstash.getCall(0).args[0]; expect(args).toEqual({ @@ -291,8 +276,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootLogstash.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springboot-logstash'); - await initButton.trigger('click'); + await component.addSpringBootLogstash(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot Logstash to project failed'); @@ -305,8 +289,7 @@ describe('SpringBootGenerator', () => { springBootService.addJWT.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springboot-jwt'); - await button.trigger('click'); + await component.addSpringBootSecurityJWT(); expect(springBootService.addJWT.called).toBe(false); }); @@ -316,8 +299,7 @@ describe('SpringBootGenerator', () => { springBootService.addJWT.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springboot-jwt'); - await button.trigger('click'); + await component.addSpringBootSecurityJWT(); const args = springBootService.addJWT.getCall(0).args[0]; expect(args).toEqual({ @@ -335,8 +317,7 @@ describe('SpringBootGenerator', () => { springBootService.addJWT.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springboot-jwt'); - await initButton.trigger('click'); + await component.addSpringBootSecurityJWT(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot Security JWT to project failed'); @@ -347,8 +328,7 @@ describe('SpringBootGenerator', () => { springBootService.addBasicAuthJWT.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springboot-jwt-basic-auth'); - await button.trigger('click'); + await component.addSpringBootSecurityJWTBasicAuth(); expect(springBootService.addBasicAuthJWT.called).toBe(false); }); @@ -358,8 +338,7 @@ describe('SpringBootGenerator', () => { springBootService.addBasicAuthJWT.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springboot-jwt-basic-auth'); - await button.trigger('click'); + await component.addSpringBootSecurityJWTBasicAuth(); const args = springBootService.addBasicAuthJWT.getCall(0).args[0]; expect(args).toEqual({ @@ -377,8 +356,7 @@ describe('SpringBootGenerator', () => { springBootService.addBasicAuthJWT.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springboot-jwt-basic-auth'); - await initButton.trigger('click'); + await component.addSpringBootSecurityJWTBasicAuth(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot Security JWT Basic Auth to project failed'); @@ -390,8 +368,7 @@ describe('SpringBootGenerator', () => { springBootService.addPostgres.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springboot-database-postgresql'); - await button.trigger('click'); + await component.addPostgreSQL(); expect(springBootService.addPostgres.called).toBe(false); }); @@ -401,8 +378,7 @@ describe('SpringBootGenerator', () => { springBootService.addPostgres.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springboot-database-postgresql'); - await button.trigger('click'); + await component.addPostgreSQL(); const args = springBootService.addPostgres.getCall(0).args[0]; expect(args).toEqual({ @@ -420,8 +396,7 @@ describe('SpringBootGenerator', () => { springBootService.addPostgres.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springboot-database-postgresql'); - await initButton.trigger('click'); + await component.addPostgreSQL(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot Database PostgreSQL to project failed'); @@ -432,8 +407,7 @@ describe('SpringBootGenerator', () => { springBootService.addMySQL.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springboot-database-mysql'); - await button.trigger('click'); + await component.addMySQL(); expect(springBootService.addMySQL.called).toBe(false); }); @@ -443,8 +417,7 @@ describe('SpringBootGenerator', () => { springBootService.addMySQL.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springboot-database-mysql'); - await button.trigger('click'); + await component.addMySQL(); const args = springBootService.addMySQL.getCall(0).args[0]; expect(args).toEqual({ @@ -462,8 +435,7 @@ describe('SpringBootGenerator', () => { springBootService.addMySQL.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springboot-database-mysql'); - await initButton.trigger('click'); + await component.addMySQL(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot Database MySQL to project failed'); @@ -474,8 +446,7 @@ describe('SpringBootGenerator', () => { springBootService.addMariaDB.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springboot-database-mariadb'); - await button.trigger('click'); + await component.addMariaDB(); expect(springBootService.addMariaDB.called).toBe(false); }); @@ -485,8 +456,7 @@ describe('SpringBootGenerator', () => { springBootService.addMariaDB.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springboot-database-mariadb'); - await button.trigger('click'); + await component.addMariaDB(); const args = springBootService.addMariaDB.getCall(0).args[0]; expect(args).toEqual({ @@ -504,8 +474,7 @@ describe('SpringBootGenerator', () => { springBootService.addMariaDB.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springboot-database-mariadb'); - await initButton.trigger('click'); + await component.addMariaDB(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot Database MariaDB to project failed'); @@ -516,8 +485,7 @@ describe('SpringBootGenerator', () => { springBootService.addMongoDB.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springboot-database-mongodb'); - await button.trigger('click'); + await component.addMongoDB(); expect(springBootService.addMongoDB.called).toBe(false); }); @@ -527,8 +495,7 @@ describe('SpringBootGenerator', () => { springBootService.addMongoDB.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springboot-database-mongodb'); - await button.trigger('click'); + await component.addMongoDB(); const args = springBootService.addMongoDB.getCall(0).args[0]; expect(args).toEqual({ @@ -546,8 +513,7 @@ describe('SpringBootGenerator', () => { springBootService.addMongoDB.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springboot-database-mongodb'); - await initButton.trigger('click'); + await component.addMongoDB(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot Database MongoDB to project failed'); @@ -560,8 +526,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootMongockInit.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#springboot-database-migration-mongock'); - await button.trigger('click'); + await component.addMongock(); expect(springBootService.addSpringBootMongockInit.called).toBe(false); }); @@ -571,8 +536,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootMongockInit.resolves({}); await wrap({ springBootService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#springboot-database-migration-mongock'); - await button.trigger('click'); + await component.addMongock(); const args = springBootService.addSpringBootMongockInit.getCall(0).args[0]; expect(args).toEqual({ @@ -590,8 +554,7 @@ describe('SpringBootGenerator', () => { springBootService.addSpringBootMongockInit.rejects({}); await wrap({ springBootService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#springboot-database-migration-mongock'); - await initButton.trigger('click'); + await component.addMongock(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding SpringBoot Database Migration Mongock to project failed'); diff --git a/src/test/javascript/spec/springboot/primary/svelte-generator/SvelteGenerator.spec.ts b/src/test/javascript/spec/springboot/primary/generator/svelte-generator/SvelteGenerator.spec.ts similarity index 79% rename from src/test/javascript/spec/springboot/primary/svelte-generator/SvelteGenerator.spec.ts rename to src/test/javascript/spec/springboot/primary/generator/svelte-generator/SvelteGenerator.spec.ts index 76ed9099a1d..f4795eb2221 100644 --- a/src/test/javascript/spec/springboot/primary/svelte-generator/SvelteGenerator.spec.ts +++ b/src/test/javascript/spec/springboot/primary/generator/svelte-generator/SvelteGenerator.spec.ts @@ -1,7 +1,7 @@ import { shallowMount, VueWrapper } from '@vue/test-utils'; import { ProjectToUpdate } from '@/springboot/primary/ProjectToUpdate'; -import { createProjectToUpdate } from '../ProjectToUpdate.fixture'; -import { SvelteGeneratorVue } from '@/springboot/primary/svelte-generator'; +import { createProjectToUpdate } from '../../ProjectToUpdate.fixture'; +import { SvelteGeneratorVue } from '@/springboot/primary/generator/svelte-generator'; let wrapper: VueWrapper; diff --git a/src/test/javascript/spec/springboot/primary/vue-generator/VueGenerator.spec.ts b/src/test/javascript/spec/springboot/primary/generator/vue-generator/VueGenerator.spec.ts similarity index 82% rename from src/test/javascript/spec/springboot/primary/vue-generator/VueGenerator.spec.ts rename to src/test/javascript/spec/springboot/primary/generator/vue-generator/VueGenerator.spec.ts index 30737ef0966..c155fd2ca02 100644 --- a/src/test/javascript/spec/springboot/primary/vue-generator/VueGenerator.spec.ts +++ b/src/test/javascript/spec/springboot/primary/generator/vue-generator/VueGenerator.spec.ts @@ -1,13 +1,14 @@ import { shallowMount, VueWrapper } from '@vue/test-utils'; import { ProjectToUpdate } from '@/springboot/primary/ProjectToUpdate'; -import { createProjectToUpdate } from '../ProjectToUpdate.fixture'; -import { stubLogger } from '../../../common/domain/Logger.fixture'; +import { createProjectToUpdate } from '../../ProjectToUpdate.fixture'; +import { stubLogger } from '../../../../common/domain/Logger.fixture'; import { Logger } from '@/common/domain/Logger'; import { VueService } from '@/springboot/domain/client/VueService'; -import { stubVueService } from '../../domain/client/VueService.fixture'; -import { VueGeneratorVue } from '@/springboot/primary/vue-generator'; +import { stubVueService } from '../../../domain/client/VueService.fixture'; +import { VueGeneratorVue } from '@/springboot/primary/generator/vue-generator'; let wrapper: VueWrapper; +let component: any; interface WrapperOptions { vueService: VueService; @@ -33,6 +34,7 @@ const wrap = (wrapperOptions?: Partial) => { }, }, }); + component = wrapper.vm; }; describe('VueGenerator', () => { @@ -47,8 +49,7 @@ describe('VueGenerator', () => { vueService.add.resolves({}); await wrap({ vueService, project: createProjectToUpdate({ folder: '' }) }); - const button = wrapper.find('#vue'); - await button.trigger('click'); + await component.addVue(); expect(vueService.add.called).toBe(false); }); @@ -58,8 +59,7 @@ describe('VueGenerator', () => { vueService.add.resolves({}); await wrap({ vueService, project: createProjectToUpdate({ folder: 'project/path' }) }); - const button = wrapper.find('#vue'); - await button.trigger('click'); + await component.addVue(); const args = vueService.add.getCall(0).args[0]; expect(args).toEqual({ @@ -78,8 +78,7 @@ describe('VueGenerator', () => { const checkbox = wrapper.find('#vue-with-style'); await checkbox.setValue(true); - const button = wrapper.find('#vue'); - await button.trigger('click'); + await component.addVue(); const args = vueService.addWithStyle.getCall(0).args[0]; expect(args).toEqual({ @@ -97,8 +96,7 @@ describe('VueGenerator', () => { vueService.add.rejects({}); await wrap({ vueService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); - const initButton = wrapper.find('#vue'); - await initButton.trigger('click'); + await component.addVue(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding Vue to project failed'); @@ -112,8 +110,7 @@ describe('VueGenerator', () => { const checkbox = wrapper.find('#vue-with-style'); await checkbox.setValue(true); - const initButton = wrapper.find('#vue'); - await initButton.trigger('click'); + await component.addVue(); const [message] = logger.error.getCall(0).args; expect(message).toBe('Adding Vue with style to project failed'); From 5cceca0be38e38101db652667966853427458c3c Mon Sep 17 00:00:00 2001 From: Quentin France Date: Sun, 1 May 2022 10:25:57 +0200 Subject: [PATCH 3/3] Frontend: Delay get current history on path update --- .../secondary/ProjectHistoryRepository.ts | 3 +- src/main/webapp/app/main.ts | 2 + .../springboot/primary/Generator.component.ts | 15 +++- .../app/springboot/primary/Generator.vue | 10 ++- .../SpringBootGenerator.vue | 7 +- .../ProjectHistoryRepository.spec.ts | 14 ++++ .../spec/springboot/primary/Generator.spec.ts | 82 ++++++++++++++++++- 7 files changed, 122 insertions(+), 11 deletions(-) diff --git a/src/main/webapp/app/common/secondary/ProjectHistoryRepository.ts b/src/main/webapp/app/common/secondary/ProjectHistoryRepository.ts index 60bfe64cdb7..e2edfcc4a8f 100644 --- a/src/main/webapp/app/common/secondary/ProjectHistoryRepository.ts +++ b/src/main/webapp/app/common/secondary/ProjectHistoryRepository.ts @@ -10,6 +10,7 @@ export default class ProjectHistoryRepository implements ProjectHistoryService { async get(folder: Folder): Promise { return this.axiosHttp .get('api/project-histories', { params: { folder } }) - .then(response => this.historyStore.setHistory(toHistory(response.data))); + .then(response => this.historyStore.setHistory(toHistory(response.data))) + .catch(() => this.historyStore.setHistory({ services: [] })); } } diff --git a/src/main/webapp/app/main.ts b/src/main/webapp/app/main.ts index 68c2958171a..74011934ea5 100644 --- a/src/main/webapp/app/main.ts +++ b/src/main/webapp/app/main.ts @@ -38,9 +38,11 @@ const springBootRepository = new SpringBootRepository(axiosHttp, projectHistoryR app.provide('angularService', angularRepository); app.provide('fileDownloader', fileDownloader); +app.provide('globalWindow', window); app.provide('historyStore', historyStore); app.provide('logger', consoleLogger); app.provide('projectService', projectRepository); +app.provide('projectHistoryService', projectHistoryRepository); app.provide('reactService', reactRepository); app.provide('springBootService', springBootRepository); app.provide('vueService', vueRepository); diff --git a/src/main/webapp/app/springboot/primary/Generator.component.ts b/src/main/webapp/app/springboot/primary/Generator.component.ts index 630ecc5734d..c77e5bf3d2c 100644 --- a/src/main/webapp/app/springboot/primary/Generator.component.ts +++ b/src/main/webapp/app/springboot/primary/Generator.component.ts @@ -1,4 +1,4 @@ -import { defineComponent, ref } from 'vue'; +import { defineComponent, inject, ref } from 'vue'; import { ProjectToUpdate } from '@/springboot/primary/ProjectToUpdate'; import { AngularGeneratorVue } from '@/springboot/primary/generator/angular-generator'; import { ReactGeneratorVue } from '@/springboot/primary/generator/react-generator'; @@ -9,6 +9,8 @@ import { DefaultButtonVue } from '@/common/primary/default-button'; import { HeaderVue } from '@/springboot/primary/header'; import { IconVue } from '@/common/primary/icon'; import { ProjectGeneratorVue } from '@/springboot/primary/generator/project-generator'; +import { ProjectHistoryService } from '@/common/domain/ProjectHistoryService'; +import { History } from '@/common/domain/History'; export default defineComponent({ name: 'GeneratorComponent', @@ -24,6 +26,8 @@ export default defineComponent({ VueGeneratorVue, }, setup() { + const projectHistoryService = inject('projectHistoryService') as ProjectHistoryService; + const globalWindow = inject('globalWindow') as Window; const selectorPrefix = 'generator'; const project = ref({ @@ -34,6 +38,13 @@ export default defineComponent({ const server = ref(); const client = ref(); + let timeoutId: number | undefined = undefined; + const getCurrentProjectHistory = (): Promise => projectHistoryService.get(project.value.folder); + const debounceGetProjectHistory = (): void => { + if (timeoutId) globalWindow.clearTimeout(timeoutId); + timeoutId = globalWindow.setTimeout(() => getCurrentProjectHistory, 400); + }; + return { project, language, @@ -41,6 +52,8 @@ export default defineComponent({ server, client, selectorPrefix, + getCurrentProjectHistory, + debounceGetProjectHistory, }; }, }); diff --git a/src/main/webapp/app/springboot/primary/Generator.vue b/src/main/webapp/app/springboot/primary/Generator.vue index 57353f01aec..7079fdc88de 100644 --- a/src/main/webapp/app/springboot/primary/Generator.vue +++ b/src/main/webapp/app/springboot/primary/Generator.vue @@ -7,7 +7,15 @@
- +
diff --git a/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.vue b/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.vue index 829bb4fd4e5..e2969a9b050 100644 --- a/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.vue +++ b/src/main/webapp/app/springboot/primary/generator/spring-boot-generator/SpringBootGenerator.vue @@ -67,12 +67,7 @@
- +
diff --git a/src/test/javascript/spec/common/secondary/ProjectHistoryRepository.spec.ts b/src/test/javascript/spec/common/secondary/ProjectHistoryRepository.spec.ts index 78dc40d247b..a3c02737b62 100644 --- a/src/test/javascript/spec/common/secondary/ProjectHistoryRepository.spec.ts +++ b/src/test/javascript/spec/common/secondary/ProjectHistoryRepository.spec.ts @@ -22,4 +22,18 @@ describe('ProjectRepository', () => { services: [Service.INITIALIZATION, Service.JAVA_BASE, Service.MAVEN_JAVA], }); }); + + it('should reset project history on fail', async () => { + const historyStoreStub = stubHistoryStore(); + const axiosHttpStub = stubAxiosHttp(); + axiosHttpStub.get.rejects(); + const projectHistoryRepository = new ProjectHistoryRepository(axiosHttpStub, historyStoreStub); + + await projectHistoryRepository.get('folder/path'); + + const [historyStored] = historyStoreStub.setHistory.getCall(0).args; + expect(historyStored).toEqual({ + services: [], + }); + }); }); diff --git a/src/test/javascript/spec/springboot/primary/Generator.spec.ts b/src/test/javascript/spec/springboot/primary/Generator.spec.ts index 19593b3a35a..87222772199 100644 --- a/src/test/javascript/spec/springboot/primary/Generator.spec.ts +++ b/src/test/javascript/spec/springboot/primary/Generator.spec.ts @@ -1,10 +1,88 @@ import { GeneratorVue } from '@/springboot/primary'; -import { shallowMount } from '@vue/test-utils'; +import { shallowMount, VueWrapper } from '@vue/test-utils'; +import { ProjectHistoryService } from '@/common/domain/ProjectHistoryService'; +import { stubProjectHistoryService } from '../../common/domain/ProjectHistoryService.fixture'; +import sinon, { SinonStub } from 'sinon'; + +let wrapper: VueWrapper; +let component: any; + +interface WrapperOptions { + projectHistoryService: ProjectHistoryService; + globalWindow: WindowStub; +} + +interface WindowStub { + clearTimeout: SinonStub; + setTimeout: SinonStub; +} + +const stubGlobalWindow = (): WindowStub => + ({ + clearTimeout: sinon.stub(), + setTimeout: sinon.stub(), + } as WindowStub); + +const wrap = (wrapperOptions?: Partial) => { + const { projectHistoryService, globalWindow }: WrapperOptions = { + projectHistoryService: stubProjectHistoryService(), + globalWindow: stubGlobalWindow(), + ...wrapperOptions, + }; + wrapper = shallowMount(GeneratorVue, { + global: { + provide: { + projectHistoryService, + globalWindow, + }, + }, + }); + component = wrapper.vm; +}; describe('Generator', () => { it('should exist', () => { - const wrapper = shallowMount(GeneratorVue); + wrap(); expect(wrapper.exists()).toBe(true); }); + + it('should get project history with current project folder', async () => { + const projectHistoryService = stubProjectHistoryService(); + wrap({ projectHistoryService }); + + const projectPathInput = wrapper.find('#path'); + await projectPathInput.setValue('path'); + component.getCurrentProjectHistory(); + + const path = projectHistoryService.get.getCall(0).args[0]; + expect(path).toEqual('path'); + }); + + it('should delay get project history', () => { + const projectHistoryService = stubProjectHistoryService(); + const globalWindow = stubGlobalWindow(); + wrap({ projectHistoryService, globalWindow }); + + component.debounceGetProjectHistory(); + + const [delayedMethod, timeout] = globalWindow.setTimeout.getCall(0).args; + expect(delayedMethod()).toEqual(component.getCurrentProjectHistory); + expect(timeout).toBe(400); + expect(globalWindow.clearTimeout.called).toBe(false); + }); + + it('should clear timeout', () => { + const TIMEOUT_ID = 1; + const projectHistoryService = stubProjectHistoryService(); + const globalWindow = stubGlobalWindow(); + globalWindow.setTimeout.returns(TIMEOUT_ID); + wrap({ projectHistoryService, globalWindow }); + + component.debounceGetProjectHistory(); + component.debounceGetProjectHistory(); + + const [timeoutId] = globalWindow.clearTimeout.getCall(0).args; + expect(timeoutId).toBe(TIMEOUT_ID); + }); });