Files
old-holivud2/spec/features/user_managing_misc_releases_spec.rb
2020-09-13 20:09:48 +02:00

243 lines
8.3 KiB
Ruby

require "rails_helper"
feature "User managing misc releases" do
let(:current_user) { create(:user) }
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context 'when signed out' do
scenario 'creating a release for an adult', js: true do
project = create(:project, members: current_user, account: current_user.primary_account)
contract_template = create(:misc_release_contract_template,
question_1_text: "Question 1",
project: project)
visit new_account_project_contract_template_misc_release_path(project.account, project, contract_template)
expect(page).to have_content("QUESTIONNAIRE")
fill_in person_first_name_field, with: 'Jane'
fill_in person_last_name_field, with: 'Doe'
fill_in_person_address_fields
fill_in person_phone_field, with: '555-555-5555'
fill_in person_email_field, with: 'jane.doe@test.com'
fill_in question_1_field, with: "Answer 1"
drop_file Rails.root.join(file_fixture("person_photo.png")), type: :dropzone
draw_signature file_fixture("signature.png"), "misc_release_signature_base64"
expect do
click_button submit_release_button
end.to change(MiscRelease, :count).by(1)
expect(page).to have_content(successful_submission_message)
end
scenario "creating a release for a minor - guardian fields are required when minor checkbox is checked", js: true do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_misc_release_path(project.account, project, contract_template)
all('input[data-required-tag="guardian"]').each do |field|
expect(field['required']).to eq 'false'
expect(field).not_to be_visible
end
page.check person_is_minor_checkbox
all('input[data-required-tag="guardian"]').each do |field|
expect(field['required']).to eq 'true'
expect(field).to be_visible
end
end
scenario "creating a release, if contract template contains signature legal language, it is shown" do
contract_template = create(:contract_template, project: project, signature_legal_text: dummy_signature_legal_text)
visit new_account_project_contract_template_misc_release_path(project.account, project, contract_template)
expect(page).to have_content dummy_signature_legal_text
end
end
context "when signed in as account manager" do
before do
sign_in current_user
end
scenario "Download is visible" do
create(:misc_release_with_contract_template, :native, project: project)
visit project_misc_releases_path(project)
expect(page).to have_content download_button
end
scenario "Downloading PDF of native misc release is possible" do
native_release = create(:misc_release_with_contract_template, :native, project: project)
visit project_misc_releases_path(project)
click_link *view_release_pdf_link_for(native_release)
expect(content_type).to eq('application/pdf')
end
scenario 'viewing the contract PDF with questionnaire' do
misc_release = create(:misc_release,
:native,
contract_template: build(:misc_release_contract_template, question_1_text: 'Q1'),
question_1_answer: 'A1',
project: project,
person_first_name: 'Jane',
person_last_name: 'Doe',
tag_list: 'Woman, Brunette',
notes: [
build(:note,
content: 'Note 1',
user: build(:user, email: 'jane.doe@test.com'),
email: 'jane.doe@test.com',
created_at: DateTime.new(2020, 2, 21, 12, 0, 0)),
build(:note,
content: 'Note 2',
user: build(:user, email: 'john.doe@test.com'),
email: 'john.doe@test.com',
created_at: DateTime.new(2020, 2, 20, 11, 0, 0))
])
sign_in(current_user)
visit project_misc_releases_path(project)
click_link *view_release_pdf_link_for(misc_release)
expect(content_type).to eq('application/pdf')
expect(content_disposition).to include('inline')
expect(pdf_filename).to include('doe-jane')
expect(pdf_body).to have_content('Jane Doe')
expect(pdf_body).to have_content('NOTES')
expect(pdf_body).to have_content('Note 1')
expect(pdf_body).to have_content('jane.doe@test.com')
expect(pdf_body).to have_content('2/21/20 12:00 PM')
expect(pdf_body).to have_content('Note 2')
expect(pdf_body).to have_content('john.doe@test.com')
expect(pdf_body).to have_content('2/20/20 11:00 AM')
expect(pdf_body).to have_content('TAGS')
expect(pdf_body).to have_content('Woman')
expect(pdf_body).to have_content('Brunette')
expect(pdf_body).not_to have_content('Guardian Email')
expect(pdf_body).to have_content questionnaire_heading.upcase
expect(pdf_body).to have_content('Q1')
expect(pdf_body).to have_content('A1')
end
scenario 'viewing the contract PDF without questionnaire' do
misc_release = create(:misc_release,
:native,
contract_template: build(:misc_release_contract_template),
project: project,
person_first_name: 'Jane',
person_last_name: 'Doe'
)
sign_in(current_user)
visit project_misc_releases_path(project)
click_link *view_release_pdf_link_for(misc_release)
expect(content_type).to eq('application/pdf')
expect(content_disposition).to include('inline')
expect(pdf_filename).to include('doe-jane')
expect(pdf_body).not_to have_content questionnaire_heading.upcase
end
end
context "when the user is manager(project manager)" do
let(:current_user) { create(:user, :manager) }
before do
sign_in current_user
end
scenario "Download action in Manage menu is not visible" do
create(:misc_release_with_contract_template, :native, project: project)
visit project_misc_releases_path(project)
expect(page).to have_link("Download", exact: true, count: 0)
end
end
private
def download_button
'Download'
end
def view_release_pdf_link_for(release)
['Download', href: misc_release_contracts_path(release, format: 'pdf')]
end
def fill_in_person_address_fields
fill_in person_address_street1_field, with: "123 Test Lane"
fill_in person_address_city_field, with: "New York"
fill_in person_address_state_field, with: "NY"
fill_in person_address_zip_field, with: '1000'
end
def person_address_street1_field
t('helpers.label.misc_release.person_address_street1')
end
def person_address_city_field
t('helpers.label.misc_release.person_address_city')
end
def person_address_state_field
t('helpers.label.misc_release.person_address_state')
end
def person_address_zip_field
t('helpers.label.misc_release.person_address_zip')
end
def person_first_name_field
t('helpers.label.misc_release.person_first_name')
end
def person_last_name_field
t('helpers.label.misc_release.person_last_name')
end
def person_email_field
t('helpers.label.misc_release.person_email')
end
def person_phone_field
t('helpers.label.misc_release.person_phone')
end
def question_1_field
'misc_release[question_1_answer]'
end
def submit_release_button
t 'shared.submit_release_long'
end
def successful_submission_message
"Your release was successfully submitted. Thank you."
end
def person_is_minor_checkbox
'misc_release_minor'
end
def dummy_signature_legal_text
'Some signature legal language'
end
def view_release_pdf_link_for(release)
['Download', href: misc_release_contracts_path(release, format: 'pdf')]
end
def questionnaire_heading
t 'contracts.questionnaire.heading.misc_release'
end
end