|
| 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 search service name', () => { |
| 20 | + const selector = { |
| 21 | + name: '#name', |
| 22 | + description: '#desc', |
| 23 | + priority: '#priority', |
| 24 | + nodes_0_host: '#submitNodes_0_host', |
| 25 | + nodes_0_port: '#submitNodes_0_port', |
| 26 | + nodes_0_weight: '#submitNodes_0_weight', |
| 27 | + drawer: '.ant-drawer-content', |
| 28 | + monacoScroll: '.monaco-scrollable-element', |
| 29 | + notification: '.ant-notification-notice-message', |
| 30 | + result: '.ant-result', |
| 31 | + nameSelector: '[title=Name]', |
| 32 | + serviceSelector: '[title="None"]', |
| 33 | + upstreamSelector: '#upstream_id', |
| 34 | + deleteAlert: '.ant-modal-body', |
| 35 | + drawer: '.ant-drawer-content', |
| 36 | + }; |
| 37 | + |
| 38 | + const data = { |
| 39 | + serviceName: 'service_test1', |
| 40 | + description: 'desc_by_autotest', |
| 41 | + ip: '127.0.0.1', |
| 42 | + port: 8000, |
| 43 | + weight: 1, |
| 44 | + serviceName2: 'service_test2', |
| 45 | + ip2: '127.0.0.1', |
| 46 | + port2: 8000, |
| 47 | + weight2: 1, |
| 48 | + priority: 1, |
| 49 | + createServiceSuccess: 'Create Service Successfully', |
| 50 | + deleteServiceSuccess: 'Delete Service Successfully', |
| 51 | + createRouteSuccess: 'Submit Successfully', |
| 52 | + deleteRouteSuccess: 'Delete Route Successfully', |
| 53 | + routeName: 'route_test1', |
| 54 | + searchServiceName: 'service_test2', |
| 55 | + upstreamName: 'None', |
| 56 | + }; |
| 57 | + |
| 58 | + beforeEach(() => { |
| 59 | + cy.login(); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should create two services', function () { |
| 63 | + cy.visit('/'); |
| 64 | + cy.contains('Service').click(); |
| 65 | + cy.contains('Create').click(); |
| 66 | + |
| 67 | + cy.get(selector.name).type(data.serviceName); |
| 68 | + cy.get(selector.description).type(data.description); |
| 69 | + cy.get(selector.nodes_0_host).click(); |
| 70 | + cy.get(selector.nodes_0_host).type(data.ip); |
| 71 | + cy.get(selector.nodes_0_port).clear().type(data.port); |
| 72 | + cy.get(selector.nodes_0_weight).clear().type(data.weight); |
| 73 | + |
| 74 | + cy.contains('Next').click(); |
| 75 | + cy.contains('Next').click(); |
| 76 | + cy.contains('Submit').click(); |
| 77 | + cy.get(selector.notification).should('contain', data.createServiceSuccess); |
| 78 | + |
| 79 | + cy.visit('/'); |
| 80 | + cy.contains('Service').click(); |
| 81 | + cy.contains('Create').click(); |
| 82 | + |
| 83 | + cy.get(selector.name).type(data.serviceName2); |
| 84 | + cy.get(selector.description).type(data.description); |
| 85 | + cy.get(selector.nodes_0_host).click(); |
| 86 | + cy.get(selector.nodes_0_host).type(data.ip2); |
| 87 | + cy.get(selector.nodes_0_port).clear().type(data.port2); |
| 88 | + cy.get(selector.nodes_0_weight).clear().type(data.weight2); |
| 89 | + |
| 90 | + cy.contains('Next').click(); |
| 91 | + cy.contains('Next').click(); |
| 92 | + cy.contains('Submit').click(); |
| 93 | + cy.get(selector.notification).should('contain', data.createServiceSuccess); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should create route with search service and set priority', function () { |
| 97 | + cy.visit('/'); |
| 98 | + cy.contains('Route').click(); |
| 99 | + cy.contains('Create').click(); |
| 100 | + cy.contains('Next').click().click(); |
| 101 | + |
| 102 | + // set name |
| 103 | + cy.get(selector.name).type(data.routeName); |
| 104 | + cy.get(selector.serviceSelector).type(data.serviceName2 + '\n'); |
| 105 | + // set priority |
| 106 | + cy.get(selector.priority).type(data.priority); |
| 107 | + cy.contains('Next').click(); |
| 108 | + // select upstream with None |
| 109 | + cy.get(selector.upstreamSelector).type(data.upstreamName + '\n'); |
| 110 | + cy.contains('Next').click(); |
| 111 | + cy.contains('Next').click(); |
| 112 | + cy.contains('Submit').click(); |
| 113 | + cy.get(selector.result).should('contain', data.createRouteSuccess); |
| 114 | + }); |
| 115 | + |
| 116 | + it('should check the priority and service was seted', function () { |
| 117 | + let serviceUuid = ''; |
| 118 | + cy.visit('/'); |
| 119 | + cy.contains('Service').click(); |
| 120 | + cy.get(selector.name).type(data.serviceName2 + '\n'); |
| 121 | + cy.contains(data.serviceName2) |
| 122 | + .siblings() |
| 123 | + .first() |
| 124 | + .then((a) => { |
| 125 | + serviceUuid = a.text(); |
| 126 | + }); |
| 127 | + cy.visit('/'); |
| 128 | + cy.contains('Route').click(); |
| 129 | + cy.get(selector.name).type(data.routeName + '\n'); |
| 130 | + cy.contains(data.routeName).siblings().contains('More').click(); |
| 131 | + cy.contains('View').click(); |
| 132 | + cy.get(selector.drawer).should('be.visible'); |
| 133 | + cy.get(selector.monacoScroll).within(() => { |
| 134 | + cy.contains('priority').should('exist'); |
| 135 | + cy.contains(`${serviceUuid}`).should('exist'); |
| 136 | + }); |
| 137 | + }); |
| 138 | + |
| 139 | + it('should delete the route and services', function () { |
| 140 | + cy.visit('/'); |
| 141 | + cy.contains('Route').click(); |
| 142 | + cy.get(selector.name).type(data.routeName + '\n'); |
| 143 | + cy.contains(data.routeName).siblings().contains('More').click(); |
| 144 | + cy.contains('Delete').click(); |
| 145 | + cy.get(selector.deleteAlert) |
| 146 | + .should('be.visible') |
| 147 | + .within(() => { |
| 148 | + cy.contains('OK').click(); |
| 149 | + }); |
| 150 | + cy.get(selector.notification).should('contain', data.deleteRouteSuccess); |
| 151 | + |
| 152 | + cy.visit('/'); |
| 153 | + cy.contains('Service').click(); |
| 154 | + cy.contains(data.serviceName).siblings().contains('Delete').click(); |
| 155 | + cy.contains('button', 'Confirm').click(); |
| 156 | + cy.get(selector.notification).should('contain', data.deleteServiceSuccess); |
| 157 | + |
| 158 | + cy.contains(data.serviceName2).siblings().contains('Delete').click(); |
| 159 | + cy.contains('button', 'Confirm').click(); |
| 160 | + cy.get(selector.notification).should('contain', data.deleteServiceSuccess); |
| 161 | + }); |
| 162 | +}); |
0 commit comments