diff --git a/src/main/webapp/app/common/domain/Service.ts b/src/main/webapp/app/common/domain/Service.ts index 9a2407843b5..1f0521b8abe 100644 --- a/src/main/webapp/app/common/domain/Service.ts +++ b/src/main/webapp/app/common/domain/Service.ts @@ -11,6 +11,7 @@ export enum Service { MARIADB = 'MARIADB', MYSQL = 'MYSQL', MONGODB = 'MONGODB', + MONGOCK = 'MONGOCK', POSTGRESQL = 'POSTGRESQL', SONAR_JAVA_BACKEND = 'SONAR_JAVA_BACKEND', SONAR_JAVA_BACKEND_AND_FRONTEND = 'SONAR_JAVA_BACKEND_AND_FRONTEND', diff --git a/src/main/webapp/app/common/primary/HistoryStore.ts b/src/main/webapp/app/common/primary/HistoryStore.ts index 8d8780bc737..08e3ba248bd 100644 --- a/src/main/webapp/app/common/primary/HistoryStore.ts +++ b/src/main/webapp/app/common/primary/HistoryStore.ts @@ -1,5 +1,6 @@ import { defineStore } from 'pinia'; import { History } from '@/common/domain/History'; +import { Service } from '@/common/domain/Service'; const emptyHistory = (): History => ({ services: [], @@ -14,6 +15,10 @@ export const useHistoryStore = defineStore('HistoryStore', { getters: { getHistory: state => state.history, + hasCalledService: + state => + (service: Service): boolean => + state.history.services.includes(service), }, actions: { 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/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 655321645a6..f1063934f06 100644 --- a/src/test/javascript/cypress/integration/Generator.spec.ts +++ b/src/test/javascript/cypress/integration/Generator.spec.ts @@ -2,6 +2,7 @@ import { composeSelector, dataSelector } from '../support/selector'; const generatorSelector = (name: string) => dataSelector(composeSelector('generator', name)); const headerSelector = (name: string) => dataSelector(composeSelector('header', name)); +const projectGeneratorSelector = (name: string) => dataSelector(composeSelector('project-generator', name)); const springBootGeneratorSelector = (name: string) => dataSelector(composeSelector('spring-boot-generator', name)); const angularGeneratorSelector = (name: string) => dataSelector(composeSelector('angular-generator', name)); const reactGeneratorSelector = (name: string) => dataSelector(composeSelector('react-generator', name)); @@ -20,34 +21,35 @@ describe('Generator', () => { it('should display generator page', () => { cy.get(headerSelector('title')).contains('JHipster lite'); - cy.get(generatorSelector('init-button')).contains('Init'); - cy.get(generatorSelector('add-maven-button')).contains('Maven'); - cy.get(generatorSelector('add-jacoco-button')).contains('JaCoCo'); - cy.get(generatorSelector('add-sonar-backend-button')).contains('Sonar Backend'); - cy.get(generatorSelector('add-sonar-backend-frontend-button')).contains('Sonar Backend+Frontend'); - cy.get(generatorSelector('add-java-base-button')).contains('Java Base'); - cy.get(generatorSelector('add-frontend-maven-plugin-button')).contains('Frontend Maven Plugin'); - cy.get(generatorSelector('download-button')).should('not.exist'); + 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('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', () => { @@ -72,6 +74,6 @@ describe('Generator', () => { it('should display download button when project path is filled', () => { cy.get('#path').type('/tmp/jhlite'); - cy.get(generatorSelector('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/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/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.spec.ts b/src/test/javascript/spec/springboot/primary/Generator.spec.ts index 6f6e4ef8bdb..87222772199 100644 --- a/src/test/javascript/spec/springboot/primary/Generator.spec.ts +++ b/src/test/javascript/spec/springboot/primary/Generator.spec.ts @@ -1,51 +1,43 @@ -import { ProjectService } from '@/springboot/domain/ProjectService'; import { GeneratorVue } from '@/springboot/primary'; import { shallowMount, VueWrapper } from '@vue/test-utils'; -import { stubProjectService } from '../domain/ProjectService.fixture'; -import { ProjectToUpdate } from '@/springboot/primary/ProjectToUpdate'; -import { createProjectToUpdate } from './ProjectToUpdate.fixture'; -import { stubLogger } from '../../common/domain/Logger.fixture'; -import { Logger } from '@/common/domain/Logger'; -import { FileDownloader } from '@/common/primary/FileDownloader'; -import { stubFileDownloader } from '../../common/primary/FileDownloader.fixture'; +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 { - logger: Logger; - projectService: ProjectService; - fileDownloader: FileDownloader; + 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 { logger, fileDownloader, projectService }: WrapperOptions = { - logger: stubLogger(), - fileDownloader: stubFileDownloader(), - projectService: stubProjectService(), + const { projectHistoryService, globalWindow }: WrapperOptions = { + projectHistoryService: stubProjectHistoryService(), + globalWindow: stubGlobalWindow(), ...wrapperOptions, }; wrapper = shallowMount(GeneratorVue, { global: { provide: { - logger, - fileDownloader, - projectService, + projectHistoryService, + globalWindow, }, }, }); -}; - -const fillFullForm = async (projectToUpdate: ProjectToUpdate): Promise => { - const projectPathInput = wrapper.find('#path'); - await projectPathInput.setValue(projectToUpdate.folder); - const baseNameInput = wrapper.find('#basename'); - await baseNameInput.setValue(projectToUpdate.baseName); - const projectNameInput = wrapper.find('#projectname'); - await projectNameInput.setValue(projectToUpdate.projectName); - const packageNameInput = wrapper.find('#packagename'); - await packageNameInput.setValue(projectToUpdate.packageName); - const serverPortInput = wrapper.find('#serverport'); - await serverPortInput.setValue(projectToUpdate.serverPort); + component = wrapper.vm; }; describe('Generator', () => { @@ -55,441 +47,42 @@ describe('Generator', () => { expect(wrapper.exists()).toBe(true); }); - it('should not init project when project path is not filled', async () => { - const projectService = stubProjectService(); - projectService.init.resolves({}); - await wrap({ projectService }); - - const initButton = wrapper.find('#init'); - await initButton.trigger('click'); - - expect(projectService.init.called).toBe(false); - }); - - it('should init project when project path is filled', async () => { - const projectService = stubProjectService(); - projectService.init.resolves({}); - await wrap({ projectService }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ - folder: 'project/path', - baseName: 'beer', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: '8080', - }); - await fillFullForm(projectToUpdate); - - const initButton = wrapper.find('#init'); - await initButton.trigger('click'); - - const args = projectService.init.getCall(0).args[0]; - expect(args).toEqual({ - baseName: 'beer', - folder: 'project/path', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: 8080, - }); - }); - - it('should handle error on init failure', async () => { - const logger = stubLogger(); - const projectService = stubProjectService(); - projectService.init.rejects({}); - await wrap({ projectService, logger }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate(); - await fillFullForm(projectToUpdate); - - const initButton = wrapper.find('#init'); - await initButton.trigger('click'); - - const [message] = logger.error.getCall(0).args; - expect(message).toBe('Project initialization failed'); - }); - - it('should not add Maven when project path is not filled', async () => { - const projectService = stubProjectService(); - projectService.addMaven.resolves({}); - await wrap({ projectService }); - - const button = wrapper.find('#maven'); - await button.trigger('click'); - - expect(projectService.addMaven.called).toBe(false); - }); - - it('should add Maven when project path is filled', async () => { - const projectService = stubProjectService(); - projectService.addMaven.resolves({}); - await wrap({ projectService }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ - folder: 'project/path', - baseName: 'beer', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: '8080', - }); - await fillFullForm(projectToUpdate); - - const button = wrapper.find('#maven'); - await button.trigger('click'); - - const args = projectService.addMaven.getCall(0).args[0]; - expect(args).toEqual({ - baseName: 'beer', - folder: 'project/path', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: 8080, - }); - }); - - it('should handle error on adding maven failure', async () => { - const logger = stubLogger(); - const projectService = stubProjectService(); - projectService.addMaven.rejects({}); - await wrap({ projectService, logger }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate(); - await fillFullForm(projectToUpdate); - - const initButton = wrapper.find('#maven'); - await initButton.trigger('click'); - - const [message] = logger.error.getCall(0).args; - expect(message).toBe('Adding Maven to project failed'); - }); - - it('should not add JaCoCo when project path is not filled', async () => { - const projectService = stubProjectService(); - projectService.addJaCoCo.resolves({}); - await wrap({ projectService }); + it('should get project history with current project folder', async () => { + const projectHistoryService = stubProjectHistoryService(); + wrap({ projectHistoryService }); - const button = wrapper.find('#jacoco'); - await button.trigger('click'); + const projectPathInput = wrapper.find('#path'); + await projectPathInput.setValue('path'); + component.getCurrentProjectHistory(); - expect(projectService.addJaCoCo.called).toBe(false); + const path = projectHistoryService.get.getCall(0).args[0]; + expect(path).toEqual('path'); }); - it('should add JaCoCo when project path is filled', async () => { - const projectService = stubProjectService(); - projectService.addJaCoCo.resolves({}); - await wrap({ projectService }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ - folder: 'project/path', - baseName: 'beer', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: '8080', - }); - await fillFullForm(projectToUpdate); - - const button = wrapper.find('#jacoco'); - await button.trigger('click'); - - const args = projectService.addJaCoCo.getCall(0).args[0]; - expect(args).toEqual({ - baseName: 'beer', - folder: 'project/path', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: 8080, - }); - }); - - it('should handle error on adding JaCoCo failure', async () => { - const logger = stubLogger(); - const projectService = stubProjectService(); - projectService.addJaCoCo.rejects({}); - await wrap({ projectService, logger }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate(); - await fillFullForm(projectToUpdate); - - const initButton = wrapper.find('#jacoco'); - await initButton.trigger('click'); - - const [message] = logger.error.getCall(0).args; - expect(message).toBe('Adding JaCoCo to project failed'); - }); - - it('should not add Sonar Backend when project path is not filled', async () => { - const projectService = stubProjectService(); - projectService.addSonarBackend.resolves({}); - await wrap({ projectService }); - - const button = wrapper.find('#sonar-backend'); - await button.trigger('click'); - - expect(projectService.addSonarBackend.called).toBe(false); - }); - - it('should add Sonar Backend when project path is filled', async () => { - const projectService = stubProjectService(); - projectService.addSonarBackend.resolves({}); - await wrap({ projectService }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ - folder: 'project/path', - baseName: 'beer', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: '8080', - }); - await fillFullForm(projectToUpdate); - - const button = wrapper.find('#sonar-backend'); - await button.trigger('click'); - - const args = projectService.addSonarBackend.getCall(0).args[0]; - expect(args).toEqual({ - baseName: 'beer', - folder: 'project/path', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: 8080, - }); - }); - - it('should handle error on adding Sonar Backend failure', async () => { - const logger = stubLogger(); - const projectService = stubProjectService(); - projectService.addSonarBackend.rejects({}); - await wrap({ projectService, logger }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate(); - await fillFullForm(projectToUpdate); - - const initButton = wrapper.find('#sonar-backend'); - await initButton.trigger('click'); - - const [message] = logger.error.getCall(0).args; - expect(message).toBe('Adding Sonar Backend to project failed'); - }); - - it('should not add Sonar Backend+Frontend when project path is not filled', async () => { - const projectService = stubProjectService(); - projectService.addSonarBackendFrontend.resolves({}); - await wrap({ projectService }); - - const button = wrapper.find('#sonar-backend-frontend'); - await button.trigger('click'); - - expect(projectService.addSonarBackendFrontend.called).toBe(false); - }); - - it('should add Sonar Backend+Frontend when project path is filled', async () => { - const projectService = stubProjectService(); - projectService.addSonarBackendFrontend.resolves({}); - await wrap({ projectService }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ - folder: 'project/path', - baseName: 'beer', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: '8080', - }); - await fillFullForm(projectToUpdate); - - const button = wrapper.find('#sonar-backend-frontend'); - await button.trigger('click'); - - const args = projectService.addSonarBackendFrontend.getCall(0).args[0]; - expect(args).toEqual({ - baseName: 'beer', - folder: 'project/path', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: 8080, - }); - }); - - it('should handle error on adding Sonar Backend+Frontend failure', async () => { - const logger = stubLogger(); - const projectService = stubProjectService(); - projectService.addSonarBackendFrontend.rejects({}); - await wrap({ projectService, logger }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate(); - await fillFullForm(projectToUpdate); - - const initButton = wrapper.find('#sonar-backend-frontend'); - await initButton.trigger('click'); - - const [message] = logger.error.getCall(0).args; - expect(message).toBe('Adding Sonar Backend+Frontend to project failed'); - }); - - it('should not add JavaBase when project path is not filled', async () => { - const projectService = stubProjectService(); - projectService.addJavaBase.resolves({}); - await wrap({ projectService }); - - const button = wrapper.find('#javabase'); - await button.trigger('click'); - - expect(projectService.addJavaBase.called).toBe(false); - }); - - it('should add JavaBase when project path is filled', async () => { - const projectService = stubProjectService(); - projectService.addJavaBase.resolves({}); - await wrap({ projectService }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ - folder: 'project/path', - baseName: 'beer', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: '8080', - }); - await fillFullForm(projectToUpdate); - - const button = wrapper.find('#javabase'); - await button.trigger('click'); - - const args = projectService.addJavaBase.getCall(0).args[0]; - expect(args).toEqual({ - baseName: 'beer', - folder: 'project/path', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: 8080, - }); - }); - - it('should handle error on adding java base failure', async () => { - const logger = stubLogger(); - const projectService = stubProjectService(); - projectService.addJavaBase.rejects({}); - await wrap({ projectService, logger }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate(); - await fillFullForm(projectToUpdate); - - const initButton = wrapper.find('#javabase'); - await initButton.trigger('click'); - - const [message] = logger.error.getCall(0).args; - expect(message).toBe('Adding Java Base to project failed'); - }); - - it('should not add Frontend Maven Plugin when project path is not filled', async () => { - const projectService = stubProjectService(); - projectService.addFrontendMavenPlugin.resolves({}); - await wrap({ projectService }); - - const button = wrapper.find('#frontend-maven-plugin'); - await button.trigger('click'); - - expect(projectService.addFrontendMavenPlugin.called).toBe(false); - }); - - it('should add Frontend Maven Plugin when project path is filled', async () => { - const projectService = stubProjectService(); - projectService.addFrontendMavenPlugin.resolves({}); - await wrap({ projectService }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ - folder: 'project/path', - baseName: 'beer', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: '8080', - }); - await fillFullForm(projectToUpdate); - - const button = wrapper.find('#frontend-maven-plugin'); - await button.trigger('click'); - - const args = projectService.addFrontendMavenPlugin.getCall(0).args[0]; - expect(args).toEqual({ - baseName: 'beer', - folder: 'project/path', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: 8080, - }); - }); - - it('should handle error on adding Frontend Maven Plugin failure', async () => { - const logger = stubLogger(); - const projectService = stubProjectService(); - projectService.addFrontendMavenPlugin.rejects({}); - await wrap({ projectService, logger }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate(); - await fillFullForm(projectToUpdate); - - const initButton = wrapper.find('#frontend-maven-plugin'); - await initButton.trigger('click'); - - const [message] = logger.error.getCall(0).args; - expect(message).toBe('Adding Frontend Maven Plugin to project failed'); - }); - - it('should download initialized project with basename', async () => { - const projectService = stubProjectService(); - projectService.download.resolves({}); - // @ts-ignore - global.URL.createObjectURL = jest.fn(() => new Blob([{}], { type: 'application/zip' })); - - await wrap({ projectService }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ - folder: 'project/path', - baseName: 'beer', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: '8080', - }); - await fillFullForm(projectToUpdate); - - const button = wrapper.find('#download'); - await button.trigger('click'); - - const args = projectService.download.getCall(0).args[0]; - expect(args).toEqual({ - baseName: 'beer', - folder: 'project/path', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: 8080, - }); - }); - - it('should download initialized project without basename', async () => { - const projectService = stubProjectService(); - projectService.download.resolves({}); - // @ts-ignore - global.URL.createObjectURL = jest.fn(() => new Blob([{}], { type: 'application/zip' })); - - await wrap({ projectService }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ - folder: 'project/path', - baseName: '', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: '8080', - }); - await fillFullForm(projectToUpdate); + it('should delay get project history', () => { + const projectHistoryService = stubProjectHistoryService(); + const globalWindow = stubGlobalWindow(); + wrap({ projectHistoryService, globalWindow }); - const button = wrapper.find('#download'); - await button.trigger('click'); + component.debounceGetProjectHistory(); - const args = projectService.download.getCall(0).args[0]; - expect(args).toEqual({ - baseName: '', - folder: 'project/path', - projectName: 'Beer Project', - packageName: 'tech.jhipster.beer', - serverPort: 8080, - }); + 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 not download an non existing project', async () => { - const logger = stubLogger(); - const projectService = stubProjectService(); - projectService.download.rejects(new Error('foo')); - await wrap({ projectService, logger }); - const projectToUpdate: ProjectToUpdate = createProjectToUpdate(); - await fillFullForm(projectToUpdate); + it('should clear timeout', () => { + const TIMEOUT_ID = 1; + const projectHistoryService = stubProjectHistoryService(); + const globalWindow = stubGlobalWindow(); + globalWindow.setTimeout.returns(TIMEOUT_ID); + wrap({ projectHistoryService, globalWindow }); - const downloadButton = wrapper.find('#download'); - await downloadButton.trigger('click'); + component.debounceGetProjectHistory(); + component.debounceGetProjectHistory(); - const [message, error] = logger.error.getCall(0).args; - expect(message).toBe('Downloading project failed'); - expect(error).toStrictEqual(new Error('foo')); + const [timeoutId] = globalWindow.clearTimeout.getCall(0).args; + expect(timeoutId).toBe(TIMEOUT_ID); }); }); 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/generator/project-generator/ProjectGenerator.spec.ts b/src/test/javascript/spec/springboot/primary/generator/project-generator/ProjectGenerator.spec.ts new file mode 100644 index 00000000000..062e02b343c --- /dev/null +++ b/src/test/javascript/spec/springboot/primary/generator/project-generator/ProjectGenerator.spec.ts @@ -0,0 +1,435 @@ +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 { Logger } from '@/common/domain/Logger'; +import { ProjectService } from '@/springboot/domain/ProjectService'; +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'; + +let wrapper: VueWrapper; +let component: any; + +interface WrapperOptions { + projectService: ProjectService; + fileDownloader: FileDownloader; + logger: Logger; + project: ProjectToUpdate; +} + +const wrap = (wrapperOptions?: Partial) => { + const { projectService, fileDownloader, logger, project }: WrapperOptions = { + projectService: stubProjectService(), + fileDownloader: stubFileDownloader(), + logger: stubLogger(), + project: createProjectToUpdate(), + ...wrapperOptions, + }; + wrapper = shallowMount(ProjectGeneratorVue, { + props: { + project, + buildTool: 'maven', + }, + global: { + provide: { + projectService, + fileDownloader, + logger, + }, + }, + }); + component = wrapper.vm; +}; + +describe('ProjectGenerator', () => { + it('should exist', () => { + wrap(); + + expect(wrapper.exists()).toBe(true); + }); + + it('should not init project when project path is not filled', async () => { + const projectService = stubProjectService(); + projectService.init.resolves({}); + await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); + + await component.initProject(); + + expect(projectService.init.called).toBe(false); + }); + + it('should init project when project path is filled', async () => { + const projectService = stubProjectService(); + projectService.init.resolves({}); + const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ + folder: 'project/path', + baseName: 'beer', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: '8080', + }); + await wrap({ projectService, project: projectToUpdate }); + + await component.initProject(); + + const args = projectService.init.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + }); + + it('should handle error on init failure', async () => { + const logger = stubLogger(); + const projectService = stubProjectService(); + projectService.init.rejects({}); + await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.initProject(); + + const [message] = logger.error.getCall(0).args; + expect(message).toBe('Project initialization failed'); + }); + + it('should not add Maven when project path is not filled', async () => { + const projectService = stubProjectService(); + projectService.addMaven.resolves({}); + await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); + + await component.addMaven(); + + expect(projectService.addMaven.called).toBe(false); + }); + + it('should add Maven when project path is filled', async () => { + const projectService = stubProjectService(); + projectService.addMaven.resolves({}); + const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ + folder: 'project/path', + baseName: 'beer', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: '8080', + }); + await wrap({ projectService, project: projectToUpdate }); + + await component.addMaven(); + + const args = projectService.addMaven.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + }); + + it('should handle error on adding maven failure', async () => { + const logger = stubLogger(); + const projectService = stubProjectService(); + projectService.addMaven.rejects({}); + await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.addMaven(); + + const [message] = logger.error.getCall(0).args; + expect(message).toBe('Adding Maven to project failed'); + }); + + it('should not add JaCoCo when project path is not filled', async () => { + const projectService = stubProjectService(); + projectService.addJaCoCo.resolves({}); + await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); + + await component.addJaCoCo(); + + expect(projectService.addJaCoCo.called).toBe(false); + }); + + it('should add JaCoCo when project path is filled', async () => { + const projectService = stubProjectService(); + projectService.addJaCoCo.resolves({}); + const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ + folder: 'project/path', + baseName: 'beer', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: '8080', + }); + await wrap({ projectService, project: projectToUpdate }); + + await component.addJaCoCo(); + + const args = projectService.addJaCoCo.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + }); + + it('should handle error on adding JaCoCo failure', async () => { + const logger = stubLogger(); + const projectService = stubProjectService(); + projectService.addJaCoCo.rejects({}); + await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.addJaCoCo(); + + const [message] = logger.error.getCall(0).args; + expect(message).toBe('Adding JaCoCo to project failed'); + }); + + it('should not add Sonar Backend when project path is not filled', async () => { + const projectService = stubProjectService(); + projectService.addSonarBackend.resolves({}); + await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); + + await component.addSonarBackend(); + + expect(projectService.addSonarBackend.called).toBe(false); + }); + + it('should add Sonar Backend when project path is filled', async () => { + const projectService = stubProjectService(); + projectService.addSonarBackend.resolves({}); + const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ + folder: 'project/path', + baseName: 'beer', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: '8080', + }); + await wrap({ projectService, project: projectToUpdate }); + + await component.addSonarBackend(); + + const args = projectService.addSonarBackend.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + }); + + it('should handle error on adding Sonar Backend failure', async () => { + const logger = stubLogger(); + const projectService = stubProjectService(); + projectService.addSonarBackend.rejects({}); + await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.addSonarBackend(); + + const [message] = logger.error.getCall(0).args; + expect(message).toBe('Adding Sonar Backend to project failed'); + }); + + it('should not add Sonar Backend+Frontend when project path is not filled', async () => { + const projectService = stubProjectService(); + projectService.addSonarBackendFrontend.resolves({}); + await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); + + await component.addSonarBackendFrontend(); + + expect(projectService.addSonarBackendFrontend.called).toBe(false); + }); + + it('should add Sonar Backend+Frontend when project path is filled', async () => { + const projectService = stubProjectService(); + projectService.addSonarBackendFrontend.resolves({}); + const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ + folder: 'project/path', + baseName: 'beer', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: '8080', + }); + await wrap({ projectService, project: projectToUpdate }); + + await component.addSonarBackendFrontend(); + + const args = projectService.addSonarBackendFrontend.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + }); + + it('should handle error on adding Sonar Backend+Frontend failure', async () => { + const logger = stubLogger(); + const projectService = stubProjectService(); + projectService.addSonarBackendFrontend.rejects({}); + await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.addSonarBackendFrontend(); + + const [message] = logger.error.getCall(0).args; + expect(message).toBe('Adding Sonar Backend+Frontend to project failed'); + }); + + it('should not add JavaBase when project path is not filled', async () => { + const projectService = stubProjectService(); + projectService.addJavaBase.resolves({}); + await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); + + await component.addJavaBase(); + + expect(projectService.addJavaBase.called).toBe(false); + }); + + it('should add JavaBase when project path is filled', async () => { + const projectService = stubProjectService(); + projectService.addJavaBase.resolves({}); + const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ + folder: 'project/path', + baseName: 'beer', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: '8080', + }); + await wrap({ projectService, project: projectToUpdate }); + + await component.addJavaBase(); + + const args = projectService.addJavaBase.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + }); + + it('should handle error on adding java base failure', async () => { + const logger = stubLogger(); + const projectService = stubProjectService(); + projectService.addJavaBase.rejects({}); + await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.addJavaBase(); + + const [message] = logger.error.getCall(0).args; + expect(message).toBe('Adding Java Base to project failed'); + }); + + it('should not add Frontend Maven Plugin when project path is not filled', async () => { + const projectService = stubProjectService(); + projectService.addFrontendMavenPlugin.resolves({}); + await wrap({ projectService, project: createProjectToUpdate({ folder: '' }) }); + + await component.addFrontendMavenPlugin(); + + expect(projectService.addFrontendMavenPlugin.called).toBe(false); + }); + + it('should add Frontend Maven Plugin when project path is filled', async () => { + const projectService = stubProjectService(); + projectService.addFrontendMavenPlugin.resolves({}); + const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ + folder: 'project/path', + baseName: 'beer', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: '8080', + }); + await wrap({ projectService, project: projectToUpdate }); + + await component.addFrontendMavenPlugin(); + + const args = projectService.addFrontendMavenPlugin.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + }); + + it('should handle error on adding Frontend Maven Plugin failure', async () => { + const logger = stubLogger(); + const projectService = stubProjectService(); + projectService.addFrontendMavenPlugin.rejects({}); + await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.addFrontendMavenPlugin(); + + const [message] = logger.error.getCall(0).args; + expect(message).toBe('Adding Frontend Maven Plugin to project failed'); + }); + + it('should download initialized project with basename', async () => { + const projectService = stubProjectService(); + projectService.download.resolves({}); + const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ + folder: 'project/path', + baseName: 'beer', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: '8080', + }); + await wrap({ projectService, project: projectToUpdate }); + + await component.download(); + + const args = projectService.download.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + }); + + it('should download initialized project without basename', async () => { + const projectService = stubProjectService(); + projectService.download.resolves({}); + const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ + folder: 'project/path', + baseName: 'beer', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: '8080', + }); + await wrap({ projectService, project: projectToUpdate }); + + await component.download(); + + const args = projectService.download.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + }); + + it('should not download an non existing project', async () => { + const logger = stubLogger(); + const projectService = stubProjectService(); + projectService.download.rejects(new Error('foo')); + await wrap({ projectService, logger, project: createProjectToUpdate({ folder: 'project/path' }) }); + + await component.download(); + + const [message, error] = logger.error.getCall(0).args; + expect(message).toBe('Downloading project failed'); + expect(error).toStrictEqual(new Error('foo')); + }); +}); 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');