-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathpost_question_test.rb
85 lines (63 loc) · 2.49 KB
/
post_question_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
require "application_system_test_case"
class QuestionTest < ApplicationSystemTestCase
Capybara.default_max_wait_time = 60
def setup
visit '/'
find(".nav-link.loginToggle").click()
fill_in("username-login", with: "jeff")
fill_in("password-signup", with: "secretive")
find(".login-modal-form #login-button").click()
end
test 'viewing question post' do
visit '/questions/new'
take_screenshot
end
# Test for https://github.com/publiclab/PublicLab.Editor/issues/113
test 'posting a question' do
visit '/questions/new'
find('[placeholder="What\'s your question? Be specific."]').set("Let's test this, shall we?");
page.execute_script <<-JS
// Create button element
var btn = document.createElement('button');
btn.id = 'copy-to-clipboard';
btn.textContent = "Click me to copy the text!";
// Copying to the clipboard requires user's interaction
btn.addEventListener('click', copyToClipboard);
document.body.appendChild(btn);
function copyToClipboard() {
// Create temporary textarea element
var tempEl = document.createElement('textarea');
// Set the value to the textarea
tempEl.value = `
1. Post your suggested activity as an Answer below (not a comment).
2. Other people can Comment on that idea.
3. Other people can Like (star) that idea.
`;
document.body.appendChild(tempEl);
// Copy the content from the textarea
tempEl.select();
document.execCommand('copy');
document.body.removeChild(tempEl);
};
JS
# Copy text to clipboard
find('#copy-to-clipboard').click()
# Paste it in the question's body
find('.wk-wysiwyg').native.send_keys [:control, 'v']
find('.ple-publish').click();
# Wait for note to be published
wait_for_ajax
message = find('.alert-success').text
note_title = find('.note-show h1', match: :first).text
assert_equal( "Let's test this, shall we?", note_title )
assert_equal( "×\nResearch note published. Get the word out on the discussion lists!", message )
end
test 'post question button is disabled on invalid data' do
visit '/questions/new'
find('[placeholder="What\'s your question? Be specific."]').set(' ');
find('.wk-wysiwyg').set('Question with an empty title!')
find('.ple-publish').click();
askQuestionButton = find('.ple-publish.disabled', text: 'Ask')
assert_equal askQuestionButton.disabled?, true
end
end