|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'application_system_test_case' |
| 4 | + |
| 5 | +class ModuleBrowserTest < ApplicationSystemTestCase |
| 6 | + MODULE_BTN_SELECT = '.module-card button[data-bs-toggle="collapse"]' |
| 7 | + |
| 8 | + def fixture_dir |
| 9 | + "#{Rails.root}/test/fixtures/modules/" |
| 10 | + end |
| 11 | + |
| 12 | + def results_text(count) |
| 13 | + "Showing #{count} results" |
| 14 | + end |
| 15 | + |
| 16 | + setup do |
| 17 | + stub_sys_apps |
| 18 | + end |
| 19 | + |
| 20 | + test 'searching by module name filters results' do |
| 21 | + with_modified_env({ OOD_MODULE_FILE_DIR: fixture_dir }) do |
| 22 | + visit module_browser_url |
| 23 | + initial_count = all('.module-card').count |
| 24 | + |
| 25 | + fill_in 'module_search', with: 'gcc' |
| 26 | + assert_selector('#module_results_count', text: results_text(2)) |
| 27 | + |
| 28 | + all('.module-card', visible: true).each do |card| |
| 29 | + module_name = card['data-name'].downcase |
| 30 | + assert module_name.include?('gcc'), "Expected #{module_name} to include 'gcc'" |
| 31 | + end |
| 32 | + |
| 33 | + fill_in 'module_search', with: '' |
| 34 | + assert_selector('#module_results_count', text: results_text(initial_count)) |
| 35 | + |
| 36 | + final_count = all('.module-card', visible: true).count |
| 37 | + assert_equal initial_count, final_count |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + test 'filtering by cluster only shows supported modules' do |
| 42 | + with_modified_env({ OOD_MODULE_FILE_DIR: fixture_dir }) do |
| 43 | + visit module_browser_url |
| 44 | + |
| 45 | + cluster_options = all('#cluster_filter option').to_a |
| 46 | + initial_count = all('.module-card', visible: true).count |
| 47 | + |
| 48 | + first_cluster = cluster_options[1] |
| 49 | + cluster_id = first_cluster.value |
| 50 | + |
| 51 | + select first_cluster.text, from: 'cluster_filter' |
| 52 | + |
| 53 | + all('.module-card', visible: true).each do |card| |
| 54 | + clusters = card['data-clusters'].split(',') |
| 55 | + assert clusters.include?(cluster_id), "Module should have #{cluster_id} in its cluster list" |
| 56 | + end |
| 57 | + |
| 58 | + select 'All Clusters', from: 'cluster_filter' |
| 59 | + |
| 60 | + final_count = all('.module-card', visible: true).count |
| 61 | + assert_equal initial_count, final_count |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + test 'module button expands and collapses the module details' do |
| 66 | + with_modified_env({ OOD_MODULE_FILE_DIR: fixture_dir }) do |
| 67 | + visit module_browser_url |
| 68 | + |
| 69 | + first_module = find(MODULE_BTN_SELECT, match: :first) |
| 70 | + collapse_id = first_module['data-bs-target'] |
| 71 | + |
| 72 | + assert_selector("#{collapse_id}", visible: :hidden) |
| 73 | + |
| 74 | + first_module.click |
| 75 | + assert_selector("#{MODULE_BTN_SELECT}.active") |
| 76 | + assert_selector("#{collapse_id}", visible: :visible) |
| 77 | + |
| 78 | + first_module.click |
| 79 | + assert_selector("#{MODULE_BTN_SELECT}.collapsed") |
| 80 | + assert_selector("#{collapse_id}", visible: :hidden) |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + test 'selecting a version updates the load command' do |
| 85 | + with_modified_env({ OOD_MODULE_FILE_DIR: fixture_dir }) do |
| 86 | + visit module_browser_url |
| 87 | + |
| 88 | + first_module = find(MODULE_BTN_SELECT, match: :first) |
| 89 | + first_module.click |
| 90 | + |
| 91 | + assert_selector("#{MODULE_BTN_SELECT}.active") |
| 92 | + version_button = find('button[data-role="selectable-version"]', match: :first) |
| 93 | + module_name = version_button['data-module'] |
| 94 | + version = version_button['data-version'] |
| 95 | + |
| 96 | + refute version_button.matches_css?('.active') |
| 97 | + version_button.click |
| 98 | + assert version_button.matches_css?('.active') |
| 99 | + |
| 100 | + load_cmd = find('[data-role="module-load-command"]') |
| 101 | + expected_text = "module load #{module_name}/#{version}" |
| 102 | + assert_equal expected_text, load_cmd.text.strip |
| 103 | + end |
| 104 | + end |
| 105 | + |
| 106 | + test 'updates results count when filtering' do |
| 107 | + with_modified_env({ OOD_MODULE_FILE_DIR: fixture_dir }) do |
| 108 | + visit module_browser_url |
| 109 | + initial_count = all('.module-card', visible: true).count |
| 110 | + initial_count_text = find('#module_results_count').text |
| 111 | + |
| 112 | + assert_equal "Showing #{initial_count} results", initial_count_text |
| 113 | + |
| 114 | + fill_in 'module_search', with: 'nonexistent_module' |
| 115 | + assert_selector('#module_results_count', text: results_text(0)) |
| 116 | + end |
| 117 | + end |
| 118 | +end |
0 commit comments