Skip to content

Commit

Permalink
spot system spec 作成完了
Browse files Browse the repository at this point in the history
  • Loading branch information
YukiWatanabe824 committed Jun 21, 2024
1 parent 0ba9db7 commit 19286a3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 72 deletions.
3 changes: 0 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
# frozen_string_literal: true

puts "\n== Seeding the database with fixtures ==" # rubocop:disable all
system('bin/rails db:fixtures:load')
4 changes: 4 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
rescue ActiveRecord::PendingMigrationError => e
abort e.to_s.strip
end
# Log output for STDOUT
# Rails.logger = Logger.new(STDOUT)

RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_paths = [
Expand Down Expand Up @@ -70,6 +73,7 @@

# using devise (auth) helper
config.include Devise::Test::ControllerHelpers, type: :controller
# config.include Devise::Test::ControllerHelpers, type: :system
config.include Devise::Test::IntegrationHelpers, type: :system

# helper methods
Expand Down
137 changes: 68 additions & 69 deletions spec/system/spots_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,40 @@
let(:make_by_admin_spot) { FactoryBot.create(:spot, :make_by_admin_user) }
let(:make_by_standard_spot) { FactoryBot.create(:spot, :make_by_standard_user) }
let(:user) { FactoryBot.create(:user, :admin_user) }
let(:not_admin_user) { FactoryBot.create(:user, :not_admin_user) }

scenario 'showing spots on map' do
scenario 'spot should appear on the map' do
make_by_admin_spot
visit_root_closed_modal
expect(Spot.all.length).to eq page.all('.spot_marker', visible: false).count
end

scenario 'showing spot menu by right click on spot marker' do
scenario 'Right-clicking on a spot marker should bring up the spot menu' do
visit_root_closed_modal

find(".mapboxgl-map").click(x: 50, y: 50)
find('#new_spot_marker').right_click
expect(page).to have_selector '#spot_menu'
end

scenario 'showing spot info in side menu by not signed in' do
scenario 'Spot information is displayed in the side menu when not logged in' do
spot = make_by_admin_spot
visit_root_closed_modal
expect(page).to have_selector '#map'
expect(page).to have_selector '.mapboxgl-canvas-container'

spot = Spot.all.first
find(".spot-#{spot.id}", visible: false).click(x: 0, y: -5)
expect(page).to have_selector '.spot_accident_date', text: "#{spot.accident_date.year}#{spot.accident_date.month}#{spot.accident_date.day}日"
expect(page).to have_selector '.spot_accident_type', text: spot.accident_type
expect(page).to have_selector '.spot_created_at', text: "#{spot.created_at.year}#{spot.created_at.month}#{spot.created_at.day}日"
expect(page).to have_selector '.spot_id', text: spot.id
end

scenario 'create spot' do
scenario 'A spot can be registered when the user is logged in' do
spot = make_by_admin_spot
sign_in user
visit_root_closed_modal

spot = Spot.all.first

find(".spot-#{spot.id}", visible: false).click(x: 50, y: 50)
find('#new_spot_marker').right_click
click_on('スポットを作成する')
Expand All @@ -53,84 +54,82 @@
expect(page).to have_selector '.spot_content', text: 'test'
end

# scenario 'unknown accident date' do
# user = users(:watanabe)
# sign_in user
# visit_root_closed_modal

# spot = spots(:one)
scenario 'Users can register a spot even if the date of the accident is not known' do
spot = make_by_admin_spot
sign_in user
visit_root_closed_modal

# find(".spot-#{spot.id}", visible: false).click(x: 50, y: 50)
# find('#new_spot_marker').right_click
# click_on('スポットを作成する')
find(".spot-#{spot.id}", visible: false).click(x: 50, y: 50)
find('#new_spot_marker').right_click
click_on('スポットを作成する')

# choose('spot_accident_type_物損事故')
# fill_in '追加情報', with: 'test'
# fill_in '事故の発生日', with: Date.new(2021, 1, 1)
# check '正確な日付がわからない'
# click_on('登録する')
# assert_selector '.spot_accident_date', text: '発生日 : 2021年1月1日 ごろ'
# end
choose('spot_accident_type_物損事故')
fill_in '追加情報', with: 'test'
fill_in '事故の発生日', with: Date.new(2021, 1, 1)
check '正確な日付がわからない'
click_on('登録する')
expect(page).to have_selector '.spot_accident_date', text: '発生日 : 2021年1月1日 ごろ'
end

# scenario 'create a spot but a warning appears if you are not logged in' do
# visit_root_closed_modal
# assert_selector '#map'
scenario 'Alerts are displayed when registering a spot if the user is not logged in' do
spot = make_by_admin_spot
visit_root_closed_modal
expect(page).to have_selector '#map'

# spot = spots(:one)

# find(".spot-#{spot.id}", visible: false).click(x: 50, y: 50)
find(".spot-#{spot.id}", visible: false).click(x: 50, y: 50)

# assert_selector '#new_spot_marker'
# find('#new_spot_marker').right_click
# click_on('スポットを作成する')
expect(page).to have_selector '#new_spot_marker'
find('#new_spot_marker').right_click
click_on('スポットを作成する')

# assert_text 'スポットの登録にはユーザー登録が必要です'
# find('.spot-creating-required-logged-in').click
# assert_text 'ログイン'
# end
expect(page).to have_text 'スポットの登録にはユーザー登録が必要です'
find('.spot-creating-required-logged-in').click
expect(page).to have_text 'ログイン'
end

# scenario 'error message is displayedcreate when create spot' do
# user = users(:watanabe)
# sign_in user
# visit_root_closed_modal
# assert_selector '#map'
scenario 'Incomplete entries will alert you when registering a spot' do
spot = make_by_admin_spot
sign_in user
visit_root_closed_modal
expect(page).to have_selector '#map'

# spot = spots(:one)

# find(".spot-#{spot.id}", visible: false).click(x: 50, y: 50)
find(".spot-#{spot.id}", visible: false).click(x: 50, y: 50)

# assert_selector '#new_spot_marker'
# find('#new_spot_marker').right_click
# click_on('スポットを作成する')
expect(page).to have_selector '#new_spot_marker'
find('#new_spot_marker').right_click
click_on('スポットを作成する')

# click_on('登録する')
# assert_text '入力内容に不備があり、登録できませんでした'
# end
click_on('登録する')
expect(page).to have_text '入力内容に不備があり、登録できませんでした'
end

# scenario 'edit spot' do
# user = users(:watanabe)
# sign_in user
# visit_root_closed_modal
scenario 'Spots created by users themselves can be edited' do
spot = make_by_standard_spot
user = spot.user
sign_in user
visit_root_closed_modal

# find(".spot-#{user.spots[0].id}", visible: false).click(x: 0, y: -5)
# click_on '編集'
# fill_in('タイトル', with: 'edited test')
# choose('spot_accident_type_物損事故')
# click_button '更新する'
find(".spot-#{spot.id}", visible: false).click(x: 0, y: -5)
click_on '編集'
fill_in('タイトル', with: 'edited test')
choose('spot_accident_type_物損事故')
click_button '更新する'

# assert_selector '#flash', text: '更新しました'
# end
expect(page).to have_selector '#flash', text: '更新しました'
end

# scenario 'destroy spot' do
# user = users(:watanabe)
# sign_in user
# visit_root_closed_modal
scenario 'Spots created by users themselves can be deleted' do
spot = make_by_standard_spot
sign_in spot.user
visit_root_closed_modal

# find(".spot-#{user.spots[0].id}", visible: false).click(x: 0, y: -5)
# accept_confirm do
# click_on '削除'
# end
find(".spot-#{spot.id}", visible: false).click(x: 0, y: -5)
accept_confirm do
click_on '削除'
end

# assert_selector '#flash', text: '削除しました'
# end
expect(page).to have_selector '#flash', text: '削除しました'
end
end

0 comments on commit 19286a3

Please sign in to comment.