[deploy] Use Javascript to Display Jobs Banner (#8303)
* Use Javascript to Display Jobs Banner * one equal is enough * stub SiteConfig values * Return banner for all searches containing jobs, ensure banner is always at top, remove old job partial * check for query before executing function
This commit is contained in:
parent
7285320824
commit
ee3792f447
5 changed files with 53 additions and 5 deletions
|
|
@ -90,7 +90,11 @@ class SearchController < ApplicationController
|
|||
feed_content_search
|
||||
end
|
||||
|
||||
render json: { result: feed_docs }
|
||||
render json: {
|
||||
result: feed_docs,
|
||||
display_jobs_banner: SiteConfig.display_jobs_banner,
|
||||
jobs_url: SiteConfig.jobs_url
|
||||
}
|
||||
end
|
||||
|
||||
def reactions
|
||||
|
|
|
|||
|
|
@ -59,6 +59,14 @@
|
|||
}
|
||||
}
|
||||
|
||||
function addOptionalBanner(query, displayBanner, jobsUrl) {
|
||||
var lowerCaseQuery = query.toLowerCase();
|
||||
|
||||
if (displayBanner && lowerCaseQuery.includes("job")) {
|
||||
document.getElementById("banner-section").innerHTML = '<div class="crayons-notice crayons-notice--info mb-3 fs-base">Interested in joining our team? Explore our <a href=' + jobsUrl + '>open roles</a>.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
function search(query, filters) {
|
||||
var hashtags = query.match(/#\w+/g);
|
||||
var searchTerm = query.replace(/#/g, '').trim();
|
||||
|
|
@ -109,6 +117,10 @@
|
|||
})
|
||||
.then(response => response.json())
|
||||
.then((content) => {
|
||||
if (searchHash["search_fields"]) {
|
||||
addOptionalBanner(searchHash["search_fields"], content.display_jobs_banner, content.jobs_url);
|
||||
}
|
||||
|
||||
var resultDivs = []
|
||||
content.result.forEach(function (story, i) {
|
||||
resultDivs.push(buildArticleHTML(story));
|
||||
|
|
|
|||
|
|
@ -9,9 +9,7 @@
|
|||
data-articles-since="<%= Timeframer.new(params[:timeframe]).datetime&.iso8601 %>">
|
||||
<%= render "articles/search/sidebar" %>
|
||||
<div class="articles-list" id="articles-list">
|
||||
<% if (params[:q]&.downcase == "job" || params[:q]&.downcase == "jobs") && SiteConfig.display_jobs_banner %>
|
||||
<div class="crayons-notice crayons-notice--info mb-3 fs-base">Interested in joining our team? Explore our <a href=<%= SiteConfig.jobs_url %>>open roles</a>.</div>
|
||||
<% end %>
|
||||
<div id="banner-section"></div>
|
||||
<div class="substories" id="substories">
|
||||
<div class="query-results-nothing">
|
||||
<div class="query-results-loader"></div>
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ RSpec.describe "Search", type: :request, proper_status: true do
|
|||
)
|
||||
|
||||
get "/search/feed_content"
|
||||
expect(response.parsed_body).to eq("result" => mock_documents)
|
||||
expect(response.parsed_body["result"]).to eq(mock_documents)
|
||||
end
|
||||
|
||||
it "queries only the user index if class_name=User" do
|
||||
|
|
|
|||
34
spec/system/search/display_jobs_banner_spec.rb
Normal file
34
spec/system/search/display_jobs_banner_spec.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Display Jobs Banner spec", type: :system, js: true do
|
||||
before do
|
||||
stub_request(:post, "http://www.google-analytics.com/collect")
|
||||
allow(SiteConfig).to receive(:jobs_url).and_return("www.very_cool_jobs_website.com")
|
||||
end
|
||||
|
||||
context "when SiteConfig.display_jobs_banner is false" do
|
||||
it "does not show jobs banner" do
|
||||
allow(SiteConfig).to receive(:display_jobs_banner).and_return(false)
|
||||
visit "/search?q=jobs"
|
||||
|
||||
expect(page).not_to have_content("Interested in joining our team?")
|
||||
end
|
||||
end
|
||||
|
||||
context "when SiteConfig.display_jobs_banner is true" do
|
||||
before { allow(SiteConfig).to receive(:display_jobs_banner).and_return(true) }
|
||||
|
||||
it "displays job banner for job search" do
|
||||
visit "/search?q=jobs"
|
||||
|
||||
expect(page).to have_content("Interested in joining our team?")
|
||||
expect(find_link("open roles")["href"]).to include(SiteConfig.jobs_url)
|
||||
end
|
||||
|
||||
it "does not display jobs banner for other searches" do
|
||||
visit "/search?q=ruby"
|
||||
|
||||
expect(page).not_to have_content("Interested in joining our team?")
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue