|
3 | 3 | shared_examples_for "conversations selenium tests" do |
4 | 4 | it_should_behave_like "in-process server selenium tests" |
5 | 5 |
|
6 | | - context "conversation loading" do |
7 | | - before do |
8 | | - course_with_teacher_logged_in |
9 | | - @user.watched_conversations_intro |
10 | | - @user.save |
| 6 | + before do |
| 7 | + course_with_teacher_logged_in |
| 8 | + @user.watched_conversations_intro |
| 9 | + @user.save |
| 10 | + end |
| 11 | + |
| 12 | + def new_conversation |
| 13 | + get "/conversations" |
| 14 | + keep_trying_until{ driver.find_element(:id, "create_message_form") } |
| 15 | + end |
| 16 | + |
| 17 | + def submit_message_form(opts={}) |
| 18 | + opts[:message] ||= "Test Message" |
| 19 | + opts[:attachments] ||= [] |
| 20 | + |
| 21 | + if browser = find_with_jquery("#create_message_form .browser:visible") |
| 22 | + browser.click |
| 23 | + keep_trying_until{ |
| 24 | + if elem = find_with_jquery('.selectable:visible') |
| 25 | + elem.click |
| 26 | + end |
| 27 | + elem |
| 28 | + } |
| 29 | + end |
| 30 | + |
| 31 | + find_with_jquery("#create_message_form textarea").send_keys(opts[:message]) |
| 32 | + |
| 33 | + opts[:attachments].each_with_index do |fullpath, i| |
| 34 | + driver.find_element(:id, "action_add_attachment").click |
| 35 | + |
| 36 | + keep_trying_until { |
| 37 | + find_all_with_jquery("#create_message_form .file_input:visible")[i] |
| 38 | + }.send_keys(fullpath) |
11 | 39 | end |
12 | 40 |
|
| 41 | + if opts[:media_comment] |
| 42 | + driver.execute_script <<-JS |
| 43 | + $("#media_comment_id").val(#{opts[:media_comment].first.inspect}) |
| 44 | + $("#media_comment_type").val(#{opts[:media_comment].last.inspect}) |
| 45 | + $("#create_message_form .media_comment").show() |
| 46 | + $("#action_media_comment").hide() |
| 47 | + JS |
| 48 | + end |
| 49 | + |
| 50 | + expect { |
| 51 | + find_with_jquery("#create_message_form button[type='submit']").click |
| 52 | + wait_for_ajax_requests |
| 53 | + }.to change(ConversationMessage, :count).by(1) |
| 54 | + |
| 55 | + message = ConversationMessage.last |
| 56 | + driver.find_element(:id, "message_#{message.id}").should_not be_nil |
| 57 | + message |
| 58 | + end |
| 59 | + |
| 60 | + context "conversation loading" do |
13 | 61 | it "should load all conversations" do |
14 | 62 | @me = @user |
15 | 63 | num = 51 |
|
23 | 71 | end |
24 | 72 | end |
25 | 73 |
|
26 | | - context "attachments" do |
27 | | - def new_conversation |
28 | | - get "/conversations" |
29 | | - keep_trying_until{ driver.find_element(:id, "create_message_form") } |
30 | | - end |
| 74 | + context "media comments" do |
| 75 | + it "should add a media comment to the message form" do |
| 76 | + # don't have a good way to test kaltura here, so we just fake it up |
| 77 | + Kaltura::ClientV3.should_receive(:config).at_least(:once).and_return({}) |
| 78 | + mo = MediaObject.new |
| 79 | + mo.media_id = '0_12345678' |
| 80 | + mo.media_type = 'audio' |
| 81 | + mo.context = @user |
| 82 | + mo.user = @user |
| 83 | + mo.title = "test title" |
| 84 | + mo.save! |
31 | 85 |
|
32 | | - def submit_message_form(opts={}) |
33 | | - opts[:message] ||= "Test Message" |
34 | | - opts[:attachments] ||= [] |
35 | | - |
36 | | - if browser = find_with_jquery("#create_message_form .browser:visible") |
37 | | - browser.click |
38 | | - keep_trying_until{ |
39 | | - if elem = find_with_jquery('.selectable:visible') |
40 | | - elem.click |
41 | | - end |
42 | | - elem |
43 | | - } |
44 | | - end |
45 | | - |
46 | | - find_with_jquery("#create_message_form textarea").send_keys(opts[:message]) |
47 | | - |
48 | | - opts[:attachments].each_with_index do |fullpath, i| |
49 | | - driver.find_element(:id, "action_add_attachment").click |
50 | | - |
51 | | - keep_trying_until { |
52 | | - find_all_with_jquery("#create_message_form .file_input:visible")[i] |
53 | | - }.send_keys(fullpath) |
54 | | - end |
55 | | - |
56 | | - expect { |
57 | | - find_with_jquery("#create_message_form button[type='submit']").click |
58 | | - wait_for_ajax_requests |
59 | | - }.to change(ConversationMessage, :count).by(1) |
60 | | - |
61 | | - message = ConversationMessage.last |
62 | | - driver.find_element(:id, "message_#{message.id}").should_not be_nil |
63 | | - message |
64 | | - end |
| 86 | + new_conversation |
| 87 | + |
| 88 | + message = submit_message_form(:media_comment => [mo.media_id, mo.media_type]) |
| 89 | + message = "#message_#{message.id}" |
65 | 90 |
|
66 | | - before do |
67 | | - course_with_teacher_logged_in |
68 | | - @user.watched_conversations_intro |
69 | | - @user.save |
| 91 | + find_all_with_jquery("#{message} .message_attachments li").size.should == 1 |
| 92 | + find_with_jquery("#{message} .message_attachments li a .title").text.should == mo.title |
70 | 93 | end |
| 94 | + end |
71 | 95 |
|
| 96 | + context "attachments" do |
72 | 97 | it "should be able to add an attachment to the message form" do |
73 | 98 | new_conversation |
74 | 99 |
|
|
0 commit comments