Skip to content

Commit d3e1861

Browse files
lookbrookpenghui.yang
andauthored
feat: add new route matching param position (#1984)
Co-authored-by: penghui.yang <[email protected]>
1 parent 9764dad commit d3e1861

File tree

6 files changed

+208
-3
lines changed

6 files changed

+208
-3
lines changed
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
/* eslint-disable no-undef */
18+
19+
context('Create Route with advanced matching conditions', () => {
20+
const selector = {
21+
name: '#name',
22+
nodes_0_host: '#nodes_0_host',
23+
nodes_0_port: '#nodes_0_port',
24+
nodes_0_weight: '#nodes_0_weight',
25+
deleteAlert: '.ant-modal-body',
26+
notificationCloseIcon: '.ant-notification-close-icon',
27+
notification: '.ant-notification-notice-message',
28+
parameterPosition: '#position',
29+
ruleCard: '.ant-modal',
30+
operator: '#operator',
31+
value: '#value',
32+
advancedMatchingTable: '.ant-table-row.ant-table-row-level-0',
33+
advancedMatchingTableOperation: '.ant-space',
34+
advancedMatchingTableCell: '.ant-table-cell',
35+
};
36+
37+
const data = {
38+
routeName: `test_route_${new Date().valueOf()}`,
39+
submitSuccess: 'Submit Successfully',
40+
ip1: '127.0.0.1',
41+
port: '80',
42+
weight: 1,
43+
matchingParamName: 'server_port',
44+
deleteRouteSuccess: 'Delete Route Successfully',
45+
};
46+
47+
const opreatorList = [
48+
// 'Equal(==)' : '1234',
49+
'Unequal(~=)',
50+
'Greater Than(>)',
51+
'Less Than(<)',
52+
// 'Regex Match(~~)',
53+
'IN',
54+
];
55+
56+
const matchingValueList1 = ['1000', '800', '2000', '["1800","1888"]'];
57+
58+
const matchingValueList2 = ['2000', '1800', '3000', '["2800","2888"]'];
59+
60+
beforeEach(() => {
61+
cy.login();
62+
});
63+
64+
it('should create route with advanced matching conditions', function () {
65+
cy.visit('/routes/list');
66+
cy.contains('Create').click();
67+
cy.contains('Next').click().click();
68+
cy.get(selector.name).type(data.routeName);
69+
70+
// All Of Operational Character Should Exist And Can be Created
71+
cy.wrap(opreatorList).each((opreator, index) => {
72+
cy.contains('Advanced Routing Matching Conditions')
73+
.parent()
74+
.siblings()
75+
.contains('Add')
76+
.click()
77+
.then(() => {
78+
cy.get(selector.parameterPosition)
79+
.click()
80+
.then(() => {
81+
cy.get('.ant-select-dropdown').within(() => {
82+
cy.contains('Build-in').should('be.visible').click();
83+
});
84+
});
85+
cy.get(selector.ruleCard).within(() => {
86+
cy.get(selector.name).type(data.matchingParamName);
87+
});
88+
cy.get(selector.operator).click();
89+
cy.get(`[title="${opreator}"]`).should('be.visible').click();
90+
cy.get(selector.value).type(matchingValueList1[index]);
91+
cy.contains('Confirm').click();
92+
});
93+
});
94+
cy.get(selector.advancedMatchingTable).should('exist');
95+
cy.wrap(opreatorList).each((operator, index) => {
96+
cy.get(selector.advancedMatchingTableCell).within(() => {
97+
cy.contains('td', 'Build-in Parameter').should('be.visible');
98+
cy.contains('td', data.matchingParamName).should('be.visible');
99+
cy.contains('td', matchingValueList1[index]).should('be.visible');
100+
});
101+
});
102+
cy.contains('Next').click();
103+
cy.get(selector.nodes_0_host).clear().type(data.ip1);
104+
cy.get(selector.nodes_0_port).type(data.port);
105+
cy.get(selector.nodes_0_weight).type(data.weight);
106+
cy.contains('Next').click();
107+
cy.contains('Next').click();
108+
cy.contains('Submit').click();
109+
cy.contains(data.submitSuccess).should('be.visible');
110+
cy.contains('Goto List').click();
111+
cy.url().should('contains', 'routes/list');
112+
});
113+
114+
it('should edit this route matching conditions', function () {
115+
cy.visit('/routes/list');
116+
cy.get(selector.name).clear().type(data.routeName);
117+
cy.contains('Search').click();
118+
cy.contains(data.routeName).siblings().contains('Configure').click();
119+
cy.get(selector.advancedMatchingTable).should('exist');
120+
cy.wrap(opreatorList).each((opreator, index) => {
121+
cy.get(selector.advancedMatchingTableCell).within(() => {
122+
cy.contains(`${opreator}`)
123+
.parent('tr')
124+
.within(() => {
125+
cy.get(selector.advancedMatchingTableOperation).within(() => {
126+
cy.contains('Configure').click();
127+
});
128+
});
129+
});
130+
cy.get(selector.ruleCard).within(() => {
131+
cy.get(`[title="Build-in Parameter"]`).should('have.class', 'ant-select-selection-item');
132+
cy.get(selector.name).clear().type(data.matchingParamName);
133+
cy.get(`[title="${opreator}"]`).should('have.class', 'ant-select-selection-item');
134+
cy.get(selector.value).clear().type(matchingValueList2[index]);
135+
cy.contains('Confirm').click();
136+
});
137+
cy.get(selector.advancedMatchingTableCell).within(() => {
138+
cy.contains('td', 'Build-in Parameter').should('be.visible');
139+
cy.contains('td', data.matchingParamName).should('be.visible');
140+
cy.contains('td', matchingValueList2[index]).should('be.visible');
141+
});
142+
});
143+
cy.contains('Next').click();
144+
cy.get(selector.nodes_0_port).focus();
145+
cy.contains('Next').click();
146+
cy.contains('Next').click();
147+
cy.contains('Submit').click();
148+
cy.contains(data.submitSuccess);
149+
cy.contains('Goto List').click();
150+
cy.url().should('contains', 'routes/list');
151+
});
152+
153+
it('should delete route matching conditions', function () {
154+
cy.visit('/routes/list');
155+
cy.get(selector.name).clear().type(data.routeName);
156+
cy.contains('Search').click();
157+
cy.contains(data.routeName).siblings().contains('Configure').click();
158+
cy.get(selector.name).should('value', data.routeName);
159+
cy.get(selector.advancedMatchingTable).should('exist');
160+
cy.wrap(opreatorList).each(() => {
161+
cy.get(selector.advancedMatchingTableOperation).within(() => {
162+
cy.contains('Delete').click().should('not.exist');
163+
});
164+
});
165+
cy.get(selector.advancedMatchingTable).should('not.exist');
166+
cy.contains('Next').click();
167+
cy.get(selector.nodes_0_port).focus();
168+
cy.contains('Next').click();
169+
cy.contains('Next').click();
170+
cy.contains('Submit').click();
171+
cy.contains(data.submitSuccess);
172+
cy.contains('Goto List').click();
173+
cy.url().should('contains', 'routes/list');
174+
175+
cy.visit('/routes/list');
176+
cy.get(selector.name).clear().type(data.routeName);
177+
cy.contains('Search').click();
178+
cy.contains(data.routeName).siblings().contains('More').click();
179+
cy.contains('Delete').click();
180+
cy.get(selector.deleteAlert)
181+
.should('be.visible')
182+
.within(() => {
183+
cy.contains('OK').click();
184+
});
185+
cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
186+
cy.get(selector.notificationCloseIcon).click();
187+
});
188+
});

web/src/pages/Route/components/Step1/MatchingRulesView.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ const MatchingRulesView: React.FC<RouteModule.Step1PassProps> = ({
116116
case 'cookie':
117117
renderText = 'Cookie';
118118
break;
119+
case 'buildin':
120+
renderText = formatMessage({ id: 'page.route.buildinParameter' });
121+
break;
119122
default:
120123
renderText = '';
121124
}
@@ -206,6 +209,7 @@ const MatchingRulesView: React.FC<RouteModule.Step1PassProps> = ({
206209
<Option value="http">{formatMessage({ id: 'page.route.httpRequestHeader' })}</Option>
207210
<Option value="arg">{formatMessage({ id: 'page.route.requestParameter' })}</Option>
208211
<Option value="cookie">Cookie</Option>
212+
<Option value="buildin">{formatMessage({ id: 'page.route.buildinParameter' })}</Option>
209213
</Select>
210214
</Form.Item>
211215
<Form.Item

web/src/pages/Route/locales/en-US.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default {
2323
'page.route.parameterPosition': 'Parameter Position',
2424
'page.route.httpRequestHeader': 'HTTP Request Header',
2525
'page.route.requestParameter': 'Request Parameter',
26+
'page.route.buildinParameter': 'Build-in Parameter',
2627
'page.route.parameterName': 'Parameter Name',
2728
'page.route.operationalCharacter': 'Operational Character',
2829
'page.route.equal': 'Equal(==)',

web/src/pages/Route/locales/zh-CN.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default {
1919
'page.route.parameterPosition': '参数位置',
2020
'page.route.httpRequestHeader': 'HTTP 请求头',
2121
'page.route.requestParameter': '请求参数',
22+
'page.route.buildinParameter': '内置参数',
2223
'page.route.parameterName': '参数名称',
2324
'page.route.operationalCharacter': '运算符',
2425
'page.route.equal': '等于(==)',

web/src/pages/Route/transform.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ export const transformStepData = ({
157157
case 'http':
158158
key = `http_${name}`;
159159
break;
160-
default:
160+
case 'arg':
161161
key = `arg_${name}`;
162+
break;
163+
default:
164+
key = `${name}`;
162165
}
163166
let finalValue = value;
164167
if (operator === 'IN') {
@@ -266,7 +269,15 @@ const transformVarsToRules = (
266269
data: [string, RouteModule.Operator, string | any[]][] = [],
267270
): RouteModule.MatchingRule[] =>
268271
data.map(([key, operator, value]) => {
269-
const [, position, name] = key.split(/^(cookie|http|arg)_/);
272+
let position = '';
273+
let name = '';
274+
const regex = new RegExp('^(cookie|http|arg)_.+');
275+
if (regex.test(key)) {
276+
[, position, name] = key.split(/^(cookie|http|arg)_/);
277+
}else {
278+
position = "buildin";
279+
name = key;
280+
}
270281
return {
271282
position: position as RouteModule.VarPosition,
272283
name,

web/src/pages/Route/typing.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
declare namespace RouteModule {
1818
type Operator = '==' | '~=' | '>' | '<' | '~~' | '~*' | 'IN' | 'HAS' | '!';
1919

20-
type VarPosition = 'arg' | 'http' | 'cookie';
20+
type VarPosition = 'arg' | 'http' | 'cookie' | 'buildin';
2121

2222
type RequestProtocol = 'https' | 'http' | 'websocket';
2323

0 commit comments

Comments
 (0)