Skip to content

Commit

Permalink
Merge pull request #266 from ita-social-projects/ZER-173-testing-of-n…
Browse files Browse the repository at this point in the history
…avigation-admin-menu

ZER-173: testing of navigation admin menu
  • Loading branch information
irakova1 authored Sep 15, 2022
2 parents a0d1fb5 + 8cb43ea commit aee56b2
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 27 deletions.
8 changes: 8 additions & 0 deletions spec/factories/feature_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 0 additions & 21 deletions spec/features/admin/navigator_spec.rb

This file was deleted.

2 changes: 2 additions & 0 deletions spec/features/admin/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
40 changes: 40 additions & 0 deletions spec/features/navigator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require 'rails_helper'

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
6 changes: 4 additions & 2 deletions spec/features/sign_out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
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
fill_in 'Password', with: user.password
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
4 changes: 3 additions & 1 deletion spec/features/visit_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions spec/features/visit_login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit aee56b2

Please sign in to comment.