|
| 1 | +require 'test_helper' |
| 2 | + |
| 3 | +class ApplicationControllerTest < ActionDispatch::IntegrationTest |
| 4 | + test 'set_active_tab sets default to primo when no feature flag or params' do |
| 5 | + assert_nil cookies[:last_tab] |
| 6 | + |
| 7 | + get root_path |
| 8 | + assert_select '#tab-to-target' do |
| 9 | + assert_select '[value=?]', 'primo' |
| 10 | + refute_select '[value=?]', 'geodata' |
| 11 | + refute_select '[value=?]', 'timdex' |
| 12 | + end |
| 13 | + |
| 14 | + assert_equal cookies[:last_tab], 'primo' |
| 15 | + end |
| 16 | + |
| 17 | + test 'set_active_tab sets to geodata when feature flag enabled' do |
| 18 | + skip 'Geodata uses a different form so we do no set the tab this way' |
| 19 | + ClimateControl.modify FEATURE_GEODATA: 'true' do |
| 20 | + get root_path |
| 21 | + assert_select '#tab-to-target' do |
| 22 | + refute_select '[value=?]', 'primo' |
| 23 | + assert_select '[value=?]', 'geodata' |
| 24 | + refute_select '[value=?]', 'timdex' |
| 25 | + end |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + test 'set_active_tab sets to geodata when feature flag enabled even if param is passed' do |
| 30 | + skip 'Geodata uses a different form' |
| 31 | + ClimateControl.modify FEATURE_GEODATA: 'true' do |
| 32 | + get root_path, params: { tab: 'primo' } |
| 33 | + assert_select '#tab-to-target' do |
| 34 | + refute_select '[value=?]', 'primo' |
| 35 | + assert_select '[value=?]', 'geodata' |
| 36 | + refute_select '[value=?]', 'timdex' |
| 37 | + end |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + test 'set_active_tab sets to param tab when provided' do |
| 42 | + get root_path, params: { tab: 'timdex' } |
| 43 | + |
| 44 | + assert_select '#tab-to-target' do |
| 45 | + refute_select '[value=?]', 'primo' |
| 46 | + refute_select '[value=?]', 'geodata' |
| 47 | + assert_select '[value=?]', 'timdex' |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + test 'set_active_tab sets to param tab when provided even if cookie is set and updates cookie' do |
| 52 | + cookies[:last_tab] = 'timdex' |
| 53 | + get root_path, params: { tab: 'geodata' } |
| 54 | + |
| 55 | + assert_select '#tab-to-target' do |
| 56 | + refute_select '[value=?]', 'primo' |
| 57 | + assert_select '[value=?]', 'geodata' |
| 58 | + refute_select '[value=?]', 'timdex' |
| 59 | + end |
| 60 | + |
| 61 | + assert_equal cookies[:last_tab], 'geodata' |
| 62 | + end |
| 63 | + |
| 64 | + test 'set_active_tab uses cookie last_tab when no param provided' do |
| 65 | + cookies[:last_tab] = 'timdex' |
| 66 | + get root_path |
| 67 | + assert_select '#tab-to-target' do |
| 68 | + refute_select '[value=?]', 'primo' |
| 69 | + refute_select '[value=?]', 'geodata' |
| 70 | + assert_select '[value=?]', 'timdex' |
| 71 | + end |
| 72 | + end |
| 73 | +end |
0 commit comments