forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturbo_spec.rb
80 lines (64 loc) · 2.46 KB
/
turbo_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
# frozen_string_literal: true
require "rails_helper"
describe "with Turbo and Stimulus" do
describe "tabs change on click" do
before do
visit "/stimulus"
end
it "shows horizontal tab on visit" do
page.has_css?("form-horizontal")
end
it "stops showing horizontal tab when other tab is clicked" do
click_link("Inline Form")
page.has_no_css?("form-horizontal")
end
it "shows inline form when Inline Form link is clicked" do
click_link("Inline Form")
page.has_css?("form-inline")
end
it "shows stacked form when Stacked Form link is clicked" do
click_link("Stacked Form")
page.has_no_css?("form-inline") and page.has_no_css?("form-horizontal")
end
end
describe "form submission functions" do
let(:comment) { Comment.new(author: "Author", text: "This is a comment #{Time.zone.now}") }
let(:author_field) { "comment_author" }
let(:author_error) { "Author: can't be blank" }
let(:text_field) { "comment_text" }
let(:text_error) { "Text: can't be blank" }
before do
visit "/stimulus"
end
it "adds a new comment to the page and database" 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")
expect(page).to have_css("h2", text: comment.author)
expect(page).to have_css("p", text: comment.text)
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("Author: can't be blank")
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("Text: can't be blank")
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("Author: can't be blank")
expect(Comment.all.count).to equal(initial_comment_count)
end
end
end