Skip to content

Commit

Permalink
spec
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGorbanev committed Jun 22, 2019
1 parent 131b5e4 commit e11022c
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 7 deletions.
8 changes: 7 additions & 1 deletion apps/web/views/vacancies/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def subscribe_form # rubocop:disable Metrics/MethodLength

def remote_filter_button(text:, remote_value:)
link_params =
if remote_value == params[:remote]
if remote_value == current_remote_query
{ class: 'btn btn-light active' }
else
{
Expand All @@ -54,6 +54,12 @@ def remote_filter_button(text:, remote_value:)
html.span { text }
end
end

private

def current_remote_query
params[:remote] if ['true', 'false'].include?(params[:remote])
end
end
end
end
Expand Down
11 changes: 9 additions & 2 deletions spec/core/queries/vacancy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
let(:repo) { described_class.new }

describe '#all_with_contact' do
subject { repo.all_with_contact(limit: 10, page: 1) }
subject { repo.all_with_contact(limit: 10, page: 1, remote_available: remote_available) }

before { Fabricate.create(:vacancy, published: published, archived: archived, deleted_at: deleted_at) }
let(:remote_available) { nil }

before { Fabricate.create(:vacancy, published: published, archived: archived, deleted_at: deleted_at, remote_available: false) }

context 'when vacancy published and not archived or deleted' do
let(:published) { true }
Expand All @@ -16,6 +18,11 @@
it { expect(subject.count).to eq(1) }
it { expect(subject).to all(be_a(Vacancy)) }
it { expect(subject.first.contact).to be_a(Contact) }

context 'when remote_available is true' do
let(:remote_available) { true }
it { expect(subject).to eq([]) }
end
end

context 'when vacancy published and archived' do
Expand Down
50 changes: 50 additions & 0 deletions spec/vacancies/operations/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,56 @@
it { expect(subject.value!).to eq(result: [], pager: pager) }
end

context 'with remote query' do
let(:vacancies) { [] }

subject { operation.call(remote_query: remote_query) }

context 'when remote_query nil' do
let(:remote_query) { nil }

it do
expect(vacancy_query)
.to receive(:all_with_contact)
.with(limit: 10, page: 1, remote_available: nil)
subject
end
end

context 'when remote_query not true or false string' do
let(:remote_query) { 'not true or false string' }

it do
expect(vacancy_query)
.to receive(:all_with_contact)
.with(limit: 10, page: 1, remote_available: nil)
subject
end
end

context 'when remote_query true' do
let(:remote_query) { 'true' }

it do
expect(vacancy_query)
.to receive(:all_with_contact)
.with(limit: 10, page: 1, remote_available: true)
subject
end
end

context 'when remote_query false' do
let(:remote_query) { 'false' }

it do
expect(vacancy_query)
.to receive(:all_with_contact)
.with(limit: 10, page: 1, remote_available: false)
subject
end
end
end

context 'with real dependencies' do
subject { operation.call }

Expand Down
10 changes: 7 additions & 3 deletions spec/web/controllers/vacancies/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
expect(action.pager).to eq(pager)
end

context 'when params inlcludes query param' do
let(:params) { { query: 'remote:true search text' } }
context 'when params includes query param' do
let(:params) { { query: 'remote:true search text', remote: 'remote_query' } }

it { expect(subject).to be_success }

it do
expect(operation).to receive(:call).with(page: nil, search_query: { remote: 'true', text: 'search text' })
expect(operation).to receive(:call).with(
page: nil,
search_query: { remote: 'true', text: 'search text' },
remote_query: 'remote_query'
)
subject
end
end
Expand Down
65 changes: 64 additions & 1 deletion spec/web/views/vacancies/index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,75 @@
# frozen_string_literal: true

RSpec.describe Web::Views::Vacancies::Index, type: :view do
let(:exposures) { Hash[format: :html] }
let(:params) { Hash[] }
let(:exposures) { Hash[format: :html, flash: {}, vacancies: [], params: params] }
let(:template) { Hanami::View::Template.new('apps/web/templates/vacancies/index.html.slim') }
let(:view) { described_class.new(template, exposures) }
let(:rendered) { view.render }

it 'exposes #format' do
expect(view.format).to eq exposures.fetch(:format)
end

describe 'remote radiobuttons' do
let(:rendered) { without_indentation(view.render) }

before { allow(view).to receive(:pagination) }

it do
expect(rendered).to include without_indentation <<~HTML
<div class="btn-group btn-group-toggle">
<a class="btn btn-light active"><span>Любые</span></a>
<a class="btn btn-light" href="/?remote=true"><span>Удаленные</span></a>
<a class="btn btn-light" href="/?remote=false"><span>В офисе</span></a>
</div>
HTML
end

context 'when remote is true' do
let(:params) { Hash[remote: 'true'] }

it do
expect(rendered).to include without_indentation <<~HTML
<div class="btn-group btn-group-toggle">
<a class="btn btn-light" href="/"><span>Любые</span></a>
<a class="btn btn-light active"><span>Удаленные</span></a>
<a class="btn btn-light" href="/?remote=false"><span>В офисе</span></a>
</div>
HTML
end
end

context 'when remote is false' do
let(:params) { Hash[remote: 'false'] }

it do
expect(rendered).to include without_indentation <<~HTML
<div class="btn-group btn-group-toggle">
<a class="btn btn-light" href="/"><span>Любые</span></a>
<a class="btn btn-light" href="/?remote=true"><span>Удаленные</span></a>
<a class="btn btn-light active"><span>В офисе</span></a>
</div>
HTML
end
end

context 'when remote is not valid' do
let(:params) { Hash[remote: 'foo'] }

it do
expect(rendered).to include without_indentation <<~HTML
<div class="btn-group btn-group-toggle">
<a class="btn btn-light active"><span>Любые</span></a>
<a class="btn btn-light" href="/?remote=true"><span>Удаленные</span></a>
<a class="btn btn-light" href="/?remote=false"><span>В офисе</span></a>
</div>
HTML
end
end
end

def without_indentation(string)
string.strip.gsub("\n", '')
end
end

0 comments on commit e11022c

Please sign in to comment.