Skip to content

Commit

Permalink
test: add edit the plugin (#1372)
Browse files Browse the repository at this point in the history
  • Loading branch information
guoqqqi authored Jan 28, 2021
1 parent 6e39bcb commit fb048ee
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
4 changes: 3 additions & 1 deletion web/cypress/integration/lang/switch-language.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ context('Switch language', () => {

cy.get(domSelector.switcher).click('right');
cy.contains('简体中文').click({
force: true,
timeout,
});
cy.contains('服务').click();

cy.get(domSelector.switcher).click('right');
cy.contains('English').click({
force: true,
timeout,
});
cy.contains('Create');
cy.contains('Create').should('exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@

context('Create and Delete Plugin List', () => {
const timeout = 5000;
const domSelectors = {
const data = {
name: 'hmac-auth',
};
const domSelector = {
tableCell: '.ant-table-cell',
empty: '.ant-empty-normal',
refresh: '.anticon-reload',
codemirror: '.CodeMirror',
switch: '#disable',
};

beforeEach(() => {
Expand All @@ -36,14 +41,30 @@ context('Create and Delete Plugin List', () => {
cy.contains('Create').click();

// add test plugins
cy.configurePlugins(this.cases);
cy.get('@cases').then((cases) => {
cy.configurePlugins(cases);
})
});

it('should edit the plugin', () => {
cy.visit('/plugin/list');
cy.get(domSelector.refresh).click();
cy.contains(data.name).should('exist').siblings().contains('Edit').click({
force: true,
});
cy.get(domSelector.codemirror)
.first()
.then(() => {
cy.get(domSelector.switch).click();
cy.contains('button', 'Submit').click();
});
cy.contains(data.name).should('not.exist');
});

it('should delete plugin list', () => {
cy.visit('/');
cy.contains('Plugin').click();
cy.get(domSelectors.refresh).click();
cy.get(domSelectors.tableCell).then(function (rows) {
cy.visit('/plugin/list');
cy.get(domSelector.refresh).click();
cy.get(domSelector.tableCell, { timeout }).should('exist').then(function (rows) {
[...rows].forEach((row) => {
const name = row.innerText;
const cases = this.cases[name] || [];
Expand All @@ -56,6 +77,6 @@ context('Create and Delete Plugin List', () => {
});

// check if plugin list is empty
cy.get(domSelectors.empty);
cy.get(domSelector.empty).should('be.visible');
});
});
4 changes: 3 additions & 1 deletion web/cypress/integration/plugin/schema-smocktest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ context('smoke test for plugin schema', () => {
cy.contains('Plugin').click();
cy.contains('Create').click();

cy.configurePlugins(this.cases);
cy.get('@cases').then((cases) => {
cy.configurePlugins(cases);
})
});
});
23 changes: 10 additions & 13 deletions web/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ Cypress.Commands.add('login', () => {
});

Cypress.Commands.add('configurePlugins', (cases) => {
const timeout = 50000;
const timeout = 300;
const domSelectors = {
name: '[data-cy-plugin-name]',
parents: '.ant-card-bordered',
drawer_wrap: '.ant-drawer-content-wrapper',
drawer: '.ant-drawer-content',
switch: '#disable',
close: '.anticon-close',
};

cy.get(domSelectors.name).then(function (cards) {
cy.get(domSelectors.name, { timeout }).then(function (cards) {
[...cards].forEach((card) => {
const name = card.innerText;
const pluginCases = cases[name] || [];
Expand All @@ -56,46 +57,42 @@ Cypress.Commands.add('configurePlugins', (cases) => {
.within(() => {
cy.contains('Enable').click({
force: true,
timeout,
});
});

// NOTE: wait for the Drawer to appear on the DOM
cy.wait(300);
cy.get(domSelectors.drawer, { timeout }).within(() => {
cy.get(domSelectors.switch).click({
force: true,
timeout,
});
});

cy.window().then(({ codemirror }) => {
if (codemirror) {
codemirror.setValue(JSON.stringify(data));
}
});

cy.get(domSelectors.drawer).within(() => {
cy.contains('Submit').click({
force: true,
timeout,
cy.get(domSelectors.drawer, { timeout }).within(() => {
cy.contains('Submit').click({
force: true,
});
});
});

cy.wait(300);
if (shouldValid === true) {
cy.get(domSelectors.drawer).should('not.exist');
} else if (shouldValid === false) {
cy.get(this.selector.notification).should('contain', 'Invalid plugin data');

cy.get(domSelectors.close).click({
force: true,
timeout,
multiple: true,
});

cy.get(domSelectors.drawer).within(() => {
cy.get(domSelectors.drawer, { timeout }).invoke('show').within(() => {
cy.contains('Cancel').click({
force: true,
timeout,
});
});
}
Expand Down

0 comments on commit fb048ee

Please sign in to comment.