|
| 1 | +require 'test_helper' |
| 2 | + |
| 3 | +class ApplicationControllerUnitTest < ActionController::TestCase |
| 4 | + setup do |
| 5 | + @controller = ApplicationController.new |
| 6 | + end |
| 7 | + |
| 8 | + test '#primo_tabs returns expected tabs' do |
| 9 | + assert_equal %w[alma cdi primo], @controller.primo_tabs |
| 10 | + end |
| 11 | + |
| 12 | + test '#timdex_tabs returns expected tabs' do |
| 13 | + assert_equal %w[aspace timdex timdex_alma website], @controller.timdex_tabs |
| 14 | + end |
| 15 | + |
| 16 | + test '#all_tabs includes both primo and timdex tabs as well as all tab' do |
| 17 | + expected = %w[all alma cdi primo aspace timdex timdex_alma website] |
| 18 | + assert_equal expected, @controller.all_tabs |
| 19 | + end |
| 20 | + |
| 21 | + test '#valid_tab? returns true for valid tabs' do |
| 22 | + assert @controller.send(:valid_tab?, 'all') |
| 23 | + assert @controller.send(:valid_tab?, 'alma') |
| 24 | + assert @controller.send(:valid_tab?, 'timdex') |
| 25 | + end |
| 26 | + |
| 27 | + test '#valid_tab? returns false for invalid tabs' do |
| 28 | + refute @controller.send(:valid_tab?, 'invalid') |
| 29 | + refute @controller.send(:valid_tab?, '') |
| 30 | + end |
| 31 | + |
| 32 | + test 'set_active_tab defaults @active_tab to all when no params or cookies are set' do |
| 33 | + @controller.stubs(:params).returns({}) |
| 34 | + @controller.stubs(:cookies).returns({}) |
| 35 | + @controller.set_active_tab |
| 36 | + assert_equal 'all', @controller.instance_variable_get(:@active_tab) |
| 37 | + end |
| 38 | + |
| 39 | + test 'set_active_tab sets @active_tab to tab when tab params is valid' do |
| 40 | + @controller.stubs(:params).returns({ tab: 'primo' }) |
| 41 | + @controller.stubs(:cookies).returns({}) |
| 42 | + @controller.set_active_tab |
| 43 | + assert_equal 'primo', @controller.instance_variable_get(:@active_tab) |
| 44 | + end |
| 45 | + |
| 46 | + test 'set_active_tab sets @active_tab to all when tab params is invalid and no cookie is set' do |
| 47 | + @controller.stubs(:params).returns({ tab: 'supertab' }) |
| 48 | + @controller.stubs(:cookies).returns({}) |
| 49 | + @controller.set_active_tab |
| 50 | + assert_equal 'all', @controller.instance_variable_get(:@active_tab) |
| 51 | + end |
| 52 | + |
| 53 | + test 'set_active_tab sets @active_tab to cookie value when tab params is invalid and valid cookie is set' do |
| 54 | + @controller.stubs(:params).returns({ tab: 'supertab' }) |
| 55 | + @controller.stubs(:cookies).returns({ last_tab: 'timdex' }) |
| 56 | + @controller.set_active_tab |
| 57 | + assert_equal 'timdex', @controller.instance_variable_get(:@active_tab) |
| 58 | + end |
| 59 | + |
| 60 | + test 'set_active_tab sets @active_tab to all value when tab params is invalid and cookie is invalid' do |
| 61 | + @controller.stubs(:params).returns({ tab: 'supertab' }) |
| 62 | + @controller.stubs(:cookies).returns({ last_tab: 'woohoo' }) |
| 63 | + @controller.set_active_tab |
| 64 | + assert_equal 'all', @controller.instance_variable_get(:@active_tab) |
| 65 | + end |
| 66 | +end |
0 commit comments