-
Notifications
You must be signed in to change notification settings - Fork 385
/
Copy pathrescript_spec.rb
86 lines (68 loc) · 2.63 KB
/
rescript_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
# frozen_string_literal: true
require "rails_helper"
describe "with Rescript" do
describe "tabs change on click" do
before do
visit "/rescript"
end
it "shows horizontal tab on visit" do
expect(page).to have_css(".form-horizontal")
end
it "stops showing horizontal tab when other tab is clicked" do
find("button", text: "Inline Form").click
expect(page).to have_no_css(".form-horizontal")
end
it "shows inline form when Inline Form link is clicked" do
find("button", text: "Inline Form").click
expect(page).to have_css(".form-inline")
end
it "shows stacked form when Stacked Form link is clicked" do
find("button", text: "Stacked Form").click
expect(page).to have_no_css(".form-inline")
expect(page).to have_no_css(".form-horizontal")
end
end
describe "form submission functions" do
let(:comment) { Comment.new(author: "Author", text: "This is a comment") }
let(:author_field) { "comment_author" }
let(:text_field) { "comment_text" }
before do
visit "/rescript"
end
it "adds a new comment to the page" do
fill_in author_field, with: comment.author
fill_in text_field, with: comment.text
click_button("Post")
expect(page).to have_selector "h2", text: comment.author
end
it "comment count increases with successful form submission" do
initital_comment_count = Comment.all.count
new_comment_count = initital_comment_count + 1
fill_in author_field, with: comment.author
fill_in text_field, with: comment.text
click_button("Post")
page.driver.browser.manage.timeouts.implicit_wait = 1
expect(Comment.all.count).to equal(new_comment_count)
end
it "comment count remains the same when author field is empty" do
initial_comment_count = Comment.all.count
fill_in text_field, with: comment.text
click_button("Post")
expect(page).to have_text(/Can't save the comment!/)
expect(Comment.all.count).to equal(initial_comment_count)
end
it "comment count remains the same when text field is empty" do
initial_comment_count = Comment.all.count
fill_in author_field, with: comment.author
click_button("Post")
expect(page).to have_text(/Can't save the comment!/)
expect(Comment.all.count).to equal(initial_comment_count)
end
it "comment count remains the same when both form fields are empty" do
initial_comment_count = Comment.all.count
click_button("Post")
expect(page).to have_text(/Can't save the comment!/)
expect(Comment.all.count).to equal(initial_comment_count)
end
end
end