Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add domSelector and data for search-route #1339

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 52 additions & 28 deletions web/cypress/integration/route/search-route.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,34 @@
/* eslint-disable no-undef */

context('Create and Search Route', () => {
const timeout = 500;
const data = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data for testcases, LGTM

host1: '11.11.11.11',
host2: '12.12.12.12',
test: 'test',
test0: 'test0',
test1: 'test1',
test2: 'test2',
testx: 'testx',
desc0: 'desc0',
desc1: 'desc1',
desc2: 'desc2',
value0: 'value0',
label0_value0: 'label0:value0',
deleteRouteSuccess: 'Delete Route Successfully',
};
const domSelector = {
name: '#name',
desc: '#desc',
hosts_0: '#hosts_0',
labels_0_labelKey: '#labels_0_labelKey',
labels_0_labelValue: '#labels_0_labelValue',
nodes_0_host: '#nodes_0_host',
searchName: '[title=Name]',
searchLabels: '[title=Labels]',
};

beforeEach(() => {
// init login
cy.login();
cy.fixture('selector.json').as('domSelector');
});
Expand All @@ -29,25 +55,24 @@ context('Create and Search Route', () => {
cy.contains('Route').click();
for (let i = 0; i < 3; i += 1) {
cy.contains('Create').click();
cy.get('#name').type(`test${i}`);
cy.get('#desc').type(`desc${i}`);
cy.get('#hosts_0').type('11.11.11.11');
cy.get(domSelector.name).type(`test${i}`);
cy.get(domSelector.desc).type(`desc${i}`);
cy.get(domSelector.hosts_0).type(data.host1);

// config label
cy.contains('Manage').click();

// eslint-disable-next-line no-loop-func
cy.get(this.domSelector.drawerBody).within(() => {
cy.contains('Add').click();
cy.get('#labels_0_labelKey').type(`label${i}`);
cy.get('#labels_0_labelValue').type(`value${i}`);
cy.get(domSelector.labels_0_labelKey).type(`label${i}`);
cy.get(domSelector.labels_0_labelValue).type(`value${i}`);
cy.contains('Confirm').click();
});

cy.contains('Next').click();
cy.wait(400);
cy.get('#nodes_0_host').type('12.12.12.12', {
timeout: 500,
cy.get(domSelector.nodes_0_host).type(data.host2, {
timeout,
});
cy.contains('Next').click();
cy.contains('Next').click();
Expand All @@ -63,51 +88,50 @@ context('Create and Search Route', () => {
cy.visit('/');
cy.contains('Route').click();
// full match
cy.get('[title=Name]').type('test1');
cy.get(domSelector.searchName).type(data.test1);
cy.contains('Search').click();
cy.contains('test1').siblings().should('contain', 'desc1');
cy.contains('test0').should('not.exist');
cy.contains('test2').should('not.exist');
cy.contains(data.test1).siblings().should('contain', data.desc1);
cy.contains(data.test0).should('not.exist');
cy.contains(data.test2).should('not.exist');
// partial match
cy.reload();
cy.get('[title=Name]').type('test');
cy.get(domSelector.searchName).type(data.test);
cy.contains('Search').click();
cy.contains('test0').siblings().should('contain', 'desc0');
cy.contains('test1').siblings().should('contain', 'desc1');
cy.contains('test2').siblings().should('contain', 'desc2');
cy.contains(data.test0).siblings().should('contain', data.desc0);
cy.contains(data.test1).siblings().should('contain', data.desc1);
cy.contains(data.test2).siblings().should('contain', data.desc2);
// no match
cy.reload();
cy.get('[title=Name]').type('testx');
cy.get(domSelector.searchName).type(data.testx);
cy.contains('Search').click();
cy.contains('test0').should('not.exist');
cy.contains('test1').should('not.exist');
cy.contains('test2').should('not.exist');
cy.contains(data.test0).should('not.exist');
cy.contains(data.test1).should('not.exist');
cy.contains(data.test2).should('not.exist');
});

it('should search the route with labels', function () {
cy.visit('/');
cy.contains('Route').click();

// search one label
cy.get('[title=Labels]').click();
cy.wait(500);
cy.get(domSelector.searchLabels).click();
cy.get(this.domSelector.dropdown).within(() => {
cy.contains('value0').click();
cy.contains(data.value0).click();
});
cy.contains('Search').click();

cy.contains('test0').siblings().should('contain', 'label0:value0');
cy.contains('test1').should('not.exist');
cy.contains('test2').should('not.exist');
cy.contains(data.test0).siblings().should('contain', data.label0_value0);
cy.contains(data.test1).should('not.exist');
cy.contains(data.test2).should('not.exist');
});

it('should delete the route', function () {
cy.visit('/routes/list');
for (let i = 0; i < 3; i += 1) {
cy.contains(`test${i}`).siblings().contains('Delete').click();
cy.contains('button', 'Confirm').click();
cy.get(this.domSelector.notification).should('contain', 'Delete Route Successfully');
cy.wait(300);
cy.get(this.domSelector.notification).should('contain', data.deleteRouteSuccess);
}
});
});