Skip to content

Commit

Permalink
[cypress] Improve url patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Apr 6, 2021
1 parent d2a00cd commit ee7d165
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const skipCreateTest = (requiredRelationships.length > 0 || !entityFakeData) ? '
_%>

describe('<%= entityClass %> e2e test', () => {
const <%= entityInstance %>PageUrl = '/<%= entityUrl %>';
const <%= entityInstance %>PageUrlPattern = new RegExp('/<%= entityUrl %>(\\?.*)?$');

<%_ if (authenticationType === 'oauth2') { _%>
beforeEach(() => {
cy.getOauth2Data();
Expand Down Expand Up @@ -52,7 +55,7 @@ describe('<%= entityClass %> e2e test', () => {
<%_ } _%>

beforeEach(() => {
cy.intercept('GET', '/<%= baseApi + entityApiUrl %>').as('entitiesRequest');
cy.intercept('GET', '/<%= baseApi + entityApiUrl %>+(?*|)').as('entitiesRequest');
cy.intercept('POST', '/<%= baseApi + entityApiUrl %>').as('postEntityRequest');
cy.intercept('DELETE', '/<%= baseApi + entityApiUrl %>/*').as('deleteEntityRequest');
});
Expand All @@ -68,11 +71,11 @@ describe('<%= entityClass %> e2e test', () => {
}
});;
cy.getEntityHeading('<%= entityClass %>').should('exist');
cy.url().should('match', /\/<%= entityUrl %>(\?.*)?$/);
cy.url().should('match', <%= entityInstance %>PageUrlPattern);
});

it('should load details <%= entityClass %> page', function() {
cy.visit('/<%= entityUrl %>');
cy.visit(<%= entityInstance %>PageUrl);
cy.wait('@entitiesRequest').then(({ response }) => {
if (response.body.length === 0) {
this.skip();
Expand All @@ -84,12 +87,12 @@ describe('<%= entityClass %> e2e test', () => {
cy.wait('@entitiesRequest').then(({ response }) => {
expect(response.statusCode).to.equal(200);
});
cy.url().should('match', /\/<%= entityUrl %>(\?.*)?$/);
cy.url().should('match', <%= entityInstance %>PageUrlPattern);
});

<%_ if (!readOnly) { _%>
it('should load create <%= entityClass %> page', () => {
cy.visit('/<%= entityUrl %>');
cy.visit(<%= entityInstance %>PageUrl);
cy.wait('@entitiesRequest');
cy.get(entityCreateButtonSelector).click({force: true});
cy.getEntityCreateUpdateHeading('<%= entityClass %>');
Expand All @@ -98,11 +101,11 @@ describe('<%= entityClass %> e2e test', () => {
cy.wait('@entitiesRequest').then(({ response }) => {
expect(response.statusCode).to.equal(200);
});
cy.url().should('match', /\/<%= entityUrl %>(\?.*)?$/);
cy.url().should('match', <%= entityInstance %>PageUrlPattern);
});

it('should load edit <%= entityClass %> page', function() {
cy.visit('/<%= entityUrl %>');
cy.visit(<%= entityInstance %>PageUrl);
cy.wait('@entitiesRequest').then(({ response }) => {
if (response.body.length === 0) {
this.skip();
Expand All @@ -115,11 +118,11 @@ describe('<%= entityClass %> e2e test', () => {
cy.wait('@entitiesRequest').then(({ response }) => {
expect(response.statusCode).to.equal(200);
});
cy.url().should('match', /\/<%= entityUrl %>(\?.*)?$/);
cy.url().should('match', <%= entityInstance %>PageUrlPattern);
});

it<%= skipCreateTest %>('should create an instance of <%= entityClass %>', () => {
cy.visit('/<%= entityUrl %>');
cy.visit(<%= entityInstance %>PageUrl);
cy.get(entityCreateButtonSelector).click({force: true});
cy.getEntityCreateUpdateHeading('<%= entityClass %>');
<%_ fields.filter(field => (!field.id || !field.autoGenerate) && !field.hidden).forEach((field) => {
Expand Down Expand Up @@ -189,14 +192,14 @@ describe('<%= entityClass %> e2e test', () => {
cy.wait('@entitiesRequest').then(({ response }) => {
expect(response.statusCode).to.equal(200);
});
cy.url().should('match', /\/<%= entityUrl %>(\?.*)?$/);
cy.url().should('match', <%= entityInstance %>PageUrlPattern);
});

it<%= skipCreateTest %>('should delete last instance of <%= entityClass %>', function() {
<%_ if (clientFramework === 'react') { _%>
cy.intercept('GET', '/<%= baseApi + entityApiUrl %>/*').as('dialogDeleteRequest');
<%_ } _%>
cy.visit('/<%= entityUrl %>');
cy.visit(<%= entityInstance %>PageUrl);
cy.wait('@entitiesRequest').then(({ response }) => {
if (response.body.length > 0) {
cy.get(entityTableSelector).should('have.lengthOf', response.body.length);
Expand All @@ -212,7 +215,7 @@ describe('<%= entityClass %> e2e test', () => {
cy.wait('@entitiesRequest').then(({ response }) => {
expect(response.statusCode).to.equal(200);
});
cy.url().should('match', /\/<%= entityUrl %>(\?.*)?$/);
cy.url().should('match', <%= entityInstance %>PageUrlPattern);
} else {
this.skip();
}
Expand Down

0 comments on commit ee7d165

Please sign in to comment.