|
5 | 5 | describe "Stores", :js, type: :feature do |
6 | 6 | before { sign_in create(:admin_user, email: 'admin@example.com') } |
7 | 7 |
|
8 | | - it "lists stores and allows deleting them" do |
9 | | - create(:store, name: "B2C Store") |
10 | | - create(:store, name: "B2B Store") |
11 | | - |
12 | | - visit "/admin/stores" |
13 | | - expect(page).to have_content("B2C Store") |
14 | | - expect(page).to have_content("B2B Store") |
15 | | - expect(page).to be_axe_clean |
16 | | - |
17 | | - select_row("B2C Store") |
18 | | - click_on "Delete" |
19 | | - expect(page).to have_content("Stores were successfully removed.") |
20 | | - expect(page).not_to have_content("B2C Store") |
21 | | - expect(Spree::Store.count).to eq(1) |
22 | | - expect(page).to be_axe_clean |
| 8 | + describe "index page" do |
| 9 | + before do |
| 10 | + create(:store, name: "B2C Store") |
| 11 | + create(:store, name: "B2B Store", default: true) |
| 12 | + visit "/admin/stores" |
| 13 | + expect(page).to have_content("B2C Store") |
| 14 | + expect(page).to have_content("B2B Store") |
| 15 | + expect(page).to be_axe_clean |
| 16 | + end |
| 17 | + |
| 18 | + it "lists stores and allows deleting them" do |
| 19 | + select_row("B2C Store") |
| 20 | + |
| 21 | + accept_confirm("Are you sure you want to delete 1 store?") do |
| 22 | + click_button("Delete") |
| 23 | + end |
| 24 | + |
| 25 | + expect(page).to have_content("Stores were successfully removed.") |
| 26 | + expect(page).not_to have_content("B2C Store") |
| 27 | + expect(page).to be_axe_clean |
| 28 | + end |
| 29 | + |
| 30 | + it "does not allow to delete default store" do |
| 31 | + select_row("B2B Store") |
| 32 | + |
| 33 | + accept_confirm("Are you sure you want to delete 1 store?") do |
| 34 | + click_button("Delete") |
| 35 | + end |
| 36 | + |
| 37 | + expect(page).not_to have_content("Stores were successfully removed.") |
| 38 | + expect(page).to have_content("B2B Store") |
| 39 | + expect(page).to have_content("Some Stores could not be removed") |
| 40 | + expect(page).to have_content("B2B Store: Cannot destroy the default Store") |
| 41 | + expect(page).to be_axe_clean |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + describe "creating new store" do |
| 46 | + before do |
| 47 | + visit "/admin/stores" |
| 48 | + click_on "Add new" |
| 49 | + expect(page).to be_axe_clean |
| 50 | + end |
| 51 | + |
| 52 | + context "with valid form" do |
| 53 | + it "saves store" do |
| 54 | + fill_in "Store Name", with: "New Store" |
| 55 | + fill_in "Slug", with: "new-store" |
| 56 | + fill_in "URL", with: "www.new-store.com" |
| 57 | + fill_in "Store Email", with: "mail@new-stores.com" |
| 58 | + |
| 59 | + within("header") { click_on "Save" } |
| 60 | + |
| 61 | + expect(page).to have_content("Store was successfully created") |
| 62 | + expect(page).to have_content("New Store") |
| 63 | + expect(page).to have_content("new-store") |
| 64 | + expect(page).to have_content("www.new-store.com") |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + context "with invalid form" do |
| 69 | + it "saves store" do |
| 70 | + within("header") { click_on "Save" } |
| 71 | + |
| 72 | + expect(page).to have_content("can't be blank", count: 4) |
| 73 | + end |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + describe "editing existing store" do |
| 78 | + before do |
| 79 | + create(:store, |
| 80 | + name: "B2C Store", |
| 81 | + default_currency: "GBP", |
| 82 | + cart_tax_country_iso: create(:country, iso: "GB").iso, |
| 83 | + available_locales: %w[en]) |
| 84 | + |
| 85 | + create(:country, iso: "US") |
| 86 | + visit "/admin/stores" |
| 87 | + click_on "B2C Store" |
| 88 | + expect(page).to be_axe_clean |
| 89 | + end |
| 90 | + |
| 91 | + it "updates store" do |
| 92 | + expect(solidus_select_control("Default Currency")).to have_content("GBP") |
| 93 | + expect(solidus_select_control("Tax Country")).to have_content("United Kingdom") |
| 94 | + expect(solidus_select_control("Storefront Languages")).to have_content("English (US)") |
| 95 | + |
| 96 | + fill_in "Store Name", with: "Updated Store" |
| 97 | + fill_in "Slug", with: "updated-store" |
| 98 | + fill_in "URL", with: "www.updated-store.com" |
| 99 | + fill_in "Store Email", with: "updated-mail@new-stores.com" |
| 100 | + solidus_select("USD", from: "Default Currency") |
| 101 | + solidus_select("United States", from: "Tax Country") |
| 102 | + |
| 103 | + within("header") { click_on "Save" } |
| 104 | + |
| 105 | + expect(page).to have_content("Store was successfully updated") |
| 106 | + expect(page).to have_content("Updated Store") |
| 107 | + expect(page).to have_content("updated-store") |
| 108 | + expect(page).to have_content("www.updated-store.com") |
| 109 | + |
| 110 | + click_on "Updated Store" |
| 111 | + expect(solidus_select_control("Default Currency")).to have_content("USD") |
| 112 | + expect(solidus_select_control("Tax Country")).to have_content("United States") |
| 113 | + end |
| 114 | + end |
| 115 | + |
| 116 | + describe "clicking Discard" do |
| 117 | + it "redirects back to index" do |
| 118 | + visit "/admin/stores" |
| 119 | + click_on "Add new" |
| 120 | + click_on "Discard" |
| 121 | + expect(page).to have_current_path("/admin/stores") |
| 122 | + end |
23 | 123 | end |
24 | 124 | end |
0 commit comments