Files
old-holivud2/spec/features/user_manages_contract_templates_spec.rb
2020-07-06 13:30:10 +02:00

359 lines
13 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.feature 'User manages contract templates', type: :feature do
let(:current_user) { create(:user, :manager) }
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
let(:project2) { create(:project, members: current_user, account: current_user.primary_account, name: 'New project') }
before do
sign_in(current_user)
end
scenario 'splash page is shown if tehre are no contract templates' do
visit project_contract_templates_path(project)
expect(page).to have_content schedule_demo
expect(page).to have_content create_release_template
end
scenario 'creating a new release template' do
visit new_project_contract_template_path(project)
fill_in 'Name', with: 'My Release Template'
select 'Appearance Release', from: 'Release type'
fill_in_trix body_field, with: 'You agree to this release.'
fill_hidden guardian_clause_field, with: 'Your minor agrees to this release.'
select 'All', from: 'Applicable Media'
select 'Other', from: 'Territory'
fill_in 'Describe other territory', with: 'North America only'
select 'In perpetuity', from: 'Term'
select 'None', from: 'Restriction'
click_on 'Create Release Template'
expect(page).to have_content(create_contract_template_success_message)
end
scenario 'creating new release template, all release types accept signature legal text' do
all_release_types = ['Acquired Media', 'Appearance', 'Location', 'Material', 'Medical', 'Misc', 'Talent']
all_release_types.each do |release_type|
visit new_project_contract_template_path(project)
dropdown_selection = "#{release_type} Release"
select dropdown_selection, from: 'Release type'
fill_in 'Name', with: "My #{release_type} template"
fill_in_trix signature_legal_text_field, with: 'LL'
expect do
click_on 'Create Release Template'
end.to change(ContractTemplate, :count).by(1)
end
end
scenario 'medical release template has a guardian clause field' do
visit new_project_contract_template_path(project)
fill_in 'Name', with: 'My Release Template'
select 'Medical Release', from: 'Release type'
fill_hidden guardian_clause_field, with: 'Guardian clause text'
click_on 'Create Release Template'
expect(page).to have_content(create_contract_template_success_message)
expect(ContractTemplate.last.guardian_clause.body.to_s).to match /Guardian clause text/
end
scenario 'misc release templates has guardian clause and questionnaire', js: true do
visit new_project_contract_template_path(project)
fill_in 'Name', with: 'My Misc Release'
select 'Misc Release', from: 'Release type'
expect(page).to have_selector('label', text: 'Guardian Clause')
MiscRelease::NUMBER_OF_CUSTOM_FIELDS.times do |n|
expect(page).to have_field(question_field(n+1))
end
fill_in_trix 'contract_template_guardian_clause', with: 'Guardian clause text'
fill_in question_field(1), with: 'How much experience do you have in the industry?'
click_on 'Create Release Template'
expect(page).to have_content(create_contract_template_success_message)
end
scenario 'preview new talent release template without guardian clause' do
visit new_project_contract_template_path(project)
select 'Talent Release', from: 'Release type'
click_on 'Preview'
expect(content_type).to eq('application/pdf')
expect(content_disposition).to include('inline')
expect(pdf_body).to have_content('PREVIEW ONLY')
expect(pdf_body).to have_content('Talent Release')
expect(pdf_body).to have_content('Body text goes here')
expect(pdf_body).to have_content('Guardian')
end
scenario 'preview new talent release template with guardian clause' do
visit new_project_contract_template_path(project)
select 'Talent Release', from: 'Release type'
fill_hidden guardian_clause_field, with: 'Your minor agrees to this release.'
click_on 'Preview'
expect(content_type).to eq('application/pdf')
expect(content_disposition).to include('inline')
expect(pdf_body).to have_content('PREVIEW ONLY')
expect(pdf_body).to have_content('Talent Release')
expect(pdf_body).to have_content('Body text goes here')
expect(pdf_body).to have_content('Guardian')
expect(pdf_body).to have_content('Your minor')
end
scenario 'preview new appearance release template without guardian clause' do
visit new_project_contract_template_path(project)
select 'Appearance Release', from: 'Release type'
click_on 'Preview'
expect(content_type).to eq('application/pdf')
expect(content_disposition).to include('inline')
expect(pdf_body).to have_content('PREVIEW ONLY')
expect(pdf_body).to have_content('Appearance Release')
expect(pdf_body).to have_content('Body text goes here')
expect(pdf_body).to have_content('Guardian')
end
scenario 'preview new appearance release template with guardian clause' do
visit new_project_contract_template_path(project)
select 'Appearance Release', from: 'Release type'
fill_hidden guardian_clause_field, with: 'Your minor agrees to this release.'
click_on 'Preview'
expect(content_type).to eq('application/pdf')
expect(content_disposition).to include('inline')
expect(pdf_body).to have_content('PREVIEW ONLY')
expect(pdf_body).to have_content('Appearance Release')
expect(pdf_body).to have_content('Body text goes here')
expect(pdf_body).to have_content('Guardian')
expect(pdf_body).to have_content('Your minor')
end
scenario 'different release type generates different pdf' do
visit new_project_contract_template_path(project)
select 'Acquired Media Release', from: 'Release type'
click_on 'Preview'
expect(content_type).to eq('application/pdf')
expect(content_disposition).to include('inline')
expect(pdf_body).to have_content('PREVIEW ONLY')
expect(pdf_body).to have_content('Acquired Media Release')
expect(pdf_body).not_to have_content('Guardian')
visit new_project_contract_template_path(project)
select 'Location Release', from: 'Release type'
click_on 'Preview'
expect(content_type).to eq('application/pdf')
expect(content_disposition).to include('inline')
expect(pdf_body).to have_content('PREVIEW ONLY')
expect(pdf_body).to have_content('Location Release')
expect(pdf_body).not_to have_content('Guardian')
visit new_project_contract_template_path(project)
select 'Material Release', from: 'Release type'
click_on 'Preview'
expect(content_type).to eq('application/pdf')
expect(content_disposition).to include('inline')
expect(pdf_body).to have_content('PREVIEW ONLY')
expect(pdf_body).to have_content('Material Release')
expect(pdf_body).not_to have_content('Guardian')
end
context 'preventing creation of release template with wrong fee value' do
before do
visit new_project_contract_template_path(project)
fill_in 'Name', with: 'My Release Template'
select 'Appearance Release', from: 'Release type'
fill_in_trix body_field, with: 'You agree to this release.'
fill_hidden guardian_clause_field, with: 'Your minor agrees to this release.'
select 'All', from: 'Applicable Media'
select 'Other', from: 'Territory'
fill_in 'Describe other territory', with: 'North America only'
select 'In perpetuity', from: 'Term'
select 'None', from: 'Restriction'
end
scenario 'Should not allow negative fees' do
fill_in 'Fee', with: '-200'
click_on 'Create Release Template'
expect(page).not_to have_content(create_contract_template_success_message)
end
scenario 'Should not allow fees with more than 9 digits' do
fill_in 'Fee', with: '9999999999'
click_on 'Create Release Template'
expect(page).not_to have_content(create_contract_template_success_message)
end
end
scenario 'contract template preview is shown before printing' do
create(:appearance_release_contract_template, body: 'Contract legal language', project: project)
visit project_contract_templates_path(project)
click_on 'Manage'
expect(page).to have_content('Print')
click_link 'Print'
expect(page).to have_content preview_heading
expect(page).to have_selector 'embed'
end
scenario 'printing blank release template' do
create(:appearance_release_contract_template, body: 'Contract legal language', project: project)
visit project_contract_templates_path(project)
click_on 'Manage'
expect(page).to have_content('Print')
click_link 'Print'
fill_in 'Number of copies', with: '-1'
click_on t('shared.print')
expect(page).to have_content(t('contract_templates.blank_contracts.create.number_of_copies_invalid_notice'))
fill_in 'Number of copies', with: 2
click_on t('shared.print')
expect(content_type).to eq('application/pdf')
expect(content_disposition).to include('inline')
expect(pdf_body).to have_content('Contract legal language', count: 2)
expect(pdf_body).to have_content('Appearance Release', count: 2)
expect(pdf_body).to have_content('Name: _____', count: 4) #2 times for person name and 2 times for guardian name
expect(pdf_body).to have_content(t 'blank_contracts.pdf.do_not_copy_warning', count: 2)
end
scenario 'archiving an existing release template', js: true do
create(:contract_template, project: project)
visit project_contract_templates_path(project)
expect(page).to have_content('Test template')
click_on 'Manage'
accept_alert do
click_on 'Archive'
end
expect(page).to have_content('The release template has been archived')
expect(page).not_to have_content('Test template')
end
scenario 'archived contract templates from other projects are not shown when importing contract templates' do
create(:contract_template, :archived, project: project2, name: 'Archived template')
create(:contract_template, project: project2, name: 'Active template')
create(:contract_template, project: project)
visit project_contract_templates_path(project)
expect(page).to have_content('Test template')
click_on import_template_button
expect(page).not_to have_content('Test template')
expect(page).not_to have_content('Archived template')
expect(page).to have_content('Active template')
end
context 'When the user is associate' do
let(:current_user) { create(:user, :associate) }
it 'does not show management buttons for release templates' do
create(:contract_template, project: project)
visit project_contract_templates_path(project)
expect(page).not_to have_content('Create New Release Template')
expect(page).not_to have_content(import_template_button)
expect(page).not_to have_content('Delete')
end
it 'does not show create release button on splash page' do
visit project_contract_templates_path(project)
expect(page).to have_content schedule_demo
expect(page).not_to have_content create_release_template
end
end
context 'When the user is account manager' do
let(:current_user) { create(:user, :account_manager) }
it 'shows archive button for release template' do
create(:contract_template, project: project)
visit project_contract_templates_path(project)
click_on 'Manage'
expect(page).to have_content('Archive')
end
it 'does not show create release button on splash page' do
visit project_contract_templates_path(project)
expect(page).to have_content schedule_demo
expect(page).to have_content create_release_template
end
end
private
def import_template_button
t 'contract_templates.index.actions.import'
end
def import_selected_templates_button
t 'release_template_imports.new.actions.import'
end
def preview_heading
t 'blank_contracts.new.preview_heading'
end
def fill_in_trix(id, with:)
find("trix-editor##{id}").click.set(with)
end
def body_field
'contract_template_body'
end
def guardian_clause_field
'contract_template_guardian_clause_trix_input_contract_template'
end
def signature_legal_text_field
'contract_template_signature_legal_text'
end
def create_contract_template_success_message
'The release template has been created'
end
def question_field(n)
"Question #{n} text"
end
def fill_hidden(id, with:)
find(:xpath, "//input[@id='#{id}']", visible: false).set with
end
def schedule_demo
t 'contract_templates.splash.actions.book_demo'
end
def create_release_template
t 'contract_templates.splash.actions.create_template'
end
def signature_legal_text_trix_field
'Signature legal text'
end
end