Skip to content

Commit

Permalink
Add system test for schedule page
Browse files Browse the repository at this point in the history
  • Loading branch information
kinoppyd committed Mar 21, 2024
1 parent 12a7d2f commit ddc6e4b
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<nav>
<div class="flex items-center direction-row h-[50px] bg-[var(--mainColor)]">
<div class="flex flex-row items-center mx-4 my-0 text-white">
<img class="h-6" src="<%= asset_path("#{@event.name}/rubykaigi_logo.svg") %>">
<% unless Rails.env.test? %>
<img class="h-6" src="<%= asset_path("#{@event.name}/rubykaigi_logo.svg") %>">
<% end %>
<div class="flex items-center">
<div class="flex items-center gap-0.5 ml-2">
<span class="">Schedule.select</span>
Expand Down
10 changes: 5 additions & 5 deletions app/views/schedules/_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@
<%= form_with(url: event_plan_url(@plan, event_name: @plan.event.name), method: 'PATCH' ) do |form| %>
<%= form.hidden_field :remove_schedule_id, value: schedule.id %>
<%= form.hidden_field :mode, value: mode %>
<%= form.submit I18n.t('card.remove'), class: "p-2 text-sm font-bold min-h-5 normal-button", data: { turbo_frame: "event_#{@event.id}" } %>
<%= form.submit I18n.t('card.remove'), class: "remove-plan-button p-2 text-sm font-bold min-h-5 normal-button", data: { turbo_frame: "event_#{@event.id}" } %>
<% end %>
<% elsif @plan.new_record? %>
<div data-controller="dialog" data-dialog-element-id-value="terms-of-service-<%= schedule.id %>">
<button class="p-2 text-sm font-bold min-h-5 normal-button"
<button class="add-plan-button p-2 text-sm font-bold min-h-5 normal-button"
data-action="click->dialog#open"
>
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" class=" smarthr-ui-Icon" role="img" aria-hidden="true" focusable="false" height="16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm144 276c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92h-92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z"></path></svg>
Expand Down Expand Up @@ -106,7 +106,7 @@
<%= form.hidden_field :mode, value: mode %>
<%= form.hidden_field :initial, value: false %>
<%= form.hidden_field :add_schedule_id, value: schedule.id %>
<%= form.submit I18n.t('button.accept_to_add'), class: "text-sm font-bold min-h-5 ml-2 primary-button", data: { turbo_frame: "_top" } %>
<%= form.submit I18n.t('button.accept_to_add'), class: "confirm-terms-of-service-button text-sm font-bold min-h-5 ml-2 primary-button", data: { turbo_frame: "_top" } %>
<% end %>
</div>
</div>
Expand All @@ -116,13 +116,13 @@
<%= form_with(url: event_plan_url(@plan, event_name: @plan.event.name), method: 'PATCH' ) do |form| %>
<%= form.hidden_field :add_schedule_id, value: schedule.id %>
<%= form.hidden_field :mode, value: mode %>
<%= form.submit inactive ? I18n.t('card.inactive') : I18n.t('card.add'), class: "p-2 text-sm font-bold min-h-5 normal-button", disabled: inactive, data: { turbo_frame: "event_#{@event.id}"} %>
<%= form.submit inactive ? I18n.t('card.inactive') : I18n.t('card.add'), class: "add-plan-button p-2 text-sm font-bold min-h-5 normal-button", disabled: inactive, data: { turbo_frame: "event_#{@event.id}"} %>
<% end %>
<% end %>
</div>
<div class="ml-2">
<a
class="p-2 text-sm bg-transparent hover:bg-[rgb(242,242,242)] text-[rgb(35,34,30)] box-border inline-flex justify-center items-center text-center rounded-md font-bold"
class="show-detail-button p-2 text-sm bg-transparent hover:bg-[rgb(242,242,242)] text-[rgb(35,34,30)] box-border inline-flex justify-center items-center text-center rounded-md font-bold"
href="<%= event_schedule_dialog_url(schedule, event_name: @plan.event.name) %>"
data-turbo-frame="modal"
>
Expand Down
4 changes: 3 additions & 1 deletion app/views/schedules/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<meta property="og:title" content="RubyKaigi Schedule.select">
<meta property="og:site_name" content="RubyKaigi Schedule.select powerd by SmartHR">
<meta property="og:url" content="<%= event_schedules_url(event_name: @event.name) %>">
<meta property="og:image" content="<%= asset_url("#{@event.name}/ogp_top.png") %>" />
<% unless Rails.env.test? %>
<meta property="og:image" content="<%= asset_url("#{@event.name}/ogp_top.png") %>" />
<% end %>
<meta property="og:type" content="website">
<meta name="twitter:card" content="summary_large_image"/>
<% end %>
Expand Down
5 changes: 5 additions & 0 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end
94 changes: 94 additions & 0 deletions test/system/schedules_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
require "application_system_test_case"

class SchedulesTest < ApplicationSystemTestCase
test 'schedule has all days buttons' do
visit event_schedules_path(event_name: events(:kaigi).name)
assert_button('2024-03-18')
assert_button('2024-03-19')
end

test 'schedule date button can switch table' do
visit event_schedules_path(event_name: events(:kaigi).name)

assert_selector('h3', text: 'keynote1')
refute_selector('h3', text: 'keynote2')

click_button('2024-03-19')

refute_selector('h3', text: 'keynote1')
assert_selector('h3', text: 'keynote2')
end

test 'schedule cards count expected' do
visit event_schedules_path(event_name: events(:kaigi).name)

table_rows = all('tr')

assert_equal 1, table_rows[1].all('turbo-frame').count
assert_equal 3, table_rows[2].all('turbo-frame').count
assert_equal 2, table_rows[3].all('turbo-frame').count
assert_equal 1, table_rows[4].all('turbo-frame').count

click_button('2024-03-19')

table_rows = all('tr')

assert_equal 3, table_rows[1].all('turbo-frame').count
assert_equal 2, table_rows[2].all('turbo-frame').count
assert_equal 2, table_rows[3].all('turbo-frame').count
assert_equal 1, table_rows[4].all('turbo-frame').count
end

test 'anker works' do
visit "#{event_schedules_path(event_name: events(:kaigi).name)}#2024-03-19"
find_button(class: 'tab-btn-active').has_text?('2024-03-19')
end

test 'dialog shown up' do
visit event_schedules_path(event_name: events(:kaigi).name)

refute_selector('dialog')

all(class: ['show-detail-button'])[0].click

assert_selector('dialog')
end

test 'when add a schedule to plan first time, shown up dialog' do
visit event_schedules_path(event_name: events(:kaigi).name)

all(class: ['add-plan-button'])[0].click

assert_selector(class: ['confirm-terms-of-service-button'])
end

test 'when one schedule added to plan, disable same row schedule button' do
visit event_schedules_path(event_name: events(:kaigi).name)

all(class: ['add-plan-button'])[1].click
find(class: ['confirm-terms-of-service-button']).click

# wait for turbo frame
if has_selector?('dialog', visible: true, wait: (0.25).seconds)
has_no_selector?('dialog', visible: true, wait: 1.seconds)
end

table_rows = all('tr')
assert table_rows[2].all(class: ['add-plan-button']).all? { _1.disabled? }
end

test 'when one schedule added to plan, that schedule button to be remove button' do
visit event_schedules_path(event_name: events(:kaigi).name)

all(class: ['add-plan-button'])[1].click
find(class: ['confirm-terms-of-service-button']).click

# wait for turbo frame
if has_selector?('dialog', visible: true, wait: (0.25).seconds)
has_no_selector?('dialog', visible: true, wait: 1.seconds)
end

table_rows = all('tr')
assert table_rows[2].find_button(class: ['remove-plan-button'])
end
end

0 comments on commit ddc6e4b

Please sign in to comment.