Skip to content

Commit 7d36eeb

Browse files
Update cypress tests
1 parent c441f4f commit 7d36eeb

File tree

3 files changed

+88
-12
lines changed

3 files changed

+88
-12
lines changed

app/controllers/application_controller/buttons.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ def group_update
102102

103103
# Types of visibility for the custom buttons
104104
VISIBILITY_TYPES = {'role' => 'role', 'all' => 'all'}.freeze
105+
ALL_ROLES = ["_ALL_", "all"].freeze
106+
FIELDS_EMPTY = [[""], ["", ""]].freeze
105107

106108
def button_visibility_box_edit
107109
typ_changed = params[:visibility_typ].present?
108110
@edit[:new][:visibility_typ] = VISIBILITY_TYPES[params[:visibility_typ]] if typ_changed
109-
110111
visibility_typ = @edit[:new][:visibility_typ]
111-
if %w[role].include?(visibility_typ)
112+
113+
if visibility_typ.to_s == "role"
112114
plural = visibility_typ.pluralize
113115
key = plural.to_sym
114116
prefix = "#{plural}_"
@@ -178,20 +180,19 @@ def automate_button_field_changed
178180
end
179181
unless params[:target_class]
180182
@changed = session[:changed] = false
181-
182183
# This block checks if any of the fields have changed
183184
# Broken into different branches for specific fields
184185
# If no fields are changed it will not set @changed or session[:changed] to true
185186
@edit[:new].each_key do |key|
186187
if @edit[:new][key] != @edit[:current][key]
187-
if @edit[:new][key] == "" && @edit[:current][key].nil? # check empty string / nil case
188+
if @edit[:new][key].blank? && @edit[:current][key].blank? # check empty string / nil case
188189
next
189190
elsif @edit[:new][key] == @edit[:current][key].to_s # check string / integer case
190191
next
191192
elsif key == :roles # check role values
192-
if (@edit[:new][key] == ["_ALL_"] || @edit[:new][key] == []) && (@edit[:current][key].nil? || @edit[:current][key] == ["all"] || @edit[:current][key] == ["_ALL_"]) # if visibility is set to "To All"
193+
if (ALL_ROLES.include?(@edit[:new][key]) || @edit[:new][key].empty?) && (ALL_ROLES.include?(@edit[:current][key]) || @edit[:current][key].nil?) # if visibility is set to "To All"
193194
next
194-
elsif @edit[:new][key].sort == @edit[:current][key].sort # check if new roles array and current roles array are equal after sorting the ids
195+
elsif @edit[:new][key].collect(&:to_i).sort == @edit[:current][key].collect(&:to_i).sort # check if new roles array and current roles array are equal after sorting the ids
195196
next
196197
else # if new roles array and current roles array are not equal
197198
@changed = session[:changed] = true
@@ -200,9 +201,9 @@ def automate_button_field_changed
200201
end
201202
elsif key == :attrs # check attribute values
202203
@edit[:new][key].each_with_index do |_item, index|
203-
if (@edit[:new][:attrs][index] == [""] || @edit[:new][:attrs][index] == ["", ""]) && @edit[:current][:attrs][index] == [] # check if attribute and value field is empty
204+
if FIELDS_EMPTY.include?(@edit[:new][:attrs][index]) && @edit[:current][:attrs][index].empty? # check if attribute and value field is empty
204205
next
205-
elsif @edit[:new][:attrs][index] == [] && @edit[:current][:attrs][index] == [] # check if attribute or value field is empty
206+
elsif @edit[:new][:attrs][index].empty? && @edit[:current][:attrs][index].empty? # check if attribute or value field is empty
206207
next
207208
else # if new attribute array and current attribute array are not equal
208209
@changed = session[:changed] = true
@@ -214,8 +215,6 @@ def automate_button_field_changed
214215
elsif key == :visibility_typ # check visibility type
215216
if @edit[:new][key] == "all" && @edit[:current][key].nil? # if visibility is set to "To All"
216217
next
217-
elsif @edit[:new][key] == "role" && @edit[:new][:roles] == [] # if visibility type is set to "To Role" and no roles are selected
218-
next
219218
else # if new visibility type value and current visibility type value are not equal
220219
@changed = session[:changed] = true
221220
break

cypress.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = defineConfig({
77
baseUrl: 'http://localhost:3000',
88
viewportHeight: 800,
99
viewportWidth: 1800,
10-
numTestsKeptInMemory: 0,
10+
numTestsKeptInMemory: 5,
1111
videoCompression: false,
1212

1313
// See: https://docs.cypress.io/app/references/experiments#Experimental-Flake-Detection-Features

cypress/e2e/ui/Automation/Embedded-Automate/customization.cy.js

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
describe('Automation > Embedded Automate > Customization', () => {
44
beforeEach(() => {
55
cy.login();
6-
cy.intercept('POST', '/ops/accordion_select?id=rbac_accord').as('accordion');
76
cy.menu('Automation', 'Embedded Automate', 'Customization');
87
cy.get('#explorer_title_text');
98
});
@@ -162,4 +161,82 @@ describe('Automation > Embedded Automate > Customization', () => {
162161
cy.get('[class="list-group"]').should('not.contain', 'Test Description');
163162
});
164163
});
164+
165+
describe('Button Form', () => {
166+
beforeEach(() => {
167+
cy.intercept('POST', '/miq_ae_customization/accordion_select?id=ab_accord').as('accordion');
168+
cy.get('#control_ab_accord > .panel-title > .collapsed').click();
169+
cy.wait('@accordion');
170+
cy.wait(5000);
171+
});
172+
173+
it('Validates the save button correctly', () => {
174+
cy.get('.clickable-row').contains('Availability Zone').click({force: true});
175+
cy.get('.clickable-row').contains('Unassigned Buttons').click({force: true});
176+
cy.get('[title="Configuration"]').click({force: true});
177+
cy.get('[title="Add a new Button"]').click({force: true});
178+
cy.get('#explorer_title_text').contains('Adding a new Button');
179+
180+
cy.get('#name').type('Test Button');
181+
cy.get('#description').type('Test Description');
182+
cy.get('.icon-button').click();
183+
cy.get(':nth-child(1) > span > .ff').click();
184+
cy.get('.bx--modal-footer > .bx--btn--primary').click();
185+
186+
cy.get('#ab_advanced_tab_tab > a').click();
187+
cy.get('#object_request').type('Test Request');
188+
cy.get('#attribute_1').type('1-attribute');
189+
cy.get('#value_1').type('1-value');
190+
cy.get('#attribute_2').type('2-attribute');
191+
cy.get('#value_2').type('2-value');
192+
cy.get('.col-md-10 > .btn-group > .btn').click();
193+
cy.get('.col-md-10 > .btn-group > .open > .dropdown-menu > [data-original-index="1"] > a').click();
194+
195+
cy.get('#roles_1').click();
196+
cy.get('#roles_2').click();
197+
cy.get('#roles_3').click();
198+
cy.get('#roles_4').click();
199+
200+
cy.get('#buttons_on > .btn-primary').click();
201+
cy.get('.clickable-row').contains('Test Button').click();
202+
203+
cy.get('.attribute_value_pair').contains('1-attribute, 1-value');
204+
cy.get('.attribute_value_pair').contains('2-attribute, 2-value');
205+
cy.get('.visibility').contains('EvmRole-administrator, EvmRole-approver, EvmRole-auditor, EvmRole-super_administrator');
206+
207+
cy.get('[title="Configuration"]').click();
208+
cy.get('[title="Edit this Button"]').click();
209+
210+
cy.get('#buttons_off > .btn-primary');
211+
cy.get('#ab_advanced_tab_tab > a').click();
212+
cy.get('#attribute_2').clear();
213+
cy.get('#value_2').clear();
214+
215+
cy.get('#buttons_on > .btn-primary').click();
216+
217+
cy.get('.attribute_value_pair').contains('1-attribute, 1-value');
218+
cy.get('.attribute_value_pair').should('not.contain', '2-attribute, 2-value');
219+
220+
cy.get('[title="Configuration"]').click();
221+
cy.get('[title="Edit this Button"]').click();
222+
223+
cy.get('#buttons_off > .btn-primary');
224+
cy.get('#ab_advanced_tab_tab > a').click();
225+
226+
cy.get('#roles_2').click();
227+
cy.get('#roles_3').click();
228+
229+
cy.get('#buttons_on > .btn-primary').click();
230+
231+
cy.get('.visibility').contains('EvmRole-auditor, EvmRole-super_administrator');
232+
cy.get('.visibility').should('not.contain', 'EvmRole-administrator, EvmRole-approver');
233+
234+
cy.get('[title="Configuration"]').click();
235+
cy.get('[title="Remove this Button"]').click();
236+
cy.get('h4 > strong').contains('Test Button');
237+
cy.get('.Delete').click({ force: true });
238+
239+
cy.get('.alert').contains('The item "Test Button" has been successfully deleted');
240+
});
241+
});
165242
});

0 commit comments

Comments
 (0)