create-consumer-with-basic-auth-plugin-form.cy.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. context('Create and delete consumer with basic-auth plugin form', () => {
  19. const selector = {
  20. empty: '.ant-empty-normal',
  21. username: '#username',
  22. password: '#password',
  23. description: '#desc',
  24. pluginCard: '.ant-card',
  25. drawer: '.ant-drawer-content',
  26. disabledSwitcher: '#disable',
  27. notification: '.ant-notification-notice-message',
  28. notificationCloseIcon: '.ant-notification-close-icon',
  29. monacoViewZones: '.view-zones',
  30. alert: '.ant-form-item-explain-error [role=alert]',
  31. };
  32. const data = {
  33. consumerName: 'test_consumer',
  34. description: 'desc_by_autotest',
  35. createConsumerSuccess: 'Create Consumer Successfully',
  36. deleteConsumerSuccess: 'Delete Consumer Successfully',
  37. username: 'root',
  38. password: '1234',
  39. };
  40. beforeEach(() => {
  41. cy.login();
  42. });
  43. it('creates consumer with basic-auth form', function () {
  44. cy.visit('/');
  45. cy.contains('Consumer').click();
  46. cy.get(selector.empty).should('be.visible');
  47. cy.contains('Create').click();
  48. // basic information
  49. cy.get(selector.username).type(data.consumerName);
  50. cy.get(selector.description).type(data.description);
  51. cy.contains('Next').click();
  52. // config auth plugin
  53. cy.contains(selector.pluginCard, 'key-auth').within(() => {
  54. cy.contains('Enable').click({
  55. force: true,
  56. });
  57. });
  58. cy.focused(selector.drawer).should('exist');
  59. cy.get(selector.monacoViewZones).should('exist');
  60. cy.get(selector.disabledSwitcher).click();
  61. // edit monaco
  62. cy.window().then((window) => {
  63. window.monacoEditor.setValue(JSON.stringify({ key: 'test' }));
  64. cy.contains('button', 'Submit').click();
  65. });
  66. cy.contains(selector.pluginCard, 'basic-auth').within(() => {
  67. cy.contains('Enable').click({
  68. force: true,
  69. });
  70. });
  71. cy.focused(selector.drawer).should('exist');
  72. // config basic-auth form without username and password
  73. cy.get(selector.username).click();
  74. cy.get(selector.alert).contains('Please enter username');
  75. cy.get(selector.password).click();
  76. cy.get(selector.alert).contains('Please enter password');
  77. cy.get(selector.drawer).within(() => {
  78. cy.contains('Submit').click({
  79. force: true,
  80. });
  81. });
  82. cy.get(selector.notification).should('contain', 'Invalid plugin data');
  83. cy.get(selector.notificationCloseIcon).click();
  84. // config basic-auth form with username and password
  85. cy.get(selector.username).type(data.username);
  86. cy.get(selector.password).type(data.password);
  87. cy.get(selector.alert).should('not.exist');
  88. cy.get(selector.disabledSwitcher).click();
  89. cy.get(selector.drawer).within(() => {
  90. cy.contains('Submit').click({
  91. force: true,
  92. });
  93. });
  94. cy.get(selector.drawer).should('not.exist');
  95. cy.contains('button', 'Next').click();
  96. cy.contains('button', 'Submit').click();
  97. cy.get(selector.notification).should('contain', data.createConsumerSuccess);
  98. });
  99. it('delete the consumer', function () {
  100. cy.visit('/consumer/list');
  101. cy.contains(data.consumerName).should('be.visible').siblings().contains('Delete').click();
  102. cy.contains('button', 'Confirm').click();
  103. cy.get(selector.notification).should('contain', data.deleteConsumerSuccess);
  104. });
  105. });