|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require 'spec_helper' |
| 4 | +require "solidus_admin/testing_support/shared_examples/moveable" |
4 | 5 |
|
5 | 6 | describe "Product", type: :feature do |
6 | 7 | before do |
|
52 | 53 | expect(page).to have_content("Name can't be blank") |
53 | 54 | expect(page).to be_axe_clean |
54 | 55 | end |
| 56 | + |
| 57 | + describe "option types", :js do |
| 58 | + before do |
| 59 | + create(:option_type, name: "clothing-size", presentation: "Size").tap do |option_type| |
| 60 | + option_type.option_values << [ |
| 61 | + create(:option_value, name: "S", presentation: "Small"), |
| 62 | + create(:option_value, name: "M", presentation: "Medium") |
| 63 | + ] |
| 64 | + end |
| 65 | + |
| 66 | + create(:option_type, name: "clothing-color", presentation: "Color").tap do |option_type| |
| 67 | + option_type.option_values << [ |
| 68 | + create(:option_value, name: "brown", presentation: "Brown"), |
| 69 | + create(:option_value, name: "red", presentation: "Red") |
| 70 | + ] |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + let!(:product) { create(:product, name: "Just a product", slug: 'just-a-prod', price: 19.99) } |
| 75 | + |
| 76 | + it "updates option types" do |
| 77 | + visit "/admin/products/just-a-prod" |
| 78 | + solidus_select(%w[clothing-size:Size clothing-color:Color], from: "Option Types") |
| 79 | + options_panel = panel(title: "Options") |
| 80 | + # for some reason capybara on circle ci does not register a form submit when clicking "Save" within options panel, |
| 81 | + # so we have to resort to Save button in the header |
| 82 | + within("header") { click_on "Save" } |
| 83 | + |
| 84 | + expect(options_panel).to have_content("clothing-size:Size") |
| 85 | + expect(options_panel).to have_content("S:Small") |
| 86 | + expect(options_panel).to have_content("M:Medium") |
| 87 | + expect(options_panel).to have_content("clothing-color:Color") |
| 88 | + expect(options_panel).to have_content("brown:Brown") |
| 89 | + expect(options_panel).to have_content("red:Red") |
| 90 | + |
| 91 | + solidus_unselect(%w[clothing-size:Size clothing-color:Color], from: "Option Types") |
| 92 | + within(options_panel) { click_on "Save" } |
| 93 | + |
| 94 | + expect(options_panel).not_to have_content("clothing-size:Size") |
| 95 | + expect(options_panel).not_to have_content("S:Small") |
| 96 | + expect(options_panel).not_to have_content("M:Medium") |
| 97 | + expect(options_panel).not_to have_content("clothing-color:Color") |
| 98 | + expect(options_panel).not_to have_content("brown:Brown") |
| 99 | + expect(options_panel).not_to have_content("red:Red") |
| 100 | + end |
| 101 | + |
| 102 | + context "clicking on Edit" do |
| 103 | + # skipping test until updated option types UI is merged |
| 104 | + # https://github.com/solidusio/solidus/pull/6236 |
| 105 | + xit "leads to option type edit page" do |
| 106 | + option_type = create(:option_type) |
| 107 | + product.option_types << option_type |
| 108 | + visit "/admin/products/just-a-prod" |
| 109 | + |
| 110 | + within(panel(title: "Options")) { click_on "Edit" } |
| 111 | + expect(page).to have_current_path("/admin/option_types/#{option_type.id}/edit") |
| 112 | + end |
| 113 | + end |
| 114 | + |
| 115 | + context "clicking on Manage option types" do |
| 116 | + it "leads to option types index page" do |
| 117 | + visit "/admin/products/just-a-prod" |
| 118 | + |
| 119 | + within(panel(title: "Options")) { click_on "Manage option types" } |
| 120 | + expect(page).to have_current_path("/admin/option_types") |
| 121 | + end |
| 122 | + end |
| 123 | + |
| 124 | + it_behaves_like "features: sortable" do |
| 125 | + let(:product) { create(:product) } |
| 126 | + let(:factory) { :option_type } |
| 127 | + let(:factory_attrs) { { products: [product] } } |
| 128 | + let(:displayed_attribute) { :name } |
| 129 | + let(:handle) { ".handle" } |
| 130 | + let(:path) { solidus_admin.product_path(product) } |
| 131 | + end |
| 132 | + end |
55 | 133 | end |
0 commit comments