rawDataEditor-test-rawDataEditor.cy.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 */
  18. context('Test RawDataEditor', () => {
  19. const timeout = 1000;
  20. const selector = {
  21. notificationClose: '.anticon-close',
  22. tableBody: '.ant-table-tbody',
  23. drawer: '.ant-drawer-content',
  24. notification: '.ant-notification-notice-message',
  25. monacoViewZones: '.view-zones',
  26. };
  27. const data = {
  28. deleteRouteSuccess: 'Delete Route Successfully',
  29. deleteServiceSuccess: 'Delete Service Successfully',
  30. deletePluginSuccess: 'Delete Plugin Successfully',
  31. deleteUpstreamSuccess: 'Delete Upstream Successfully',
  32. deleteConsumerSuccess: 'Delete Consumer Successfully',
  33. };
  34. beforeEach(() => {
  35. cy.login();
  36. cy.fixture('rawDataEditor-dataset.json').as('dataset');
  37. });
  38. it('should create and update with rawDataEditor', function () {
  39. const menuList = ['Route', 'Service', 'Upstream', 'Consumer'];
  40. const dataset = this.dataset;
  41. menuList.forEach(function (item) {
  42. cy.visit('/');
  43. cy.contains(item).click();
  44. cy.get('.anticon-reload').click();
  45. if (item === 'Route') {
  46. cy.contains('Advanced').should('be.visible').click({ force: true });
  47. cy.contains('Raw Data Editor').should('be.visible').click();
  48. } else {
  49. cy.contains('Raw Data Editor').should('be.visible').click();
  50. }
  51. const dataSetItem = dataset[item];
  52. cy.get(selector.monacoViewZones).should('exist').click({ force: true });
  53. // edit monaco
  54. cy.window().then((window) => {
  55. window.monacoEditor.setValue(JSON.stringify(dataSetItem));
  56. cy.get(selector.drawer).should('exist');
  57. cy.get(selector.drawer, { timeout }).within(() => {
  58. cy.contains('Submit').click({
  59. force: true,
  60. });
  61. cy.get(selector.drawer).should('not.exist');
  62. });
  63. });
  64. cy.reload();
  65. if (item === 'Route') {
  66. // update with editor
  67. cy.contains(item === 'Consumer' ? dataSetItem.username : dataSetItem.name)
  68. .siblings()
  69. .contains('More')
  70. .click();
  71. cy.contains('View').should('be.visible').click({ force: true });
  72. } else {
  73. // update with editor
  74. cy.contains(item === 'Consumer' ? dataSetItem.username : dataSetItem.name)
  75. .siblings()
  76. .contains('View')
  77. .click();
  78. }
  79. cy.get(selector.monacoViewZones).should('exist').click({ force: true });
  80. // edit monaco
  81. cy.window().then((window) => {
  82. if (item === 'Consumer') {
  83. window.monacoEditor.setValue(JSON.stringify({ ...dataSetItem, desc: 'newDesc' }));
  84. } else {
  85. window.monacoEditor.setValue(JSON.stringify({ ...dataSetItem, name: 'newName' }));
  86. }
  87. cy.get(selector.drawer).should('exist');
  88. cy.get(selector.drawer, { timeout }).within(() => {
  89. cy.contains('Submit').click({
  90. force: true,
  91. });
  92. cy.get(selector.drawer).should('not.exist');
  93. });
  94. });
  95. if (item === 'Route') {
  96. cy.reload();
  97. cy.get(selector.tableBody).should('contain', item === 'Consumer' ? 'newDesc' : 'newName');
  98. cy.contains(item === 'Consumer' ? 'newDesc' : 'newName')
  99. .siblings()
  100. .contains('More')
  101. .click();
  102. cy.contains('Delete').should('be.visible').click();
  103. cy.get('.ant-modal-content')
  104. .should('be.visible')
  105. .within(() => {
  106. cy.contains('OK').click();
  107. });
  108. } else {
  109. cy.reload();
  110. cy.get(selector.tableBody).should('contain', item === 'Consumer' ? 'newDesc' : 'newName');
  111. cy.contains(item === 'Consumer' ? 'newDesc' : 'newName')
  112. .siblings()
  113. .contains('Delete')
  114. .click();
  115. cy.contains('button', 'Confirm').click();
  116. }
  117. cy.get(selector.notification).should('contain', data[`delete${item}Success`]);
  118. cy.get(selector.notificationClose).should('be.visible').click({
  119. force: true,
  120. multiple: true,
  121. });
  122. });
  123. });
  124. });