forked from seanpdoyle/select-your-own-seat
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add System Test for viewing a Seat's details
This commit introduces `factory_bot` and configures MiniTest to use it instead of loading our application's fixture files. The first test drives the browser by visiting the Benedum Center's Orchestra floor, then clicking on seat `AA-101`. The `click_on_seat` help is necessary due to Capybara's inability to treat `<a>` elements nested within `<svg>` elements as if they were normal `<a>` elements. Capybara's selector strategies include a matcher that finds `<a>` elements based on their `title` attribute text, or their `aria-label` attribute text. However, when matching elements exist within an `<svg>`, they are not found. To counteract this limitation, the `click_on_seat` uses an `aria-label` attribute CSS selector to determine which element to click. Running the tests --- To simplify executing the entire test suite, this commit declares the `default` Rake task to execute _both_ [`rails test`][test] and [`rails test:system`][system-test]. This diff intentionally commits a failing test suite to the project's revisions history. It represents the "Red" phase of a ["Red, Green, Refactor" cycle][tdd-cycle], and will be resolved in future commits. [default-task]: https://github.com/ruby/rake/tree/v13.0.1#label-Usage [test]: https://guides.rubyonrails.org/v6.0/command_line.html#rails-test [system-test]: https://guides.rubyonrails.org/v6.0/testing.html#implementing-a-system-test [tdd-cycle]: https://en.wikipedia.org/wiki/Test-driven_development#Development_style
- Loading branch information
Showing
6 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
require_relative 'config/application' | ||
|
||
Rails.application.load_tasks | ||
|
||
task default: ["test", "test:system"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
FactoryBot.define do | ||
factory :benedum_center, class: "Venue" do | ||
name { "Benedum Center" } | ||
slug { "benedum_center" } | ||
end | ||
|
||
factory :orchestra, class: "Floor" do | ||
association :venue, factory: [:benedum_center] | ||
|
||
name { "Orchestra" } | ||
slug { "orchestra" } | ||
end | ||
|
||
factory :section do | ||
association :floor, factory: [:orchestra] | ||
|
||
name { "Section #{id}" } | ||
slug { "section-#{id}" } | ||
price { 10_00 } | ||
end | ||
|
||
factory :seat do | ||
association :section | ||
|
||
sequence(:number) | ||
row { "AA" } | ||
x { 0 } | ||
y { 0 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "application_system_test_case" | ||
|
||
class VisitorViewsSeatsTest < ApplicationSystemTestCase | ||
test "visiting the seats index" do | ||
venue = create(:benedum_center) | ||
floor = create(:orchestra, venue: venue) | ||
section = create(:section, floor: floor, price: 10_00) | ||
seat = create(:seat, row: "AA", number: "101", section: section) | ||
|
||
visit("/venues/benedum_center/floors/orchestra/seats") | ||
click_on_seat("AA-101") | ||
|
||
assert_text("$10.00") | ||
end | ||
|
||
def click_on_seat(row_number) | ||
find(%{[aria-label*="#{row_number}"]}).click | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters