|
| 1 | +# frozen_string_literal: true |
| 2 | + |
1 | 3 | require "rails_helper" |
2 | 4 |
|
3 | 5 | RSpec.describe "contact_types/new", type: :system do |
4 | 6 | let!(:organization) { create(:casa_org) } |
5 | | - let!(:admin) { create(:casa_admin, casa_org_id: organization.id) } |
| 7 | + let!(:admin) { create(:casa_admin, casa_org: organization) } |
6 | 8 | let!(:contact_type_group) { create(:contact_type_group, casa_org: organization, name: "Contact type group 1") } |
7 | | - let!(:contact_type) { create(:contact_type, name: "Contact type 1") } |
8 | 9 |
|
9 | 10 | before do |
10 | 11 | sign_in admin |
11 | | - |
12 | | - visit new_contact_type_path(contact_type) |
| 12 | + visit new_contact_type_path |
13 | 13 | end |
14 | 14 |
|
15 | | - it "errors with invalid name" do |
16 | | - fill_in "Name", with: "" |
17 | | - click_on "Submit" |
| 15 | + context "with valid data" do |
| 16 | + it "creates contact type successfully" do |
| 17 | + fill_in "Name", with: "New Contact Type test" |
| 18 | + click_on "Submit" |
18 | 19 |
|
19 | | - expect(page).to have_text("Name can't be blank") |
| 20 | + expect(page).to have_text("Contact Type was successfully created.") |
| 21 | + end |
20 | 22 | end |
21 | 23 |
|
22 | | - it "creates with valid data" do |
23 | | - fill_in "Name", with: "New Contact Type test" |
24 | | - click_on "Submit" |
| 24 | + context "with invalid data" do |
| 25 | + it "shows error when name is blank" do |
| 26 | + fill_in "Name", with: "" |
| 27 | + click_on "Submit" |
| 28 | + |
| 29 | + expect(page).to have_text("Name can't be blank") |
| 30 | + end |
| 31 | + |
| 32 | + it "shows error when name is not unique within group" do |
| 33 | + create(:contact_type, name: "Existing Name", contact_type_group:) |
| 34 | + |
| 35 | + fill_in "Name", with: "Existing Name" |
| 36 | + select "Contact type group 1", from: "contact_type_contact_type_group_id" |
| 37 | + click_on "Submit" |
25 | 38 |
|
26 | | - expect(page).to have_text("Contact Type was successfully created.") |
| 39 | + expect(page).to have_text("Name should be unique per contact type group") |
| 40 | + end |
27 | 41 | end |
28 | 42 | end |
0 commit comments