Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions spec/system/contact_types/new_spec.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "contact_types/new", type: :system do
let!(:organization) { create(:casa_org) }
let!(:admin) { create(:casa_admin, casa_org_id: organization.id) }
let!(:admin) { create(:casa_admin, casa_org: organization) }
let!(:contact_type_group) { create(:contact_type_group, casa_org: organization, name: "Contact type group 1") }
let!(:contact_type) { create(:contact_type, name: "Contact type 1") }

before do
sign_in admin

visit new_contact_type_path(contact_type)
visit new_contact_type_path
end

it "errors with invalid name" do
fill_in "Name", with: ""
click_on "Submit"
context "with valid data" do
it "creates contact type successfully" do
fill_in "Name", with: "New Contact Type test"
click_on "Submit"

expect(page).to have_text("Name can't be blank")
expect(page).to have_text("Contact Type was successfully created.")
end
end

it "creates with valid data" do
fill_in "Name", with: "New Contact Type test"
click_on "Submit"
context "with invalid data" do
it "shows error when name is blank" do
fill_in "Name", with: ""
click_on "Submit"

expect(page).to have_text("Name can't be blank")
end

it "shows error when name is not unique within group" do
create(:contact_type, name: "Existing Name", contact_type_group:)

fill_in "Name", with: "Existing Name"
select "Contact type group 1", from: "contact_type_contact_type_group_id"
click_on "Submit"

expect(page).to have_text("Contact Type was successfully created.")
expect(page).to have_text("Name should be unique per contact type group")
end
end
end