Skip to content

Commit

Permalink
[modify] add spec
Browse files Browse the repository at this point in the history
  • Loading branch information
itowtips committed Apr 22, 2021
1 parent 204a06c commit a295dbb
Show file tree
Hide file tree
Showing 9 changed files with 459 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/views/guide/questions/edge/_no.html.erb
Expand Up @@ -12,7 +12,7 @@
<tbody>
<% edge.points.each do |point| %>
<tr data-id="<%= point.id %>">
<td><%= hidden_field_tag "item[in_edges][][point_ids][]", point.id %> <%= point.name %></td>
<td><%= hidden_field_tag "item[in_edges][][point_ids][]", point.id %> <%= point.name_with_type %></td>
<td><%= link_to t("ss.buttons.delete"), "#", class: "deselect btn" %></td>
</tr>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/guide/questions/edge/_yes.html.erb
Expand Up @@ -4,7 +4,7 @@
<dd>
<%= hidden_field_tag "item[in_edges][][value]", t("guide.links.applicable") %>
<%= hidden_field_tag "item[in_edges][][question_type]", "yes_no" %>
<%= hidden_field_tag "item[in_edges][][point_ids][]", edge.value, class: "hidden-ids" %>
<%= hidden_field_tag "item[in_edges][][point_ids][]", "", class: "hidden-ids" %>
<%= link_to t("ss.links.select"), guide_apis_procedures_path(nid: @cur_node.id, id: @item.id), class: "ajax-box" %>
</dd>
<dd>
Expand Down
9 changes: 9 additions & 0 deletions spec/factories/guide/nodes.rb
@@ -0,0 +1,9 @@
FactoryBot.define do
factory :guide_node_base, class: Guide::Node::Base, traits: [:cms_node] do
route "guide/base"
end

factory :guide_node_guide, class: Guide::Node::Guide, traits: [:cms_node] do
route "guide/guide"
end
end
11 changes: 11 additions & 0 deletions spec/factories/guide/procedures.rb
@@ -0,0 +1,11 @@
FactoryBot.define do
factory :guide_procedure, class: Guide::Procedure do
name unique_id
link_url "https://shirasagi.example.jp"
html "<p>#{unique_id}</p>"
procedure_location "location1\nlocation2\nlocation3"
belongings "belong1\nbelong2\nbelong3"
procedure_applicant "applicant1\napplicant2\napplicant3"
remarks "remarks"
end
end
6 changes: 6 additions & 0 deletions spec/factories/guide/questions.rb
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :guide_question, class: Guide::Question do
name unique_id
question_type "yes_no"
end
end
199 changes: 199 additions & 0 deletions spec/features/guide/agents/nodes/guide_spec.rb
@@ -0,0 +1,199 @@
require 'spec_helper'

describe "guide_agents_nodes_guide", type: :feature, dbscope: :example, js: true do
let(:site) { cms_site }
let(:layout) { create_cms_layout }
let(:node) { create :guide_node_guide, layout_id: layout.id, filename: "guide" }

context "public" do
before do
Capybara.app_host = "http://#{site.domain}"
end

context "no procedures" do
it "#index" do
visit node.url
within ".guide-node-form" do
within "footer.send" do
click_on I18n.t("guide.links.start_guide")
end

expect(page).to have_css(".procedure-count", text: I18n.t("guide.views.procedures_needed", count: 0))
click_on I18n.t("guide.links.show_answer")

expect(page).to have_text(I18n.t("guide.views.your-answers"))
click_on I18n.t("guide.links.show_result")

expect(page).to have_css(".procedure-count", text: I18n.t("guide.views.procedures_needed", count: 0))
click_on I18n.t("guide.links.show_procedure")

expect(page).to have_text(I18n.t("guide.views.all_procedure"))
click_on I18n.t("guide.links.show_result")

expect(page).to have_css(".procedure-count", text: I18n.t("guide.views.procedures_needed", count: 0))
click_on I18n.t("guide.links.back_to_first")

within "footer.send" do
click_on I18n.t("guide.links.start_guide")
end
end
end
end

context "diagram" do
let!(:procedure1) { create :guide_procedure, cur_site: site, cur_node: node, name: "procedure1", order: 10 }
let!(:procedure2) { create :guide_procedure, cur_site: site, cur_node: node, name: "procedure2", order: 20 }
let!(:procedure3) { create :guide_procedure, cur_site: site, cur_node: node, name: "procedure3", order: 30 }
let!(:procedure4) { create :guide_procedure, cur_site: site, cur_node: node, name: "procedure4", order: 40 }
let!(:procedure5) { create :guide_procedure, cur_site: site, cur_node: node, name: "procedure5", order: 50 }

let!(:question1) { create :guide_question, cur_site: site, cur_node: node, name: "question1", order: 10, in_edges: in_edges(procedure1) }
let!(:question2) { create :guide_question, cur_site: site, cur_node: node, name: "question2", order: 20, in_edges: in_edges(procedure2) }
let!(:question3) { create :guide_question, cur_site: site, cur_node: node, name: "question3", order: 30, in_edges: in_edges(procedure3) }
let!(:question4) { create :guide_question, cur_site: site, cur_node: node, name: "question4", order: 40, in_edges: in_edges(procedure4) }
let!(:question5) { create :guide_question, cur_site: site, cur_node: node, name: "question5", order: 50, in_edges: in_edges(procedure5) }

def in_edges(point)
[
{ value: I18n.t("guide.links.applicable"), question_type: "yes_no", point_ids: [point.id] },
{ value: I18n.t("guide.links.not_applicable"), question_type: "yes_no", point_ids: [] }
]
end

it "#index" do
visit node.url
within ".guide-node-form" do
# 5 times yes
within "footer.send" do
click_on I18n.t("guide.links.start_guide")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question1.name)
within "footer.send" do
click_on I18n.t("guide.links.applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question2.name)
within "footer.send" do
click_on I18n.t("guide.links.applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question3.name)
within "footer.send" do
click_on I18n.t("guide.links.applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question4.name)
within "footer.send" do
click_on I18n.t("guide.links.applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question5.name)
within "footer.send" do
click_on I18n.t("guide.links.applicable")
end

expect(page).to have_css(".procedure-count", text: I18n.t("guide.views.procedures_needed", count: 5))
expect(page).to have_link(procedure1.name)
expect(page).to have_link(procedure2.name)
expect(page).to have_link(procedure3.name)
expect(page).to have_link(procedure4.name)
expect(page).to have_link(procedure5.name)

click_on I18n.t("guide.links.back_to_first")

# 3 times yes, 2 times no
within "footer.send" do
click_on I18n.t("guide.links.start_guide")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question1.name)
within "footer.send" do
click_on I18n.t("guide.links.applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question2.name)
within "footer.send" do
click_on I18n.t("guide.links.not_applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question3.name)
within "footer.send" do
click_on I18n.t("guide.links.applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question4.name)
within "footer.send" do
click_on I18n.t("guide.links.not_applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question5.name)
within "footer.send" do
click_on I18n.t("guide.links.applicable")
end

expect(page).to have_css(".procedure-count", text: I18n.t("guide.views.procedures_needed", count: 3))
expect(page).to have_link(procedure1.name)
expect(page).to have_no_link(procedure2.name)
expect(page).to have_link(procedure3.name)
expect(page).to have_no_link(procedure4.name)
expect(page).to have_link(procedure5.name)

click_on I18n.t("guide.links.back_to_first")

# 5 times no
within "footer.send" do
click_on I18n.t("guide.links.start_guide")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question1.name)
within "footer.send" do
click_on I18n.t("guide.links.not_applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question2.name)
within "footer.send" do
click_on I18n.t("guide.links.not_applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question3.name)
within "footer.send" do
click_on I18n.t("guide.links.not_applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question4.name)
within "footer.send" do
click_on I18n.t("guide.links.not_applicable")
end

expect(page).to have_css(".question-nav", text: I18n.t("guide.views.choose_yes_no"))
expect(page).to have_css(".question", text: question5.name)
within "footer.send" do
click_on I18n.t("guide.links.not_applicable")
end

expect(page).to have_css(".procedure-count", text: I18n.t("guide.views.procedures_needed", count: 0))
expect(page).to have_no_link(procedure1.name)
expect(page).to have_no_link(procedure2.name)
expect(page).to have_no_link(procedure3.name)
expect(page).to have_no_link(procedure4.name)
expect(page).to have_no_link(procedure5.name)
end
end
end
end
end
81 changes: 81 additions & 0 deletions spec/features/guide/procedures/basic_crud_spec.rb
@@ -0,0 +1,81 @@
require 'spec_helper'

describe "guide_procedures", type: :feature, dbscope: :example, js: true do
let(:site) { cms_site }
let(:node) { create :guide_node_guide, filename: "guide" }
let(:item) { create(:guide_procedure, cur_site: site, cur_node: node) }

let(:index_path) { guide_procedures_path site.id, node }
let(:new_path) { new_guide_procedure_path site.id, node }
let(:show_path) { guide_procedure_path site.id, node, item }
let(:edit_path) { edit_guide_procedure_path site.id, node, item }
let(:delete_path) { delete_guide_procedure_path site.id, node, item }

context "basic crud" do
before { login_cms_user }

it "#index" do
visit index_path
expect(current_path).not_to eq sns_login_path
end

it "#new" do
visit new_path
within "form#item-form" do
fill_in "item[name]", with: "sample"
click_on I18n.t("ss.buttons.save")
end
expect(page).to have_css('#notice', text: I18n.t('ss.notice.saved'))
end

it "#show" do
visit show_path

within "#addon-basic" do
expect(page).to have_text(item.name)
expect(page).to have_text(item.link_url)
end
within "#addon-guide-agents-addons-procedure" do
expect(page).to have_text("location1")
expect(page).to have_text("belong1")
expect(page).to have_text("applicant1")
expect(page).to have_text("remarks")
end
end

it "#edit" do
visit edit_path
within "form#item-form" do
fill_in "item[name]", with: "modify"
fill_in "item[link_url]", with: "https://modify.example.jp"
fill_in_code_mirror "item[html]", with: "<p>modify_html</p>"
fill_in "item[procedure_location]", with: "modify_location1"
fill_in "item[belongings]", with: "modify_belong1"
fill_in "item[procedure_applicant]", with: "modify_applicant1"
fill_in "item[remarks]", with: "modify_remarks"
click_on I18n.t("ss.buttons.save")
end
expect(page).to have_css('#notice', text: I18n.t('ss.notice.saved'))

within "#addon-basic" do
expect(page).to have_text("modify")
expect(page).to have_text("https://modify.example.jp")
end
within "#addon-guide-agents-addons-procedure" do
expect(page).to have_text("modify_html")
expect(page).to have_text("modify_location1")
expect(page).to have_text("modify_belong1")
expect(page).to have_text("modify_applicant1")
expect(page).to have_text("modify_remarks")
end
end

it "#delete" do
visit delete_path
within "form" do
click_on I18n.t("ss.buttons.delete")
end
expect(page).to have_css('#notice', text: I18n.t('ss.notice.deleted'))
end
end
end
60 changes: 60 additions & 0 deletions spec/features/guide/questions/basic_crud_spec.rb
@@ -0,0 +1,60 @@
require 'spec_helper'

describe "guide_questions", type: :feature, dbscope: :example, js: true do
let(:site) { cms_site }
let(:node) { create :guide_node_guide, filename: "guide" }
let(:item) { create(:guide_question, cur_site: site, cur_node: node) }

let(:index_path) { guide_questions_path site.id, node }
let(:new_path) { new_guide_question_path site.id, node }
let(:show_path) { guide_question_path site.id, node, item }
let(:edit_path) { edit_guide_question_path site.id, node, item }
let(:delete_path) { delete_guide_question_path site.id, node, item }

context "basic crud" do
before { login_cms_user }

it "#index" do
visit index_path
expect(current_path).not_to eq sns_login_path
end

it "#new" do
visit new_path
within "form#item-form" do
fill_in "item[name]", with: "sample"
click_on I18n.t("ss.buttons.save")
end
expect(page).to have_css('#notice', text: I18n.t('ss.notice.saved'))
end

it "#show" do
visit show_path
expect(page).to have_css("#addon-basic", text: item.name)
expect(page).to have_css("#addon-guide-agents-addons-question", text: I18n.t("guide.options.question_type.yes_no"))
end

it "#edit" do
visit edit_path
within "form#item-form" do
fill_in "item[name]", with: "modify"
choose "item_question_type_choices"
choose "item_check_type_single"
fill_in "item[in_edges][][value]", with: "answer1"
click_on I18n.t("ss.buttons.save")
end
expect(page).to have_css('#notice', text: I18n.t('ss.notice.saved'))

expect(page).to have_css("#addon-basic", text: "modify")
expect(page).to have_css("#addon-guide-agents-addons-question", text: I18n.t("guide.options.question_type.choices"))
end

it "#delete" do
visit delete_path
within "form" do
click_on I18n.t("ss.buttons.delete")
end
expect(page).to have_css('#notice', text: I18n.t('ss.notice.deleted'))
end
end
end

0 comments on commit a295dbb

Please sign in to comment.