-
Notifications
You must be signed in to change notification settings - Fork 482
/
user_menu_test.rb
99 lines (74 loc) · 2.55 KB
/
user_menu_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require 'test_helper'
class UserMenuTest < ActionDispatch::IntegrationTest
def open_pairing_test(show_pairing)
student = create(:student_in_word_section)
section = student.sections_as_student.first
post "/sections/#{section.code}/log_in", params: {
id: section.code,
user_id: student.id,
secret_words: student.secret_words,
show_pairing_dialog: show_pairing ? 1 : nil
}
assert_redirected_to '/'
assert_equal show_pairing, !!@controller.session[:show_pairing_dialog]
get '/home'
assert_select 'script', /dashboard.pairing.init.*#{show_pairing}/
refute @controller.session[:show_pairing_dialog] # should only show once
end
test 'user menu should open pairing dialog if asked to on login' do
open_pairing_test true
end
test 'user menu should not open pairing dialog if not asked to on login' do
open_pairing_test false
end
test 'student does not see links to teacher dashboard' do
student = create :student
sign_in student
get '/home'
assert_response :success
assert_select 'a[href="//test.code.org/teacher-dashboard"]', 0
end
test 'should redirect for signed out user' do
sign_out :user
get '/home'
assert_response :redirect
end
test 'should show sign out link for signed in user' do
student = create :student
sign_in student
get '/home'
assert_response :success
assert_select 'a[href="//test-studio.code.org/users/sign_out"]', 'Sign out'
end
test "don't show link to pair programming when not in a section" do
student = create(:student)
sign_in student
get '/home'
assert_response :success
assert_select 'a[href="http://test.host/pairing"]', false
end
test 'show link to pair programming when in a section that has pairing enabled' do
student = create(:follower).student_user
sign_in student
section = student.sections_as_student.first
assert section.pairing_allowed?
assert student.can_pair?
get '/home'
assert_response :success
assert_select '#pairing_link'
end
test "don't show link to pair programming when in a section that has pairing disabled" do
student = create(:follower).student_user
sign_in student
section = student.sections_as_student.first
assert section.pairing_allowed?
assert student.can_pair?
section.update!(pairing_allowed: false)
student.reload
refute section.pairing_allowed?
refute student.can_pair?
get '/home'
assert_response :success
assert_select 'a[href="http://test.host/pairing"]', false
end
end