Skip to content

Commit

Permalink
Merge pull request #2239 from DamnClin/modules-cypress-test
Browse files Browse the repository at this point in the history
Add cypress tests to modules page
  • Loading branch information
pascalgrimaud authored Jun 28, 2022
2 parents 5732c37 + 4ed3911 commit 42259b7
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/test/javascript/cypress/cypress-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export default defineConfig({
e2e: {
baseUrl: 'http://localhost:7471',
specPattern: 'src/test/javascript/cypress/integration/**/*.spec.ts',
fixturesFolder: false,
fixturesFolder: 'src/test/javascript/cypress/fixtures',
supportFolder: 'src/test/javascript/cypress/support',
supportFile: false,
video: false,
},
Expand Down
38 changes: 38 additions & 0 deletions src/test/javascript/cypress/fixtures/modules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"categories": [
{
"name": "Spring",
"modules": [
{
"slug": "spring-cucumber",
"description": "Add cucumber to the application",
"properties": {
"definitions": [
{
"type": "STRING",
"mandatory": true,
"key": "baseName",
"description": "Application base name",
"example": "jhipster"
},
{
"type": "BOOLEAN",
"mandatory": false,
"key": "optionalBoolean"
},
{
"type": "INTEGER",
"mandatory": false,
"key": "optionalInteger"
}
]
}
},
{
"slug": "spring-test",
"description": "Add spring test to the application"
}
]
}
]
}
81 changes: 78 additions & 3 deletions src/test/javascript/cypress/integration/Modules.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,84 @@
import { dataSelector } from '../support/selector';
import { interceptForever } from '../support/Interceptor';

describe('Modules', () => {
it('Should display modules', () => {
cy.visit('/modules');
describe('E2E', () => {
it('Should display modules', () => {
cy.visit('/modules');

cy.get(dataSelector('modules-list')).should('be.visible');
cy.get(dataSelector('modules-list')).should('be.visible');
});
});

describe('Component', () => {
it('Should display loader while loading modules', () => {
const result = interceptForever({ path: '/api/modules' }, { fixture: 'modules.json' });

cy.visit('/modules');

cy.get(dataSelector('modules-loader'))
.should('be.visible')
.then(() => {
result.send();

cy.get(dataSelector('modules-loader')).should('not.exist');
cy.get(dataSelector('modules-list')).should('be.visible');
cy.get(dataSelector('module-spring-test-application-button')).should('be.disabled');
cy.get(dataSelector('module-spring-cucumber-application-button')).should('be.disabled');
});
});

it('Should apply module without properties', () => {
cy.intercept({ path: '/api/modules' }, { fixture: 'modules.json' });

cy.intercept({
path: '/api/modules/spring-test/apply',
method: 'POST',
}).as('spring-test-creation');

cy.visit('/modules');
cy.get(dataSelector('folder-path-field')).type('test');
cy.get(dataSelector('module-spring-test-application-button')).click();

cy.wait('@spring-test-creation').should(xhr => {
const body = xhr.request.body;

expect(body).to.deep.equal({
projectFolder: 'test',
properties: {},
});
});
});

it('Should apply module with properties', () => {
cy.intercept({ path: '/api/modules' }, { fixture: 'modules.json' });

cy.intercept({
path: '/api/modules/spring-cucumber/apply',
method: 'POST',
}).as('spring-cucumber-creation');

cy.visit('/modules');

cy.get(dataSelector('spring-cucumber-module-content')).click();
cy.get(dataSelector('folder-path-field')).type('test');
cy.get(dataSelector('property-baseName-field')).type('jhipster');
cy.get(dataSelector('property-optionalBoolean-field')).select('true');
cy.get(dataSelector('property-optionalInteger-field')).type('42');
cy.get(dataSelector('module-spring-cucumber-application-button')).click();

cy.wait('@spring-cucumber-creation').should(xhr => {
const body = xhr.request.body;

expect(body).to.deep.equal({
projectFolder: 'test',
properties: {
baseName: 'jhipster',
optionalBoolean: true,
optionalInteger: 42,
},
});
});
});
});
});
21 changes: 21 additions & 0 deletions src/test/javascript/cypress/support/Interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { HttpResponseInterceptor, RouteMatcher, StaticResponse } from '../../../../../node_modules/cypress/types/net-stubbing';

type ResponseSender = {
send: () => void;
};

export const interceptForever = (requestMatcher: RouteMatcher, response?: StaticResponse | HttpResponseInterceptor): ResponseSender => {
let send;

const trigger = new Promise(resolve => {
send = resolve;
});

cy.intercept(requestMatcher, request => {
return trigger.then(() => {
request.reply(response);
});
});

return { send };
};

0 comments on commit 42259b7

Please sign in to comment.