From 1be1d161d33e5310646d28daee92de14c8f7a21e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 18 Mar 2021 09:39:20 +0100 Subject: [PATCH] Add tests about unit price inside a shopfront - Test that the unit price wrapper is here - Click on the question mark icon and display the tooltip - Click outside the question mark icon and hide the toolip --- .../consumer/shopping/unit_price_spec.rb | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 spec/features/consumer/shopping/unit_price_spec.rb diff --git a/spec/features/consumer/shopping/unit_price_spec.rb b/spec/features/consumer/shopping/unit_price_spec.rb new file mode 100644 index 0000000000..262d966cfb --- /dev/null +++ b/spec/features/consumer/shopping/unit_price_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +feature "As a consumer, I want to check unit price information for a product", js: true do + include AuthenticationHelper + include WebHelper + include ShopWorkflow + include UIComponentHelper + + let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } + let(:supplier) { create(:supplier_enterprise) } + let(:oc1) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now) } + let(:product) { create(:simple_product, supplier: supplier) } + let(:variant) { product.variants.first } + let(:order) { create(:order, distributor: distributor) } + let(:exchange1) { oc1.exchanges.to_enterprises(distributor).outgoing.first } + let(:user) { create(:user, password: "password", password_confirmation: "password") } + + before do + set_order order + exchange1.update_attribute :pickup_time, "monday" + add_variant_to_order_cycle(exchange1, variant) + allow(OpenFoodNetwork::FeatureToggle) + .to receive(:enabled?).with(:unit_price, anything) { true } + end + + describe "for the shopfront" do + before do + visit shop_path + end + + it "one click on the question mark icon should open the tooltip, another click should close it" do + expect(page).to have_selector '.variant-unit-price' + within '.variant-unit-price' do + expect(page).to have_selector '.question-mark-icon' + end + find('.question-mark-icon').click + expect(page).to have_selector '.joyride-tip-guide.question-mark-tooltip' + within '.joyride-tip-guide.question-mark-tooltip' do + expect(page).to have_content I18n.t('js.shopfront.unit_price_tooltip') + end + + page.find("body").click + expect(page).not_to have_selector '.joyride-tip-guide.question-mark-tooltip' + expect(page).to have_no_content I18n.t('js.shopfront.unit_price_tooltip') + end + + end +end