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 proxy-mirror plugin form #1725

Merged
merged 29 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1acb995
feat: add proxy-mirror form
LiteSun Apr 9, 2021
8136c15
feat: update
LiteSun Apr 9, 2021
11bf7f9
fix: ci
LiteSun Apr 9, 2021
f02d0c5
feat: update ci
LiteSun Apr 9, 2021
28ba08f
fix: ci
LiteSun Apr 9, 2021
457dccb
feat: add proxy-mirror plugin form
LiteSun Apr 9, 2021
2b743e1
fix: ci
LiteSun Apr 9, 2021
2b71a7e
fix: lint
LiteSun Apr 9, 2021
f10c60a
fix: ci
LiteSun Apr 9, 2021
ae5a3dc
Merge branch 'master' into proxy-mirror-form
LiteSun Apr 9, 2021
0d7b781
test: update
LiteSun Apr 10, 2021
81e1107
fix: ci unstable
LiteSun Apr 10, 2021
f0b596c
Merge branch 'fix-fe-ci' into proxy-mirror-form
LiteSun Apr 10, 2021
3f3045c
fix: ci
LiteSun Apr 10, 2021
4c59311
fix: ci
LiteSun Apr 10, 2021
8143999
fix: ci
LiteSun Apr 10, 2021
34c9921
fix: ci
LiteSun Apr 10, 2021
12b5500
Merge branch 'fix-fe-ci' into proxy-mirror-form
LiteSun Apr 10, 2021
54d1ccd
feat: update i18n
LiteSun Apr 11, 2021
d84d919
Merge remote-tracking branch 'upstream/master' into proxy-mirror-form
LiteSun Apr 11, 2021
814892b
fix: lint
LiteSun Apr 11, 2021
2b5df55
Merge branch 'master' into proxy-mirror-form
LiteSun Apr 11, 2021
86ec8a6
Merge branch 'master' into proxy-mirror-form
LiteSun Apr 12, 2021
53e7ac3
feat: add rule tip
LiteSun Apr 12, 2021
2b13d81
feat: udpate test case
LiteSun Apr 12, 2021
dd5d849
test: add create-route-with-proxy-mirror-form.spec
LiteSun Apr 13, 2021
6191a40
feat: update
LiteSun Apr 13, 2021
4b4ff42
Merge branch 'master' into proxy-mirror-form
LiteSun Apr 14, 2021
43a6890
Merge branch 'master' into proxy-mirror-form
LiteSun Apr 14, 2021
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
1 change: 0 additions & 1 deletion web/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"viewportHeight": 1080,
"baseUrl": "http://localhost:8000",
"video": true,
"numTestsKeptInMemory": 0,
"videoUploadOnPasses": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-undef */

context('Create and Delete Consumer', () => {
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
beforeEach(() => {
cy.login();

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

const selector = {
host: "#host"
}

const data = {
correctHost: 'http://127.0.0.1',
wrongHost: '127.0.0.1:1999'
}
Copy link
Member

Choose a reason for hiding this comment

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

Please write directly in the test case, not this layer of data structure

Copy link
Member Author

Choose a reason for hiding this comment

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

TBH, I think it's more intuitive to write it this way.


it('creates consumer with proxy-mirror form', function () {
Copy link
Member

Choose a reason for hiding this comment

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

why we need consumer?

cy.visit('/');
cy.contains('Consumer').click();
cy.get(this.domSelector.empty).should('be.visible');
cy.contains('Create').click();
// basic information
cy.get(this.domSelector.username).type(this.data.consumerName);
cy.get(this.domSelector.description).type(this.data.description);
cy.contains('Next').click();

// config auth plugin
cy.contains(this.domSelector.pluginCard, 'key-auth').within(() => {
cy.contains('Enable').click({
force: true,
});
});
cy.focused(this.domSelector.drawer).should('exist');
cy.get(this.domSelector.disabledSwitcher).click();
// edit codemirror
cy.get(this.domSelector.codeMirror)
.first()
.then((editor) => {
editor[0].CodeMirror.setValue(
JSON.stringify({
key: 'test',
}),
);
cy.contains('button', 'Submit').click();
});

Comment on lines +43 to +61
Copy link
Member

Choose a reason for hiding this comment

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

why we need key-auth plugin?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is because an authentication plugin is required when creating a Consumer.

cy.contains(this.domSelector.pluginCard, 'proxy-mirror').within(() => {
cy.contains('Enable').click({
force: true,
});
});

cy.focused(this.domSelector.drawer).should('exist');

// config proxy-mirror form
cy.get(selector.host).type(data.wrongHost);
cy.get(this.domSelector.drawer).within(() => {
cy.contains('Submit').click({
force: true,
});
});
cy.get(this.domSelector.notification).should('contain', 'Invalid plugin data');

cy.get(selector.host).clear().type(data.correctHost);
cy.get(this.domSelector.disabledSwitcher).click();
cy.get(this.domSelector.drawer).within(() => {
cy.contains('Submit').click({
force: true,
});
});
cy.get(this.domSelector.drawer).should('not.exist');

cy.contains('button', 'Next').click();
cy.contains('button', 'Submit').click();
cy.get(this.domSelector.notification).should('contain', this.data.createConsumerSuccess);
});

it('delete the consumer', function () {
cy.visit('/consumer/list');
cy.contains(this.data.consumerName).should('be.visible').siblings().contains('Delete').click();
cy.contains('button', 'Confirm').click();
cy.get(this.domSelector.notification).should('contain', this.data.deleteConsumerSuccess);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ context('Create PluginTemplate Binding To Route', () => {

cy.visit('/routes/list');
cy.contains('Create').click();
cy.get(this.domSelector.empty).should('be.visible');
cy.get(this.domSelector.name).click();

// NOTE: make sure all components rerender done
cy.contains('Next').click().click();
cy.get(this.domSelector.name).type(this.data.routeName);
cy.contains('Next').click();
cy.get(this.domSelector.nodes_0_host).type(this.data.ip1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ context('Create and Delete Route', () => {
cy.contains('Search').click();
cy.contains(name).siblings().contains('Configure').click();

cy.wait(500);
// NOTE: make sure all components rerender done
cy.get('#status').should('have.class', 'ant-switch-checked');
cy.get(this.domSelector.name).clear().type(newName);
cy.get(this.domSelector.description).clear().type(this.data.description2);
cy.contains('Next').click();
Expand All @@ -166,13 +167,15 @@ context('Create and Delete Route', () => {
it('should duplicate the route', function () {
cy.visit('/');
cy.contains('Route').click();
cy.reload();

cy.get(this.domSelector.nameSelector).type(newName);
cy.contains('Search').click();
cy.contains(newName).siblings().contains('More').click();
cy.contains('Duplicate').click();

cy.wait(500);
// NOTE: make sure all components rerender done
cy.get('#status').should('have.class', 'ant-switch-checked');
cy.get(this.domSelector.name).clear().type(duplicateNewName);
cy.get(this.domSelector.description).clear().type(this.data.description2);
cy.contains('Next').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ context('create route with proxy-rewrite plugin', () => {
cy.get(this.domSelector.nameSelector).type(this.data.routeName);
cy.contains('Search').click();
cy.contains(this.data.routeName).siblings().contains('Configure').click();
cy.wait(500);

// NOTE: make sure all components rerender done
cy.get('#status').should('have.class', 'ant-switch-checked');
cy.get(this.domSelector.name).type(this.data.routeName);

cy.contains(routeLocaleUS['page.route.form.itemLabel.newPath']).should('be.visible');
Expand Down
3 changes: 1 addition & 2 deletions web/cypress/integration/route/search-route.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ context('Create and Search Route', () => {
});

it('should search the route with labels', function () {
cy.visit('/routes/list');
// search one label
cy.contains(data.test0).should('exist');
cy.reload();
cy.get(this.domSelector.labelSelect_0).click({ timeout });
cy.get(this.domSelector.dropdown).contains(data.value0).should('be.visible').click();
cy.contains('Search').click();
Expand Down
31 changes: 23 additions & 8 deletions web/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,41 @@ Cypress.Commands.add('configurePlugins', (cases) => {

// NOTE: wait for the Drawer to appear on the DOM
cy.focused(domSelector.drawer).should('exist');

cy.get(domSelector.codeMirrorMode).invoke('text').then(text => {
if (text === 'Form') {
// FIXME: https://github.com/cypress-io/cypress/issues/7306
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
cy.wait(5000);
cy.get(domSelector.codeMirrorMode).should('be.visible');
cy.get(domSelector.codeMirrorMode).click();
cy.get(domSelector.selectDropdown).should('be.visible');
cy.get(domSelector.selectJSON).click();
}
});

cy.get(domSelector.drawer, { timeout }).within(() => {
cy.get(domSelector.switch).click({
force: true,
});
});

cy.get(domSelector.codeMirrorMode).invoke('text').then(text => {
if (text === 'Form') {
// FIXME: https://github.com/cypress-io/cypress/issues/7306
cy.wait(5000);
cy.get(domSelector.codeMirrorMode).should('be.visible');
cy.get(domSelector.codeMirrorMode).click();
cy.get(domSelector.selectDropdown).should('be.visible');
cy.get(domSelector.selectJSON).click();
}
});

cy.window().then(({ codemirror }) => {
if (codemirror) {
codemirror.setValue(JSON.stringify(data));
}
cy.get(domSelector.drawer).should('exist');

cy.get(domSelector.codeMirrorMode).invoke('text').then(text => {
if (text === 'Form') {
cy.get(domSelector.codeMirrorMode).click();
cy.get(domSelector.selectDropdown).should('be.visible');
cy.get(domSelector.selectJSON).click();
}
});

cy.get(domSelector.drawer, { timeout }).within(() => {
cy.contains('Submit').click({
force: true,
Expand Down
7 changes: 5 additions & 2 deletions web/src/components/Plugin/UI/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ import { FormInstance } from 'antd/es/form';
import { Empty } from 'antd';
import { useIntl } from 'umi';

import BasicAuth from './basic-auth'
import BasicAuth from './basic-auth';
import ProxyMirror from './proxy-mirror';

type Props = {
name: string,
form: FormInstance,
renderForm: boolean
}

export const PLUGIN_UI_LIST = ['basic-auth',];
export const PLUGIN_UI_LIST = ['basic-auth', 'proxy-mirror'];

export const PluginForm: React.FC<Props> = ({ name, renderForm, form }) => {

Expand All @@ -38,6 +39,8 @@ export const PluginForm: React.FC<Props> = ({ name, renderForm, form }) => {
switch (name) {
case 'basic-auth':
return <BasicAuth form={form} />
case 'proxy-mirror':
return <ProxyMirror form={form} />
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
default:
return null;
}
Expand Down
51 changes: 51 additions & 0 deletions web/src/components/Plugin/UI/proxy-mirror.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import type { FormInstance } from 'antd/es/form';
import { Form, Input } from 'antd';

type Props = {
form: FormInstance;
};

const FORM_ITEM_LAYOUT = {
labelCol: {
span: 3,
},
wrapperCol: {
span: 10
},
};

const ProxyMirror: React.FC<Props> = ({ form }) => {
return (
<Form
form={form}
{...FORM_ITEM_LAYOUT}
>
<Form.Item
label="host"
name="host"
tooltip='Specify a mirror service address, e.g. http://127.0.0.1:9797 (address needs to contain schema: http or https, not URI part)'
>
<Input />
LiteSun marked this conversation as resolved.
Show resolved Hide resolved
</Form.Item>
</Form>
);
}

export default ProxyMirror;