Skip to content

Commit

Permalink
chore: refactor test can-skip-upstream-when-select-service-id.spec.js (
Browse files Browse the repository at this point in the history
  • Loading branch information
iamayushdas committed May 17, 2021
1 parent 4627ca5 commit b43be5a
Showing 1 changed file with 64 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,64 @@
/* eslint-disable no-undef */

context('Can select service_id skip upstream in route', () => {
const selector = {
name: '#name',
nodes_0_host: '#nodes_0_host',
nodes_0_port: '#nodes_0_port',
nodes_0_weight: '#nodes_0_weight',
notification: '.ant-notification-notice-message',
upstreamSelector: '[data-cy=upstream_selector]',
input: ':input',
nameSelector: '[title=Name]',
serviceSelector: '[title=test_service]',
deleteAlert: '.ant-modal-body',
notificationCloseIcon: '.ant-notification-close-icon',
};

const data = {
createUpstreamSuccess: 'Create Upstream Successfully',
createServiceSuccess: 'Create Service Successfully',
upstreamName: 'test_upstream',
serviceName: 'test_service',
routeName: 'test_route',
submitSuccess: 'Submit Successfully',
deleteUpstreamSuccess: 'Delete Upstream Successfully',
deleteServiceSuccess: 'Delete Service Successfully',
deleteRouteSuccess: 'Delete Route Successfully',
ip1: '127.0.0.1',
port0: '7000',
weight0: '1',
};

beforeEach(() => {
cy.login();

cy.fixture('selector.json').as('domSelector');
cy.fixture('data.json').as('data');
});

it('should create test upstream and service', function () {
cy.visit('/');
cy.contains('Upstream').click();
cy.contains('Create').click();

cy.get(this.domSelector.name).type(this.data.upstreamName);
cy.get(this.domSelector.nodes_0_host).type(this.data.ip1);
cy.get(this.domSelector.nodes_0_port).clear().type('7000');
cy.get(this.domSelector.nodes_0_weight).clear().type(1);
cy.get(selector.name).type(data.upstreamName);
cy.get(selector.nodes_0_host).type(data.ip1);
cy.get(selector.nodes_0_port).clear().type(data.port0);
cy.get(selector.nodes_0_weight).clear().type(data.weight0);
cy.contains('Next').click();
cy.contains('Submit').click();
cy.get(this.domSelector.notification).should('contain', this.data.createUpstreamSuccess);
cy.contains(this.data.createUpstreamSuccess);
cy.get(selector.notification).should('contain', data.createUpstreamSuccess);
cy.contains(data.createUpstreamSuccess);

cy.visit('/');
cy.contains('Service').click();
cy.contains('Create').click();
cy.get(this.domSelector.name).type(this.data.serviceName);
cy.get(this.domSelector.upstreamSelector).click();
cy.contains(this.data.upstreamName).click();
cy.get(selector.name).type(data.serviceName);
cy.get(selector.upstreamSelector).click();
cy.contains(data.upstreamName).click();
cy.contains('Next').click();
cy.contains('Next').click();
cy.contains('Submit').click();
cy.get(this.domSelector.notification).should('contain', this.data.createServiceSuccess);
cy.contains(this.data.createServiceSuccess);
cy.get(selector.notification).should('contain', data.createServiceSuccess);
cy.contains(data.createServiceSuccess);
});

it('should skip upstream module after service is selected when creating route', function () {
Expand All @@ -58,23 +84,23 @@ context('Can select service_id skip upstream in route', () => {

// The None option doesn't exist when service isn't selected
cy.contains('Next').click().click();
cy.get(this.domSelector.name).type(this.data.routeName);
cy.get(selector.name).type(data.routeName);
cy.contains('Next').click();
cy.get(this.domSelector.upstreamSelector).click();
cy.get(selector.upstreamSelector).click();
cy.get('.ant-select-item-option-disabled > .ant-select-item-option-content').contains('None');

cy.contains('Previous').click();
cy.wait(500);
cy.contains('None').click();
cy.contains(this.data.serviceName).click();
cy.contains(data.serviceName).click();
cy.contains('Next').click();

// make sure upstream data can be saved
cy.get(this.domSelector.upstreamSelector).click();
cy.contains(this.data.upstreamName).click();
cy.get(this.domSelector.input).should('be.disabled');
cy.get(selector.upstreamSelector).click();
cy.contains(data.upstreamName).click();
cy.get(selector.input).should('be.disabled');

cy.contains(this.data.upstreamName).click();
cy.contains(data.upstreamName).click();
cy.contains('None').click({ force: true });
cy.contains('Next').click();
cy.contains('Next').click();
Expand All @@ -86,41 +112,44 @@ context('Can select service_id skip upstream in route', () => {
cy.visit('/');
cy.contains('Route').click();

cy.get(this.domSelector.nameSelector).type(this.data.routeName);
cy.get(selector.nameSelector).type(data.routeName);
cy.contains('Search').click();
cy.contains(this.data.routeName).siblings().contains('Configure').click();
cy.get(this.domSelector.serviceSelector).click();
cy.contains(data.routeName).siblings().contains('Configure').click();
cy.get(selector.serviceSelector).click();
cy.contains('None').click();
cy.contains('Next').click();
cy.wait(500);
cy.get('[data-cy=upstream_selector]').click();
cy.contains(this.data.upstreamName).click();
cy.contains(data.upstreamName).click();
cy.contains('Next').click();
cy.contains('Next').click();
cy.contains('Submit').click();
cy.contains(this.data.submitSuccess);
cy.contains(data.submitSuccess);
});

it('should delete route, service and upstream', function () {
cy.visit('/');
cy.contains('Route').click();
cy.contains(this.data.routeName).siblings().contains('More').click();
cy.contains(data.routeName).siblings().contains('More').click();
cy.contains('Delete').click();
cy.get(this.domSelector.deleteAlert).should('be.visible').within(() => {
cy.contains('OK').click();
});
cy.get(selector.deleteAlert)
.should('be.visible')
.within(() => {
cy.contains('OK').click();
});

cy.get(this.domSelector.notification).should('contain', this.data.deleteRouteSuccess);
cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
cy.visit('/');
cy.contains('Service').click();
cy.contains(this.data.serviceName).siblings().contains('Delete').click();
cy.contains(data.serviceName).siblings().contains('Delete').click();
cy.contains('button', 'Confirm').click();
cy.get(this.domSelector.notification).should('contain', this.data.deleteServiceSuccess);
cy.get(selector.notification).should('contain', data.deleteServiceSuccess);

cy.visit('/');
cy.contains('Upstream').click();
cy.contains(this.data.upstreamName).siblings().contains('Delete').click();
cy.contains(data.upstreamName).siblings().contains('Delete').click();
cy.contains('button', 'Confirm').click();
cy.get(this.domSelector.notification).should('contain', this.data.deleteUpstreamSuccess);
cy.get(selector.notification).should('contain', data.deleteUpstreamSuccess);
cy.get(selector.notificationCloseIcon).click();
});
});

0 comments on commit b43be5a

Please sign in to comment.