blob: 700204c1aeec5defb5b159bbdc958f8be45f034b [file] [log] [blame]
/*
* 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 with proxy-mirror plugin form', () => {
const selector = {
empty: '.ant-empty-normal',
username: '#username',
description: '#desc',
pluginCard: '.ant-card',
drawer: '.ant-drawer-content',
dropdown: '.rc-virtual-list',
disabledSwitcher: '#disable',
notification: '.ant-notification-notice-message',
notificationCloseIcon: '.ant-notification-close-icon',
max_age: '#max_age',
allow_origins_by_regex: '#allow_origins_by_regex_0',
host: '#host',
alert: '[role=alert]',
monacoViewZones: '.view-zones',
};
const data = {
consumerName: 'test_consumer',
description: 'desc_by_autotest',
createConsumerSuccess: 'Create Consumer Successfully',
deleteConsumerSuccess: 'Delete Consumer Successfully',
time: 2,
};
beforeEach(() => {
cy.login();
});
it('should create consumer with proxy-mirror form', function () {
cy.visit('/');
cy.contains('Consumer').click();
cy.get(selector.empty).should('be.visible');
cy.contains('Create').click();
// basic information
cy.get(selector.username).type(data.consumerName);
cy.get(selector.description).type(data.description);
cy.contains('Next').click();
// config auth plugin
cy.contains(selector.pluginCard, 'key-auth').within(() => {
cy.contains('Enable').click({
force: true,
});
});
cy.focused(selector.drawer).should('exist');
cy.get(selector.monacoViewZones).should('exist');
cy.get(selector.disabledSwitcher).click();
// edit monaco
cy.window().then((window) => {
window.monacoEditor.setValue(JSON.stringify({ key: 'test' }));
cy.contains('button', 'Submit').click();
});
cy.contains(selector.pluginCard, 'proxy-mirror').within(() => {
cy.contains('Enable').click({
force: true,
});
});
cy.focused(selector.drawer).should('exist');
// config proxy-mirror form with wrong host
cy.get(selector.host).type('127.0.0.1:1999');
cy.get(selector.alert).contains('address needs to contain schema: http or https, not URI part');
cy.get(selector.drawer).within(() => {
cy.contains('Submit').click({
force: true,
});
});
cy.get(selector.notification).should('contain', 'Invalid plugin data');
cy.get(selector.notificationCloseIcon).click();
// config proxy-mirror form with correct host
cy.get(selector.host).clear().type('http://127.0.0.1:1999');
cy.get(selector.alert).should('not.be.visible');
cy.get(selector.disabledSwitcher).click();
cy.get(selector.drawer).within(() => {
cy.contains('Submit').click({
force: true,
});
});
cy.get(selector.drawer).should('not.exist');
cy.contains('button', 'Next').click();
cy.contains('button', 'Submit').click();
cy.get(selector.notification).should('contain', data.createConsumerSuccess);
});
it('should delete the consumer', function () {
cy.visit('/consumer/list');
cy.contains(data.consumerName).should('be.visible').siblings().contains('Delete').click();
cy.contains('button', 'Confirm').click();
cy.get(selector.notification).should('contain', data.deleteConsumerSuccess);
});
});