liuxiran commented on a change in pull request #2081:
URL: https://github.com/apache/apisix-dashboard/pull/2081#discussion_r694601235



##########
File path: 
web/cypress/integration/route/create-route-with-service-discovery-upstream.spec.js
##########
@@ -0,0 +1,158 @@
+/*
+ * 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 Route with Service Discovery Upstream', () => {
+  const selector = {
+    name: '#name',
+    description: '#desc',
+    discovery_type: '#discovery_type',
+    service_name: '#service_name',
+    upstreamSelector: '[data-cy=upstream_selector]',
+    nameSelector: '[title=Name]',
+    selectItem: '.ant-select-item-option-content',
+    drawer: '.ant-drawer-content',
+    monacoScroll: '.monaco-scrollable-element',
+    input: ':input',
+    deleteAlert: '.ant-modal-body',
+    notification: '.ant-notification-notice-message',
+  };
+
+  const data = {
+    deleteRouteSuccess: 'Delete Route Successfully',
+    submitSuccess: 'Submit Successfully',
+    deleteUpstreamSuccess: 'Delete Upstream Successfully',
+    weight: 1,
+    description: 'desc_by_autotest',
+    upstreamName: 'test_upstream',
+    routeName: 'test_route',
+    serviceName: 'test.cluster.local',
+  };
+
+  beforeEach(() => {
+    cy.login();
+  });
+
+  it('should create route with DNS service discovery upstream', function () {
+    cy.visit('/');
+    cy.get('[role=menu]')
+      .should('be.visible')
+      .within(() => {
+        cy.contains('Route').click();
+      });
+    cy.contains('Create').click();
+
+    cy.contains('Next').click().click();
+    cy.get(selector.name).type(data.routeName);
+    cy.contains('Next').click();
+
+    // should enable Upstream input boxes after selecting Custom mode
+    cy.get(selector.upstreamSelector).click();
+    cy.contains('.ant-select-item-option-content', 'Custom').click();
+
+    // set service discovery
+    cy.get('[title="Node"]').click();
+    cy.get(selector.selectItem).within(() => {
+      cy.contains('Service Discovery').click();
+    });
+
+    cy.get(selector.discovery_type).click();
+    cy.get(selector.selectItem).within(() => {
+      cy.contains('DNS').click();
+    });
+    cy.get(selector.service_name).type(data.serviceName);
+
+    cy.contains('Next').click();
+    cy.contains('Next').click();
+    cy.contains('Submit').click();
+    cy.contains(data.submitSuccess).should('be.visible');
+    cy.contains('Goto List').click();
+    cy.url().should('contains', 'routes/list');
+  });
+
+  it('should edit this route with Nacos Service Discovery upstream', function 
() {
+    cy.visit('/');
+    cy.contains('Route').click();
+    cy.get(selector.nameSelector).type(data.routeName);
+
+    cy.contains('Search').click();
+    cy.contains(data.routeName).siblings().contains('Configure').click();
+
+    cy.get(selector.name).should('value', data.routeName);
+    cy.contains('Next').click({
+      force: true,
+    });
+
+    cy.wait(1000);

Review comment:
       `cy.wait` here is not a recommended way,  
   
   add an assertion to confirm that the page is rendered, just like your other 
cases
   `cy.get(selector.service_name).should('value', 
`another.${data.serviceName}`);`

##########
File path: 
web/cypress/integration/route/create-route-with-service-discovery-upstream.spec.js
##########
@@ -0,0 +1,158 @@
+/*
+ * 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 Route with Service Discovery Upstream', () => {
+  const selector = {
+    name: '#name',
+    description: '#desc',
+    discovery_type: '#discovery_type',
+    service_name: '#service_name',
+    upstreamSelector: '[data-cy=upstream_selector]',
+    nameSelector: '[title=Name]',
+    selectItem: '.ant-select-item-option-content',
+    drawer: '.ant-drawer-content',
+    monacoScroll: '.monaco-scrollable-element',
+    input: ':input',
+    deleteAlert: '.ant-modal-body',
+    notification: '.ant-notification-notice-message',
+  };
+
+  const data = {
+    deleteRouteSuccess: 'Delete Route Successfully',
+    submitSuccess: 'Submit Successfully',
+    deleteUpstreamSuccess: 'Delete Upstream Successfully',
+    weight: 1,
+    description: 'desc_by_autotest',
+    upstreamName: 'test_upstream',
+    routeName: 'test_route',
+    serviceName: 'test.cluster.local',
+  };
+
+  beforeEach(() => {
+    cy.login();
+  });
+
+  it('should create route with DNS service discovery upstream', function () {
+    cy.visit('/');
+    cy.get('[role=menu]')
+      .should('be.visible')
+      .within(() => {
+        cy.contains('Route').click();
+      });
+    cy.contains('Create').click();
+
+    cy.contains('Next').click().click();
+    cy.get(selector.name).type(data.routeName);
+    cy.contains('Next').click();
+
+    // should enable Upstream input boxes after selecting Custom mode
+    cy.get(selector.upstreamSelector).click();
+    cy.contains('.ant-select-item-option-content', 'Custom').click();
+
+    // set service discovery
+    cy.get('[title="Node"]').click();
+    cy.get(selector.selectItem).within(() => {
+      cy.contains('Service Discovery').click();
+    });
+
+    cy.get(selector.discovery_type).click();
+    cy.get(selector.selectItem).within(() => {
+      cy.contains('DNS').click();
+    });
+    cy.get(selector.service_name).type(data.serviceName);

Review comment:
       last one suggestion about your test case:
   
   add an assertion to confirm that there are not `discovery_args` and 
`namespace_id` when choose `DNS`

##########
File path: 
web/cypress/integration/route/create-route-with-service-discovery-upstream.spec.js
##########
@@ -0,0 +1,158 @@
+/*
+ * 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 Route with Upstream', () => {
+  const selector = {
+    name: '#name',
+    description: '#desc',
+    discovery_type: '#discovery_type',
+    service_name: '#service_name',
+    upstreamSelector: '[data-cy=upstream_selector]',
+    nameSelector: '[title=Name]',
+    selectItem: '.ant-select-item-option-content',
+    drawer: '.ant-drawer-content',
+    monacoScroll: '.monaco-scrollable-element',
+    input: ':input',
+    deleteAlert: '.ant-modal-body',
+    notification: '.ant-notification-notice-message',
+  };
+
+  const data = {
+    deleteRouteSuccess: 'Delete Route Successfully',
+    submitSuccess: 'Submit Successfully',
+    deleteUpstreamSuccess: 'Delete Upstream Successfully',
+    weight: 1,
+    description: 'desc_by_autotest',
+    upstreamName: 'test_upstream',
+    routeName: 'test_route',
+    serviceName: 'test.cluster.local',
+  };
+
+  beforeEach(() => {
+    cy.login();
+  });
+
+  it('should create route with service discovery upstream', function () {
+    cy.visit('/');
+    cy.get('[role=menu]')
+      .should('be.visible')
+      .within(() => {
+        cy.contains('Route').click();
+      });
+    cy.contains('Create').click();
+
+    cy.contains('Next').click().click();
+    cy.get(selector.name).type(data.routeName);
+    cy.contains('Next').click();
+
+    // should enable Upstream input boxes after selecting Custom mode
+    cy.get(selector.upstreamSelector).click();
+    cy.contains('.ant-select-item-option-content', 'Custom').click();
+
+    // set service discovery
+    cy.get('[title="Node"]').click();
+    cy.get(selector.selectItem).within(() => {
+      cy.contains('Service Discovery').click();
+    });
+
+    cy.get(selector.discovery_type).click();
+    cy.get(selector.selectItem).within(() => {
+      cy.contains('DNS').click();
+    });
+    cy.get(selector.service_name).type(data.serviceName);
+
+    cy.contains('Next').click();
+    cy.contains('Next').click();
+    cy.contains('Submit').click();
+    cy.contains(data.submitSuccess).should('be.visible');
+    cy.contains('Goto List').click();
+    cy.url().should('contains', 'routes/list');
+  });
+
+  it('should edit this route with upstream', function () {
+    cy.visit('/');
+    cy.contains('Route').click();
+    cy.get(selector.nameSelector).type(data.routeName);
+
+    cy.contains('Search').click();
+    cy.contains(data.routeName).siblings().contains('Configure').click();
+
+    cy.get(selector.name).should('value', data.routeName);
+    cy.contains('Next').click({
+      force: true,
+    });
+
+    cy.wait(1000);
+
+    // set another service discovery
+    cy.get(selector.discovery_type).click({ force: true });

Review comment:
       You  can try this one: @bzp2010 
   
![image](https://user-images.githubusercontent.com/2561857/130578608-38c247f2-6487-49f8-a9e7-b3ab504f5c6f.png)
   
   `cy.get('#discovery_type').parent().next().should('have.attr', 'title', 
'DNS');`

##########
File path: web/src/components/Upstream/components/ServiceDiscovery.tsx
##########
@@ -0,0 +1,82 @@
+/*
+ * 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 { Form, Input, Select } from 'antd';
+import { useIntl } from 'umi';
+import type { FormInstance } from 'antd/lib/form';
+import ServiceDiscoveryArgs from 
'@/components/Upstream/components/ServiceDiscoveryArgs';
+
+type Props = {
+  form: FormInstance;
+  readonly?: boolean;
+};
+
+const ServiceDiscovery: React.FC<Props> = ({ readonly, form }) => {
+  const { formatMessage } = useIntl();
+
+  return (
+    <React.Fragment>
+      <Form.Item
+        name="discovery_type"
+        label={formatMessage({ id: 'component.upstream.fields.discovery_type' 
})}
+        tooltip={formatMessage({ id: 
'component.upstream.fields.discovery_type.tooltip' })}
+        rules={[{ required: true }]}
+      >
+        <Select
+          disabled={readonly}
+          placeholder={formatMessage({
+            id: 'component.upstream.fields.discovery_type.placeholder',
+          })}
+        >
+          <Select.Option value="dns">
+            {formatMessage({ id: 
'component.upstream.fields.discovery_type.type.dns' })}
+          </Select.Option>
+          <Select.Option value="consul_kv">
+            {formatMessage({ id: 
'component.upstream.fields.discovery_type.type.consul_kv' })}
+          </Select.Option>
+          <Select.Option value="nacos">
+            {formatMessage({ id: 
'component.upstream.fields.discovery_type.type.nacos' })}
+          </Select.Option>
+          <Select.Option value="eureka">
+            {formatMessage({ id: 
'component.upstream.fields.discovery_type.type.eureka' })}
+          </Select.Option>
+        </Select>

Review comment:
       we can consider to use  a list to store the supported options, which 
would be better to maintenance




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to