diff --git a/app/helpers/ops_helper.rb b/app/helpers/ops_helper.rb index 5c74dca1778..997351ea9ee 100644 --- a/app/helpers/ops_helper.rb +++ b/app/helpers/ops_helper.rb @@ -22,9 +22,9 @@ def row_data(label, value) end def database_details - @database_details = ActiveRecord::Base.configurations[Rails.env] + @database_details = ActiveRecord::Base.configurations.configs_for(:env_name => Rails.env).first.configuration_hash @database_display_name = - if @database_details["host"].in?([nil, "", "localhost", "127.0.0.1"]) + if @database_details[:host].in?([nil, "", "localhost", "127.0.0.1"]) _("Internal Database") else _("External Database") @@ -32,9 +32,9 @@ def database_details @data = {:title => _('Basic Information')} @data[:rows] = [ row_data(_('Name'), @database_display_name), - row_data(_('Hostname'), @database_details["host"]), - row_data(_('Database name'), @database_details["database"]), - row_data(_('Username'), @database_details["username"]) + row_data(_('Hostname'), @database_details[:host]), + row_data(_('Database name'), @database_details[:database]), + row_data(_('Username'), @database_details[:username]) ] end diff --git a/cypress/e2e/ui/Settings/Application-Settings/diagnostics.cy.js b/cypress/e2e/ui/Settings/Application-Settings/diagnostics.cy.js new file mode 100644 index 00000000000..9bf401d8006 --- /dev/null +++ b/cypress/e2e/ui/Settings/Application-Settings/diagnostics.cy.js @@ -0,0 +1,43 @@ +/* eslint-disable no-undef */ + +// Menu options +const SETTINGS_MENU_OPTION = 'Settings'; +const APP_SETTINGS_MENU_OPTION = 'Application Settings'; + +// Accordion items +const DIAGNOSTICS_ACCORDION_ITEM = 'Diagnostics'; +const MANAGEIQ_REGION_ACCORDION_ITEM = /^ManageIQ Region:/; + +// Tab names +const DATABASE_TAB_LABEL = 'Database'; + +describe('Settings > Application Settings > Diagnostics', () => { + beforeEach(() => { + cy.login(); + cy.menu(SETTINGS_MENU_OPTION, APP_SETTINGS_MENU_OPTION); + cy.accordion(DIAGNOSTICS_ACCORDION_ITEM); + }); + + describe('ManageIQ Region', () => { + beforeEach(() => { + cy.selectAccordionItem([MANAGEIQ_REGION_ACCORDION_ITEM]); + }); + + it('should navigate to the Database tab', () => { + // Intercept the API call when clicking on the Database tab + cy.interceptApi({ + alias: 'getDatabaseTabInfo', + urlPattern: '/ops/change_tab?tab_id=diagnostics_database', + triggerFn: () => cy.tabs({ tabLabel: DATABASE_TAB_LABEL }), + }); + + // Verify the Database tab content is loaded + cy.get(`@getDatabaseTabInfo`).then((getCall) => { + expect(getCall.state).to.equal('Complete'); + }); + + // Verify we're on the Database tab + cy.get('.tab-content').contains(DATABASE_TAB_LABEL).should('be.visible'); + }); + }); +}); diff --git a/spec/helpers/ops_helper_spec.rb b/spec/helpers/ops_helper_spec.rb index b01d839d430..9d1acf8d33a 100644 --- a/spec/helpers/ops_helper_spec.rb +++ b/spec/helpers/ops_helper_spec.rb @@ -1,4 +1,17 @@ describe OpsHelper do + it "#database_details" do + db_config = ActiveRecord::Base.configurations.configs_for(:env_name => Rails.env).first.configuration_hash + + expect(helper.database_details).to match_array( + [ + {:cells => a_hash_including(:label => "Name", :value => a_string_matching(/ Database$/))}, + {:cells => {:label => "Hostname", :value => db_config[:host]}}, + {:cells => {:label => "Database name", :value => db_config[:database]}}, + {:cells => {:label => "Username", :value => db_config[:username]}}, + ] + ) + end + describe '#auth_mode_name' do modes = %w[amazon httpd database] modes_pretty = %w[Amazon External\ Authentication Database]