Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
233 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require 'rails_helper' | ||
|
||
describe 'Add program:', :js do | ||
Given(:user) { create(:person)} | ||
Given(:activities) { %w[program:index] } | ||
Given(:new_program_link_selector) { "a.btn-success[href=\"#{new_program_path}\"]" } | ||
|
||
Given { user.roles << create(:role, activities: activities) } | ||
Given { login_as(user) } | ||
|
||
When { visit programs_path } | ||
|
||
describe 'without rights' do | ||
describe 'link navigation' do | ||
Then { expect(page).not_to have_selector(new_program_link_selector) } | ||
end | ||
|
||
describe 'direct navigation' do | ||
When { visit new_program_path } | ||
|
||
Then { expect(find('.alert-dismissible')).to have_content(I18n.t('not_authorized')) } | ||
And { expect(current_path).not_to eq(new_program_path) } | ||
end | ||
end | ||
|
||
describe 'with rights to view form' do | ||
Given(:activities) { %w[program:index program:new] } | ||
|
||
describe 'navigates to the page directly' do | ||
When { visit new_program_path } | ||
|
||
Then { expect(current_path).to eq(new_program_path) } | ||
end | ||
|
||
describe 'does not allow to create' do | ||
When { find(new_program_link_selector).click } | ||
When { click_button I18n.t('programs.new.submit') } | ||
|
||
Then { expect(find('.alert-dismissible')).to have_content(I18n.t('not_authorized')) } | ||
And { expect(current_path).to eq(new_program_path) } | ||
end | ||
end | ||
|
||
describe 'with rights to create' do | ||
Given(:activities) { %w[program:index program:new program:create] } | ||
|
||
describe 'creates the program' do | ||
When { find(new_program_link_selector).click } | ||
When { fill_program_data manager: user } | ||
When { click_button I18n.t('programs.new.submit') } | ||
|
||
Then { expect(current_path).to eq(programs_path) } | ||
And { expect(page).to have_selector('.alert-notice') } | ||
end | ||
end | ||
|
||
def fill_program_data(params = {}) | ||
program = build_stubbed(:program, params) | ||
|
||
fill_in 'program_title_uk', with: program.title_uk | ||
fill_in 'program_title_ru', with: program.title_ru | ||
fill_in 'program_description_uk', with: program.description_uk | ||
fill_in 'program_description_ru', with: program.description_ru | ||
|
||
visibility_label = I18n.t("simple_form.options.program.visible.#{program.visible ? 'visible' : 'invisible' }") | ||
|
||
select visibility_label, from: 'program_visible' | ||
|
||
select2_single('program_manager', program.manager.complex_name) | ||
|
||
program | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'rails_helper' | ||
|
||
describe 'Delete program:', :js do | ||
Given!(:program) { create(:program) } | ||
Given(:user) { create(:person)} | ||
Given(:activities) { %w[program:index] } | ||
Given(:delete_program_link_selector) { "a.btn-danger" } | ||
|
||
Given { user.roles << create(:role, activities: activities) } | ||
Given { login_as(user) } | ||
|
||
When { visit programs_path } | ||
|
||
describe 'without rights' do | ||
Then { expect(page).not_to have_selector(delete_program_link_selector) } | ||
end | ||
|
||
describe 'with rights but with study application' do | ||
Given(:activities) { %w[program:index program:destroy] } | ||
Given(:student) { create(:person, :student) } | ||
|
||
Given { StudyApplication.create(person_id: student.id, program_id: program.id) } | ||
|
||
Then { expect(find('tbody tr:nth-child(1) td:nth-child(3)')).to have_content('1') } | ||
And { expect(find('tbody tr:nth-child(1) td:nth-child(7)')).to have_selector('a.btn-danger.disabled') } | ||
end | ||
|
||
describe 'with rights to destroy' do | ||
Given(:activities) { %w[program:index program:destroy] } | ||
Given(:program_title) { program["title_#{user.locale}"] } | ||
|
||
describe 'dismiss_confirm' do | ||
When { dismiss_confirm { find(delete_program_link_selector).click } } | ||
|
||
Then { expect(find('tbody tr:nth-child(1) td:nth-child(1)')).to have_content(program_title) } | ||
end | ||
|
||
describe 'accept_confirm' do | ||
When { accept_confirm { find(delete_program_link_selector).click } } | ||
|
||
Then { expect(page).not_to have_selector('tbody tr') } | ||
And { expect(current_path).to eq(programs_path) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require 'rails_helper' | ||
|
||
describe 'Update program:', :js do | ||
Given!(:program) { create(:program) } | ||
Given(:user) { create(:person)} | ||
Given(:activities) { %w[program:index] } | ||
Given(:edit_path) { edit_program_path(program.id) } | ||
Given(:edit_program_link_selector) { "a.btn-warning[href=\"#{edit_path}\"]" } | ||
|
||
Given { user.roles << create(:role, activities: activities) } | ||
Given { login_as(user) } | ||
|
||
When { visit programs_path } | ||
|
||
describe 'without rights' do | ||
describe 'link navigation' do | ||
Then { expect(page).not_to have_selector(edit_program_link_selector) } | ||
end | ||
|
||
describe 'direct navigation' do | ||
When { visit edit_path } | ||
|
||
Then { expect(find('.alert-dismissible')).to have_content(I18n.t('not_authorized')) } | ||
And { expect(current_path).not_to eq(edit_path) } | ||
end | ||
end | ||
|
||
describe 'with rights to view form' do | ||
Given(:activities) { %w[program:index program:edit] } | ||
|
||
describe 'navigates to the page directly' do | ||
When { visit edit_path } | ||
|
||
Then { expect(current_path).to eq(edit_path) } | ||
end | ||
|
||
describe 'does not allow to save' do | ||
When { find(edit_program_link_selector).click } | ||
When { click_button I18n.t('programs.edit.submit') } | ||
|
||
Then { expect(find('.alert-dismissible')).to have_content(I18n.t('not_authorized')) } | ||
And { expect(current_path).to eq(edit_path) } | ||
end | ||
end | ||
|
||
describe 'with rights to create' do | ||
Given(:activities) { %w[program:index program:edit program:update] } | ||
Given(:title_id) { "program_title_#{user.locale}"} | ||
Given(:new_title_value) { 'Some title here' } | ||
|
||
describe 'check the state of unmodified fields' do | ||
Then { expect(find('tbody tr:nth-child(1) td:nth-child(1)')).not_to have_content(new_title_value) } | ||
And { expect(find('tbody tr:nth-child(1) td:nth-child(6)')).to have_content('0') } | ||
And { expect(current_path).to eq(programs_path) } | ||
end | ||
|
||
describe 'updates the program' do | ||
Given(:questionnaire_title_field) { "title_#{user.locale}" } | ||
Given!(:questionnaire_1) { create(:questionnaire) } | ||
Given!(:questionnaire_2) { create(:questionnaire) } | ||
|
||
When { find(edit_program_link_selector).click } | ||
When { fill_in title_id, with: new_title_value } | ||
When { select2_multi('program_questionnaires', questionnaire_1[questionnaire_title_field]) } | ||
When { select2_multi('program_questionnaires', questionnaire_2[questionnaire_title_field]) } | ||
When { click_button I18n.t('programs.edit.submit') } | ||
|
||
Then { expect(current_path).to eq(programs_path) } | ||
And { expect(page).to have_selector('.alert-notice') } | ||
Then { expect(find('tbody tr:nth-child(1) td:nth-child(1)')).to have_content(new_title_value) } | ||
And { expect(find('tbody tr:nth-child(1) td:nth-child(6)')).to have_content('2') } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters