From 6dd14bf98dfddff54c7a6eb55be6f1e48e8dc020 Mon Sep 17 00:00:00 2001 From: Iryna Koval Date: Wed, 14 Sep 2022 23:24:48 +0300 Subject: [PATCH 1/2] Added traits in FactoryBot, tested navigator and corrected other feature tests --- spec/factories/feature_flags.rb | 8 +++++ spec/features/admin/navigator_spec.rb | 21 ------------- spec/features/admin/users_spec.rb | 2 ++ spec/features/navigator_spec.rb | 42 ++++++++++++++++++++++++++ spec/features/sign_out_spec.rb | 6 ++-- spec/features/visit_calculator_spec.rb | 4 ++- spec/features/visit_login_spec.rb | 7 +++-- 7 files changed, 63 insertions(+), 27 deletions(-) delete mode 100644 spec/features/admin/navigator_spec.rb create mode 100644 spec/features/navigator_spec.rb diff --git a/spec/factories/feature_flags.rb b/spec/factories/feature_flags.rb index e8fe9c7e4..11e5046a6 100644 --- a/spec/factories/feature_flags.rb +++ b/spec/factories/feature_flags.rb @@ -4,5 +4,13 @@ factory :feature_flag do name { 'FeatureFlag' } enabled { false } + trait :show_admin_menu do + name { 'show_admin_menu' } + enabled { true } + end + trait :hide_admin_menu do + name { 'show_admin_menu' } + enabled { false } + end end end diff --git a/spec/features/admin/navigator_spec.rb b/spec/features/admin/navigator_spec.rb deleted file mode 100644 index fc4d9be2d..000000000 --- a/spec/features/admin/navigator_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rails_helper' - - RSpec.feature 'Link Contacts', type: :feature do - describe 'contacts on entry page', js: true do - context 'when follow the link' do - before do - visit root_path - end - - xit 'is not valid without a css style' do - expect(page).to have_css('.page-header') - expect(page).to have_css('.tabs') - end - - xit 'is not valid without a link' do - expect(page).not_to have_link('Contacts') - click_link('Contacts', href: 'https://zerowastelviv.org.ua/en/contacts/') - end - end - end - end diff --git a/spec/features/admin/users_spec.rb b/spec/features/admin/users_spec.rb index 01b897dd8..0c843329d 100644 --- a/spec/features/admin/users_spec.rb +++ b/spec/features/admin/users_spec.rb @@ -26,6 +26,7 @@ visit USERS_PATH within(:css, "#user-info-#{user1.id}") do click_link(href: "/admins/users/#{user1.id}") + sleep 3 end expect(page).to have_current_path('/admins/users/1') expect(page).to have_content 'Email' @@ -43,6 +44,7 @@ visit USERS_PATH within(:css, "#user-info-#{user1.id}") do click_link(href: "/admins/users/#{user1.id}/edit") + sleep 3 end expect(page).to have_current_path(EDIT_USERS_PATH) expect(page).to have_content 'First name' diff --git a/spec/features/navigator_spec.rb b/spec/features/navigator_spec.rb new file mode 100644 index 000000000..a3f2ea115 --- /dev/null +++ b/spec/features/navigator_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'rails_helper' +require 'pry' + + +describe 'navigator', js: true do + it 'should style the navbar' do + visit root_path + expect(page).to have_css('.page-header') + expect(page.body).to have_css('.tabs') + end + + context 'when feature show_admin_menu does not exist' do + it 'should not consist tabs' do + visit root_path + expect(page).not_to have_content("SIGN UP") + expect(page).not_to have_content("LOG IN") + expect(page).not_to have_content("CONTACT US") + end + end + + context 'when feature show_admin_menu is disabled' do + it 'should not consist tabs' do + create(:feature_flag, :hide_admin_menu) + visit root_path + expect(page).not_to have_content("SIGN UP") + expect(page).not_to have_content("LOG IN") + expect(page).not_to have_content("CONTACT US") + end + end + + context 'when feature show_admin_menu is enabled' do + it 'should consist tabs' do + create(:feature_flag, :show_admin_menu) + visit root_path + expect(page).to have_content("SIGN UP") + expect(page).to have_content("LOG IN") + expect(page).to have_content("CONTACT US") + end + end +end diff --git a/spec/features/sign_out_spec.rb b/spec/features/sign_out_spec.rb index 798fa35c3..36efc562e 100644 --- a/spec/features/sign_out_spec.rb +++ b/spec/features/sign_out_spec.rb @@ -8,6 +8,7 @@ let(:calculator) { create(:calculator) } flash_message_disappear_time = 20 before do + create(:feature_flag, :show_admin_menu) allow_any_instance_of(ApplicationController).to receive(:after_sign_in_path_for).and_return("/calculators/#{calculator.slug}") visit '/users/sign_in' fill_in 'Email', with: user.email @@ -15,11 +16,12 @@ click_button 'Log in' Capybara.using_wait_time flash_message_disappear_time do click_link 'Log Out' + sleep 3 end end - xit "signs the user out" do + it "signs the user out" do expect(page).to have_current_path("/calculators/#{calculator.slug}") - expect(page).to have_selector("a[href='/users/sign_in']") + expect(page).to have_content("LOG IN") end end diff --git a/spec/features/visit_calculator_spec.rb b/spec/features/visit_calculator_spec.rb index f8b81557a..cb1bc8689 100644 --- a/spec/features/visit_calculator_spec.rb +++ b/spec/features/visit_calculator_spec.rb @@ -12,9 +12,11 @@ end - xit "visits calculator page and open log_in page" do + it "visits calculator page and open log_in page" do + create(:feature_flag, :show_admin_menu) visit "/calculators/#{calculator.slug}" click_link ('Log In') + sleep 3 expect(page).to have_content 'Forgot your password' end end diff --git a/spec/features/visit_login_spec.rb b/spec/features/visit_login_spec.rb index 8a97ce209..56ed6b78a 100644 --- a/spec/features/visit_login_spec.rb +++ b/spec/features/visit_login_spec.rb @@ -6,17 +6,18 @@ let(:user) { create(:user) } let(:calculator) { create(:calculator) } - xit 'when sign in with correct login and password' do + it 'when sign in with correct login and password' do allow_any_instance_of(ApplicationController) .to receive(:after_sign_in_path_for) .and_return("/calculators/#{calculator.slug}") allow(Devise::Mailer).to receive(:confirmation_instructions) .and_return(double(deliver: true)) + create(:feature_flag, :show_admin_menu) visit '/users/sign_in' fill_in 'Email', with: user.email fill_in 'Password', with: user.password click_button 'Log in' - expect(page).to have_content 'Signed in successfully' - expect(page).to have_selector("a[href='/users/sign_out']") + expect(page).to have_content('Signed in successfully') + expect(page).to have_content('LOG OUT') end end From 8cb43ea86d36b638ac75d4f0903deb3a340ecc30 Mon Sep 17 00:00:00 2001 From: Iryna Koval Date: Thu, 15 Sep 2022 11:24:55 +0300 Subject: [PATCH 2/2] Removed unnecessary line. --- spec/features/navigator_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/features/navigator_spec.rb b/spec/features/navigator_spec.rb index a3f2ea115..5d824c974 100644 --- a/spec/features/navigator_spec.rb +++ b/spec/features/navigator_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true require 'rails_helper' -require 'pry' - describe 'navigator', js: true do it 'should style the navbar' do