From 6bec7da9895a151821f806e2ad0c955ce83a07aa Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Wed, 31 Jul 2024 16:43:02 +0200 Subject: [PATCH] add routing and tabbar specs --- config/routes.rb | 9 +++-- spec/features/cv_search_spec.rb | 9 +---- spec/features/routing_spec.rb | 20 ++++++++++ spec/features/tabbar_spec.rb | 71 +++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 spec/features/routing_spec.rb create mode 100644 spec/features/tabbar_spec.rb diff --git a/config/routes.rb b/config/routes.rb index 3ff612dff..1e553ee01 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,6 @@ delete 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_auth_user_session end - get "/:locale", locale: LOCALE_REGEX, to: 'people#index' # Status scope 'status' do @@ -20,8 +19,10 @@ get 'readiness', to: 'status#readiness' end - scope "(:locale)", locale: LOCALE_REGEX do - get root to: 'people#index' + get "/", to: redirect(path: "/people") + + scope "/:locale", locale: LOCALE_REGEX, defaults: {locale: I18n.locale} do + get root to: redirect(path: "/%{locale}/people") resources :skills do collection do @@ -66,6 +67,8 @@ end end end + match '*path', to: redirect("/#{I18n.locale}/%{path}"), :via => [:get, :post] + # Outdated api routes namespace :api do diff --git a/spec/features/cv_search_spec.rb b/spec/features/cv_search_spec.rb index 6d3833444..13abcdd66 100644 --- a/spec/features/cv_search_spec.rb +++ b/spec/features/cv_search_spec.rb @@ -43,14 +43,7 @@ fill_in 'cv_search_field', with: education_location check_search_results(Person.human_attribute_name(:educations)) click_link(Person.human_attribute_name(:educations)) - url = URI.parse(current_url) - path = url.path - query_params = url.query.split("&") - - # expect(path).to eq(person_people_skills_path(person)) - expect(path).to include(person.id.to_s) - - expect(query_params).to include({q: education_location}.to_query) + expect(current_url).to eq(person_path(person, q: education_location)) end it 'should only display results when length of search-text is > 3' do diff --git a/spec/features/routing_spec.rb b/spec/features/routing_spec.rb new file mode 100644 index 000000000..c21057c81 --- /dev/null +++ b/spec/features/routing_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +describe 'Check routes', type: :feature, js: true do + ROUTES = { + "/": "/de/people", + "/de/": "/de/people", + "/people": "/de/people", + "/people_skills": "/de/people_skills" + } + before(:each) do + sign_in auth_users(:user), scope: :auth_user + end + + ROUTES.each do |url, target| + it "Should route from '#{url}' to #{target}" do + visit url + expect(current_path).to eq(target) + end + end +end diff --git a/spec/features/tabbar_spec.rb b/spec/features/tabbar_spec.rb new file mode 100644 index 000000000..445f805ee --- /dev/null +++ b/spec/features/tabbar_spec.rb @@ -0,0 +1,71 @@ +require 'rails_helper' + +describe 'Tabbar', type: :feature, js:true do + let(:bob) { people(:bob) } + + let(:global_tabs){ + [ + { title: t('global.navbar.profile'), path: people_path }, + { title: t('global.navbar.skill_search'), path: people_skills_path }, + { title: t('global.navbar.cv_search'), path: cv_search_index_path }, + { title: t('global.navbar.skillset'), path: skills_path } + ] + } + + let(:person_tabs) { + [ + { title: 'CV', path: person_path(bob) }, + { title: 'Skills', path: person_people_skills_path(bob) } + ] + } + + before(:each) do + sign_in auth_users(:admin) + visit root_path + end + + describe 'Global' do + it 'Should highlight right tab using click' do + global_tabs.each do |hash| + click_link(href: hash[:path]) + check_highlighted_tab(hash[:title]) + end + end + + it 'Should highlight right tab after visit by url' do + global_tabs.each do |hash| + visit (hash[:path]) + check_highlighted_tab(hash[:title]) + end + end + + + def check_highlighted_tab(text) + expect(page).to have_selector("div.skills-navbar .btn .nav-link.active", text: text) + end + end + + describe 'Person' do + + it 'Should highlight right tab using dropdown' do + person_tabs.each do |hash| + visit root_path + select_from_slim_select("#person_id_person", bob.name) + check_highlighted_tab("CV") + click_link(href: hash[:path]) + check_highlighted_tab(hash[:title]) + end + end + + it 'Should highlight right tab after visit by url' do + person_tabs.each do |hash| + visit (hash[:path]) + check_highlighted_tab(hash[:title]) + end + end + + def check_highlighted_tab(text) + expect(page).to have_selector(".nav.nav-tabs .btn .nav-link.active", text: text) + end + end +end