-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
enhanceable_content_spec.rb
166 lines (141 loc) · 5.79 KB
/
enhanceable_content_spec.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
require File.expand_path(File.dirname(__FILE__) + '/common')
describe "enhanceable_content" do
include_examples "in-process server selenium tests"
it "should automatically enhance content using jQuery UI" do
stub_kaltura
course_with_teacher_logged_in
page = @course.wiki.wiki_pages.build(:title => 'title')
page.body = %{
<div id="dialog_for_link1" class="enhanceable_content dialog">dialog for link 1</div>
<a href="#dialog_for_link1" id="link1">link 1</a>
<div class="enhanceable_content draggable" style="width: 100px;">draggable</div>
<div class="enhanceable_content resizable" style="width: 100px;">resizable</div>
<ul class="enhanceable_content sortable" style="display: none;">
<li>item 1</li>
<li>item 2</li>
</ul>
<div class="enhanceable_content accordion">
<h3><a href="#">Section 1</a></h3>
<div>
<p>
Section 1 Content
</p>
</div>
<h3><a href="#">Section 2</a></h3>
<div>
<p>
Section 2 Content
</p>
</div>
<h3><a href="#">Section 3</a></h3>
<div>
<p>
Section 3 Content
</p>
<ul>
<li>List item one</li>
<li>List item two</li>
<li>List item three</li>
</ul>
</div>
</div>
<div class="enhanceable_content tabs">
<ul>
<li><a href="#fragment-1"><span>One</span></a></li>
<li><a href="#fragment-2"><span>Two</span></a></li>
<li><a href="#fragment-3"><span>Three</span></a></li>
</ul>
<div id="fragment-1">
<p>First tab is active by default:</p>
<pre><code>$('#example').tabs();</code></pre>
</div>
<div id="fragment-2">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</div>
<div id="fragment-3">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</div>
</div>
<a id="media_comment_0_deadbeef" class="instructure_file_link instructure_video_link" title="Video.mp4" href="/courses/1/files/1/download?wrap=1">Video</a>
}
page.save!
get "/courses/#{@course.id}/wiki/#{page.url}"
dialog = f(".enhanceable_content.dialog")
# need to wait for the content to get enhanced (it happens in instructure.js in a setTimeout of 1000 ms)
keep_trying_until {
f("#link1").click
expect(dialog).to be_displayed
expect(dialog).to have_class('ui-dialog')
}
f(".ui-dialog .ui-dialog-titlebar-close").click
expect(dialog).not_to be_displayed
expect(f(".enhanceable_content.draggable")).to have_class('ui-draggable')
expect(f(".enhanceable_content.resizable")).to have_class('ui-resizable')
ul = f(".enhanceable_content.sortable")
expect(ul).to be_displayed
expect(ul).to have_class('ui-sortable')
accordion = f(".enhanceable_content.accordion")
expect(accordion).to have_class('ui-accordion')
headers = accordion.find_elements(:css, ".ui-accordion-header")
expect(headers.length).to eq 3
divs = accordion.find_elements(:css, ".ui-accordion-content")
expect(divs.length).to eq 3
expect(headers[0]).to have_class('ui-state-active')
expect(divs[0]).to be_displayed
expect(divs[1]).not_to be_displayed
headers[1].click
wait_for_ajaximations
expect(headers[0]).to have_class('ui-state-default')
expect(headers[1]).to have_class('ui-state-active')
expect(divs[0]).not_to be_displayed
expect(divs[1]).to be_displayed
tabs = f(".enhanceable_content.tabs")
expect(tabs).to have_class('ui-tabs')
headers = tabs.find_elements(:css, ".ui-tabs-nav li")
expect(headers.length).to eq 3
divs = tabs.find_elements(:css, ".ui-tabs-panel")
expect(divs.length).to eq 3
expect(headers[0]).to have_class('ui-state-active')
expect(headers[1]).to have_class('ui-state-default')
expect(divs[0]).to be_displayed
expect(divs[1]).not_to be_displayed
expect(f('#media_comment_0_deadbeef span.media_comment_thumbnail')).not_to be_nil
end
context "media file preview thumbnails" do
before :each do
stub_kaltura
course(:active_all => true)
@attachment = @course.attachments.create!(:uploaded_data => stub_file_data('video1.mp4', nil, 'video/mp4'))
@page = @course.wiki.wiki_pages.build(:title => 'title')
@page.body = %{
<a id="media_comment_0_deadbeef" class="instructure_file_link instructure_video_link" title="Video.mp4"
href="/courses/#{@course.id}/files/#{@attachment.id}/download?wrap=1">Video</a>
}
@page.save!
end
it "should show for students" do
student_in_course(:course => @course, :active_user => true)
user_session(@student)
get "/courses/#{@course.id}/wiki/#{@page.url}"
expect(f('#media_comment_0_deadbeef span.media_comment_thumbnail')).to_not be_nil
end
describe "for locked files" do
before :each do
@attachment.locked = true
@attachment.save!
end
it "should not show for students" do
student_in_course(:course => @course, :active_user => true)
user_session(@student)
get "/courses/#{@course.id}/wiki/#{@page.url}"
expect(f('#media_comment_0_deadbeef span.media_comment_thumbnail')).to be_nil
end
it "should show for teachers" do
teacher_in_course(:course => @course, :active_user => true)
user_session(@teacher)
get "/courses/#{@course.id}/wiki/#{@page.url}"
expect(f('#media_comment_0_deadbeef span.media_comment_thumbnail')).to_not be_nil
end
end
end
end