add signing form specs
This commit is contained in:
committed by
Pete Matsyburka
parent
6d5c6e086d
commit
18d60f5522
@@ -5,7 +5,6 @@ FactoryBot.define do
|
||||
submission
|
||||
email { Faker::Internet.email }
|
||||
name { Faker::Name.name }
|
||||
phone { Faker::PhoneNumber.phone_number }
|
||||
|
||||
before(:create) do |submitter, _|
|
||||
submitter.account_id = submitter.submission.account_id
|
||||
|
||||
+273
-9
@@ -9,9 +9,13 @@ FactoryBot.define do
|
||||
|
||||
transient do
|
||||
submitter_count { 1 }
|
||||
only_field_types do
|
||||
%w[text date checkbox radio signature number multiple select initials image file stamp cells phone payment]
|
||||
end
|
||||
except_field_types { [] }
|
||||
end
|
||||
|
||||
after(:create) do |template, evaluator|
|
||||
after(:create) do |template, ev|
|
||||
blob = ActiveStorage::Blob.create_and_upload!(
|
||||
io: Rails.root.join('spec/fixtures/sample-document.pdf').open,
|
||||
filename: 'sample-document.pdf',
|
||||
@@ -28,7 +32,7 @@ FactoryBot.define do
|
||||
template.schema = [{ attachment_uuid: attachment.uuid, name: 'sample-document' }]
|
||||
number_words = %w[first second third fourth fifth sixth seventh eighth ninth tenth]
|
||||
|
||||
template.submitters = Array.new(evaluator.submitter_count) do |i|
|
||||
template.submitters = Array.new(ev.submitter_count) do |i|
|
||||
{
|
||||
'name' => "#{number_words[i]&.capitalize} Party",
|
||||
'uuid' => SecureRandom.uuid
|
||||
@@ -43,12 +47,13 @@ FactoryBot.define do
|
||||
'name' => 'First Name',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'preferences' => {},
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.09027777777777778,
|
||||
'y' => 0.1197252208047105,
|
||||
'w' => 0.3069444444444444,
|
||||
'h' => 0.03336604514229637,
|
||||
'x' => 0.09273546006944444,
|
||||
'y' => 0.1099851117387033,
|
||||
'w' => 0.2701497395833333,
|
||||
'h' => 0.0372705365913556,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
@@ -57,12 +62,271 @@ FactoryBot.define do
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => '',
|
||||
'name' => 'Birthday',
|
||||
'type' => 'date',
|
||||
'required' => true,
|
||||
'preferences' => { 'format' => 'DD/MM/YYYY' },
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.09166666666666666,
|
||||
'y' => 0.1762778204144282,
|
||||
'w' => 0.2763888888888889,
|
||||
'h' => 0.0359029261474578,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'Do you agree?',
|
||||
'type' => 'checkbox',
|
||||
'required' => true,
|
||||
'preferences' => {},
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.09051106770833334,
|
||||
'y' => 0.227587027259332,
|
||||
'w' => 0.2784450954861111,
|
||||
'h' => 0.04113074042239687,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'First child',
|
||||
'type' => 'radio',
|
||||
'required' => true,
|
||||
'preferences' => {},
|
||||
'options' => [
|
||||
{ 'value' => 'Girl', 'uuid' => SecureRandom.uuid },
|
||||
{ 'value' => 'Boy', 'uuid' => SecureRandom.uuid }
|
||||
],
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.09027777777777778,
|
||||
'y' => 0.3020184190330008,
|
||||
'w' => 0.2,
|
||||
'h' => 0.02857142857142857,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'Signature',
|
||||
'type' => 'signature',
|
||||
'required' => true,
|
||||
'areas' => []
|
||||
'preferences' => {},
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.08611111111111111,
|
||||
'y' => 0.3487183422870299,
|
||||
'w' => 0.2,
|
||||
'h' => 0.0707269155206287,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'House number',
|
||||
'type' => 'number',
|
||||
'required' => true,
|
||||
'preferences' => {},
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.08333333333333333,
|
||||
'y' => 0.4582041442824252,
|
||||
'w' => 0.2,
|
||||
'h' => 0.02857142857142857,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'Colors',
|
||||
'type' => 'multiple',
|
||||
'required' => true,
|
||||
'preferences' => {},
|
||||
'options' => [
|
||||
{ 'value' => 'Red', 'uuid' => SecureRandom.uuid },
|
||||
{ 'value' => 'Green', 'uuid' => SecureRandom.uuid },
|
||||
{ 'value' => 'Blue', 'uuid' => SecureRandom.uuid }
|
||||
],
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.45,
|
||||
'y' => 0.1133998465080583,
|
||||
'w' => 0.2,
|
||||
'h' => 0.02857142857142857,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'Gender',
|
||||
'type' => 'select',
|
||||
'required' => true,
|
||||
'preferences' => {},
|
||||
'options' => [
|
||||
{ 'value' => 'Male', 'uuid' => SecureRandom.uuid },
|
||||
{ 'value' => 'Female', 'uuid' => SecureRandom.uuid }
|
||||
],
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.4513888888888889,
|
||||
'y' => 0.1752954719877206,
|
||||
'w' => 0.2,
|
||||
'h' => 0.02857142857142857,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'Initials',
|
||||
'type' => 'initials',
|
||||
'required' => true,
|
||||
'preferences' => {},
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.4486111111111111,
|
||||
'y' => 0.2273599386032233,
|
||||
'w' => 0.1,
|
||||
'h' => 0.02857142857142857,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'Avatar',
|
||||
'type' => 'image',
|
||||
'required' => true,
|
||||
'preferences' => {},
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.7180555555555556,
|
||||
'y' => 0.1129547198772064,
|
||||
'w' => 0.2,
|
||||
'h' => 0.1414538310412574,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'Attachment',
|
||||
'type' => 'file',
|
||||
'required' => true,
|
||||
'preferences' => {},
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.7166666666666667,
|
||||
'y' => 0.3020107444359171,
|
||||
'w' => 0.2,
|
||||
'h' => 0.02857142857142857,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'Stamp',
|
||||
'type' => 'stamp',
|
||||
'required' => true,
|
||||
'readonly' => true,
|
||||
'preferences' => {},
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.7166666666666667,
|
||||
'y' => 0.3771910974673829,
|
||||
'w' => 0.2,
|
||||
'h' => 0.0707269155206287,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'Cell code',
|
||||
'type' => 'cells',
|
||||
'required' => true,
|
||||
'preferences' => {},
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.4472222222222222,
|
||||
'y' => 0.3530851880276286,
|
||||
'w' => 0.2,
|
||||
'h' => 0.02857142857142857,
|
||||
'cell_w' => 0.04,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'Payment',
|
||||
'type' => 'payment',
|
||||
'required' => true,
|
||||
'preferences' => { 'currency' => 'EUR', 'price' => 1000 },
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.4486111111111111,
|
||||
'y' => 0.43168073676132,
|
||||
'w' => 0.2,
|
||||
'h' => 0.02857142857142857,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => SecureRandom.uuid,
|
||||
'submitter_uuid' => submitter['uuid'],
|
||||
'name' => 'Mobile Phone',
|
||||
'type' => 'phone',
|
||||
'required' => true,
|
||||
'preferences' => {},
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.44443359375,
|
||||
'y' => 0.3010283960092095,
|
||||
'w' => 0.2,
|
||||
'h' => 0.02857142857142857,
|
||||
'attachment_uuid' => attachment.uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
].select { |f| ev.only_field_types.include?(f['type']) && ev.except_field_types.exclude?(f['type']) }
|
||||
|
||||
fields
|
||||
end
|
||||
|
||||
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 129 KiB |
@@ -10,6 +10,7 @@ require 'capybara/cuprite'
|
||||
require 'capybara/rspec'
|
||||
require 'webmock/rspec'
|
||||
require 'sidekiq/testing'
|
||||
require 'signing_form_helper'
|
||||
|
||||
Sidekiq::Testing.fake!
|
||||
|
||||
@@ -50,6 +51,7 @@ RSpec.configure do |config|
|
||||
|
||||
config.include FactoryBot::Syntax::Methods
|
||||
config.include Devise::Test::IntegrationHelpers
|
||||
config.include SigningFormHelper
|
||||
|
||||
config.before(:each, type: :system) do
|
||||
if ENV['HEADLESS'] == 'false'
|
||||
|
||||
@@ -176,33 +176,7 @@ describe 'Templates API', type: :request do
|
||||
id: template.id,
|
||||
slug: template.slug,
|
||||
name: template.name,
|
||||
fields: [
|
||||
{
|
||||
'uuid' => template.fields[0]['uuid'],
|
||||
'submitter_uuid' => template.submitters[0]['uuid'],
|
||||
'name' => 'First Name',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'areas' => [
|
||||
{
|
||||
'x' => 0.09027777777777778,
|
||||
'y' => 0.1197252208047105,
|
||||
'w' => 0.3069444444444444,
|
||||
'h' => 0.03336604514229637,
|
||||
'attachment_uuid' => template_attachment_uuid,
|
||||
'page' => 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'uuid' => template.fields[1]['uuid'],
|
||||
'submitter_uuid' => template.submitters[0]['uuid'],
|
||||
'name' => '',
|
||||
'type' => 'signature',
|
||||
'required' => true,
|
||||
'areas' => []
|
||||
}
|
||||
],
|
||||
fields: template.fields,
|
||||
submitters: [
|
||||
{
|
||||
name: 'First Party',
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module SigningFormHelper
|
||||
module_function
|
||||
|
||||
def draw_canvas
|
||||
page.find('canvas').click([], { x: 150, y: 100 })
|
||||
page.execute_script <<~JS
|
||||
const canvas = document.getElementsByTagName('canvas')[0];
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(150, 100);
|
||||
ctx.lineTo(450, 100);
|
||||
ctx.stroke();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(150, 100);
|
||||
ctx.lineTo(150, 150);
|
||||
ctx.stroke();
|
||||
JS
|
||||
sleep 1
|
||||
end
|
||||
|
||||
def field_value(submitter, field_name)
|
||||
field = template_field(submitter.template, field_name)
|
||||
|
||||
submitter.values[field['uuid']]
|
||||
end
|
||||
|
||||
def template_field(template, field_name)
|
||||
template.fields.find { |f| f['name'] == field_name || f['title'] == field_name } || {}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,598 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Signing Form', type: :system do
|
||||
let(:account) { create(:account) }
|
||||
let(:author) { create(:user, account:) }
|
||||
|
||||
context 'when the template form link is opened' do
|
||||
let(:template) { create(:template, account:, author:, except_field_types: %w[phone payment stamp]) }
|
||||
|
||||
before do
|
||||
visit start_form_path(slug: template.slug)
|
||||
end
|
||||
|
||||
it 'shows the email step', type: :system do
|
||||
expect(page).to have_content('You have been invited to submit a form')
|
||||
expect(page).to have_content("Invited by #{account.name}")
|
||||
expect(page).to have_field('Email', type: 'email')
|
||||
expect(page).to have_button('Start')
|
||||
end
|
||||
|
||||
it 'completes the form' do
|
||||
# Submit's email step
|
||||
fill_in 'Email', with: 'john.dou@example.com'
|
||||
click_button 'Start'
|
||||
|
||||
# Text step
|
||||
fill_in 'First Name', with: 'John'
|
||||
click_button 'next'
|
||||
|
||||
# Date step
|
||||
fill_in 'Birthday', with: I18n.l(20.years.ago, format: '%Y-%m-%d')
|
||||
click_button 'next'
|
||||
|
||||
# Checkbox step
|
||||
check 'Do you agree?'
|
||||
click_button 'next'
|
||||
|
||||
# Radio step
|
||||
choose 'Boy'
|
||||
click_button 'next'
|
||||
|
||||
# Signature step
|
||||
draw_canvas
|
||||
click_button 'next'
|
||||
|
||||
# Number step
|
||||
fill_in 'House number', with: '123'
|
||||
click_button 'next'
|
||||
|
||||
# Multiple choice step
|
||||
%w[Red Blue].each { |color| check color }
|
||||
click_button 'next'
|
||||
|
||||
# Select step
|
||||
select 'Male', from: 'Gender'
|
||||
click_button 'next'
|
||||
|
||||
# Initials step
|
||||
draw_canvas
|
||||
click_button 'next'
|
||||
|
||||
# Image step
|
||||
find('#dropzone').click
|
||||
find('input[type="file"]', visible: false).attach_file(Rails.root.join('spec/fixtures/sample-image.png'))
|
||||
click_button 'next'
|
||||
|
||||
# File step
|
||||
find('#dropzone').click
|
||||
find('input[type="file"]', visible: false).attach_file(Rails.root.join('spec/fixtures/sample-document.pdf'))
|
||||
click_button 'next'
|
||||
|
||||
# Cell step
|
||||
fill_in 'Cell code', with: '123'
|
||||
click_on 'Complete'
|
||||
|
||||
expect(page).to have_button('Download')
|
||||
expect(page).to have_content('Document has been signed!')
|
||||
|
||||
submitter = template.submissions.last.submitters.last
|
||||
|
||||
expect(submitter.email).to eq('john.dou@example.com')
|
||||
expect(submitter.ip).to eq('127.0.0.1')
|
||||
expect(submitter.ua).to be_present
|
||||
expect(submitter.opened_at).to be_present
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(submitter.declined_at).to be_nil
|
||||
|
||||
expect(field_value(submitter, 'First Name')).to eq 'John'
|
||||
expect(field_value(submitter, 'Birthday')).to eq 20.years.ago.strftime('%Y-%m-%d')
|
||||
expect(field_value(submitter, 'Do you agree?')).to be_truthy
|
||||
expect(field_value(submitter, 'First child')).to eq 'Boy'
|
||||
expect(field_value(submitter, 'Signature')).to be_present
|
||||
expect(field_value(submitter, 'House number')).to eq 123
|
||||
expect(field_value(submitter, 'Colors')).to contain_exactly('Red', 'Blue')
|
||||
expect(field_value(submitter, 'Gender')).to eq 'Male'
|
||||
expect(field_value(submitter, 'Initials')).to be_present
|
||||
expect(field_value(submitter, 'Avatar')).to be_present
|
||||
expect(field_value(submitter, 'Attachment')).to be_present
|
||||
expect(field_value(submitter, 'Cell code')).to eq '123'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the submitter form link is opened' do
|
||||
let(:template) { create(:template, account:, author:, except_field_types: %w[phone payment stamp]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:, email: 'robin@example.com')
|
||||
end
|
||||
|
||||
before do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
end
|
||||
|
||||
it 'complete the form' do
|
||||
# Text step
|
||||
fill_in 'First Name', with: 'John'
|
||||
click_button 'next'
|
||||
|
||||
# Date step
|
||||
fill_in 'Birthday', with: I18n.l(20.years.ago, format: '%Y-%m-%d')
|
||||
click_button 'next'
|
||||
|
||||
# Checkbox step
|
||||
check 'Do you agree?'
|
||||
click_button 'next'
|
||||
|
||||
# Radio step
|
||||
choose 'Boy'
|
||||
click_button 'next'
|
||||
|
||||
# Signature step
|
||||
draw_canvas
|
||||
click_button 'next'
|
||||
|
||||
# Number step
|
||||
fill_in 'House number', with: '123'
|
||||
click_button 'next'
|
||||
|
||||
# Multiple choice step
|
||||
%w[Red Blue].each { |color| check color }
|
||||
click_button 'next'
|
||||
|
||||
# Select step
|
||||
select 'Male', from: 'Gender'
|
||||
click_button 'next'
|
||||
|
||||
# Initials step
|
||||
draw_canvas
|
||||
click_button 'next'
|
||||
|
||||
# Image step
|
||||
find('#dropzone').click
|
||||
find('input[type="file"]', visible: false).attach_file(Rails.root.join('spec/fixtures/sample-image.png'))
|
||||
click_button 'next'
|
||||
|
||||
# File step
|
||||
find('#dropzone').click
|
||||
find('input[type="file"]', visible: false).attach_file(Rails.root.join('spec/fixtures/sample-document.pdf'))
|
||||
click_button 'next'
|
||||
|
||||
# Cell step
|
||||
fill_in 'Cell code', with: '123'
|
||||
click_on 'Complete'
|
||||
|
||||
expect(page).to have_button('Download')
|
||||
expect(page).to have_content('Document has been signed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.email).to eq 'robin@example.com'
|
||||
expect(submitter.ip).to eq('127.0.0.1')
|
||||
expect(submitter.ua).to be_present
|
||||
expect(submitter.opened_at).to be_present
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(submitter.declined_at).to be_nil
|
||||
|
||||
expect(field_value(submitter, 'First Name')).to eq 'John'
|
||||
expect(field_value(submitter, 'Birthday')).to eq 20.years.ago.strftime('%Y-%m-%d')
|
||||
expect(field_value(submitter, 'Do you agree?')).to be_truthy
|
||||
expect(field_value(submitter, 'First child')).to eq 'Boy'
|
||||
expect(field_value(submitter, 'Signature')).to be_present
|
||||
expect(field_value(submitter, 'House number')).to eq 123
|
||||
expect(field_value(submitter, 'Colors')).to contain_exactly('Red', 'Blue')
|
||||
expect(field_value(submitter, 'Gender')).to eq 'Male'
|
||||
expect(field_value(submitter, 'Initials')).to be_present
|
||||
expect(field_value(submitter, 'Avatar')).to be_present
|
||||
expect(field_value(submitter, 'Attachment')).to be_present
|
||||
expect(field_value(submitter, 'Cell code')).to eq '123'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the text step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[text]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the field is filled' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
input = find_field('First Name')
|
||||
|
||||
expect(input[:required]).to be_truthy
|
||||
expect(input[:placeholder]).to eq 'Type here...'
|
||||
|
||||
fill_in 'First Name', with: 'Mary'
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'First Name')).to eq 'Mary'
|
||||
end
|
||||
|
||||
it 'toggle multiple text button' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
input = find_field('First Name')
|
||||
|
||||
expect(input.tag_name).to eq('input')
|
||||
|
||||
find(:css, 'div[data-tip="Toggle Multiline Text"]').click
|
||||
|
||||
input = find_field('First Name')
|
||||
|
||||
expect(input.tag_name).to eq('textarea')
|
||||
expect(page).not_to have_selector(:css, 'div[data-tip="Toggle Multiline Text"]')
|
||||
|
||||
fill_in 'First Name', with: 'Very long text'
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(field_value(submitter, 'First Name')).to eq 'Very long text'
|
||||
expect(submitter.completed_at).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the date step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[date]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the field is filled' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
input = find_field('Birthday')
|
||||
|
||||
expect(input[:required]).to be_truthy
|
||||
|
||||
fill_in 'Birthday', with: I18n.l(25.years.ago, format: '%Y-%m-%d')
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Birthday')).to eq 25.years.ago.strftime('%Y-%m-%d')
|
||||
end
|
||||
|
||||
it 'pre-fills the current date into the form field' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
input = find_field('Birthday')
|
||||
|
||||
expect(input[:value]).to eq ''
|
||||
|
||||
click_button 'Set Today'
|
||||
|
||||
input = find_field('Birthday')
|
||||
|
||||
expect(input[:value]).to eq Time.zone.now.strftime('%Y-%m-%d')
|
||||
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Birthday')).to eq Time.zone.now.strftime('%Y-%m-%d')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the checkbox step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[checkbox]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the checkbox is checked' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
check 'Do you agree?'
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Do you agree?')).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the radio step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[radio]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the checkbox is checked' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
%w[Girl Boy].map { |v| find_field(v) }.each { |input| expect(input[:required]).to be_truthy }
|
||||
|
||||
choose 'Boy'
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'First child')).to eq 'Boy'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the signature step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[signature]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the canvas is drawn' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
find('#expand_form_button').click
|
||||
draw_canvas
|
||||
click_button 'Sign and Complete'
|
||||
|
||||
expect(page).to have_content('Document has been signed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Signature')).to be_present
|
||||
end
|
||||
|
||||
it 'completes the form if the canvas is typed' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
find('#expand_form_button').click
|
||||
click_link 'Type'
|
||||
fill_in 'signature_text_input', with: 'John Doe'
|
||||
click_button 'Sign and Complete'
|
||||
|
||||
expect(page).to have_content('Document has been signed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Signature')).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the number step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[number]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the field is filled' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
input = find_field('House number')
|
||||
|
||||
expect(input[:required]).to be_truthy
|
||||
expect(input[:placeholder]).to eq 'Type here...'
|
||||
|
||||
fill_in 'House number', with: '4'
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'House number')).to eq 4
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the multiple choice step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[multiple]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the multiple choice is checked' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
%w[Red Green].each { |color| check color }
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Colors')).to contain_exactly('Red', 'Green')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the select step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[select]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the multiple choice is checked' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
select 'Female', from: 'Gender'
|
||||
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Gender')).to eq 'Female'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the initials step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[initials]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the canvas is typed' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
find('#expand_form_button').click
|
||||
fill_in 'initials_text_input', with: 'John Doe'
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Document has been signed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Initials')).to be_present
|
||||
end
|
||||
|
||||
it 'completes the form if the canvas is drawn' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
find('#expand_form_button').click
|
||||
click_link 'Draw'
|
||||
draw_canvas
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Document has been signed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Initials')).to be_present
|
||||
end
|
||||
|
||||
it 'completes the form if the initials is uploaded' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
find('#expand_form_button').click
|
||||
find('span[data-tip="Click to upload"]').click
|
||||
find('input[type="file"]', visible: false).attach_file(Rails.root.join('spec/fixtures/sample-image.png'))
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Document has been signed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Initials')).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the image step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[image]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the image is uploaded' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
find('#expand_form_button').click
|
||||
find('#dropzone').click
|
||||
find('input[type="file"]', visible: false).attach_file(Rails.root.join('spec/fixtures/sample-image.png'))
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Avatar')).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the file step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[file]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the file is uploaded' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
find('#expand_form_button').click
|
||||
find('#dropzone').click
|
||||
find('input[type="file"]', visible: false).attach_file(Rails.root.join('spec/fixtures/sample-document.pdf'))
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Attachment')).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the cells step' do
|
||||
let(:template) { create(:template, account:, author:, only_field_types: %w[cells]) }
|
||||
let(:submission) { create(:submission, template:) }
|
||||
let(:submitter) do
|
||||
create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
end
|
||||
|
||||
it 'completes the form if the field is filled' do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
input = find_field('Cell code')
|
||||
|
||||
expect(input[:required]).to be_truthy
|
||||
expect(input[:placeholder]).to eq 'Type here...'
|
||||
|
||||
fill_in 'Cell code', with: '456'
|
||||
click_button 'Complete'
|
||||
|
||||
expect(page).to have_content('Form has been completed!')
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(field_value(submitter, 'Cell code')).to eq '456'
|
||||
end
|
||||
end
|
||||
|
||||
it 'sends completed email' do
|
||||
template = create(:template, account:, author:, only_field_types: %w[text signature])
|
||||
submission = create(:submission, template:)
|
||||
submitter = create(:submitter, submission:, uuid: template.submitters.first['uuid'], account:)
|
||||
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
|
||||
fill_in 'First Name', with: 'Adam'
|
||||
click_on 'next'
|
||||
click_link 'Type'
|
||||
fill_in 'signature_text_input', with: 'Adam'
|
||||
|
||||
expect do
|
||||
click_on 'Sign and Complete'
|
||||
end.to change(ProcessSubmitterCompletionJob.jobs, :size).by(1)
|
||||
end
|
||||
end
|
||||
@@ -1,87 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Submit Form' do
|
||||
let(:account) { create(:account) }
|
||||
let(:user) { create(:user, account:) }
|
||||
let(:template) { create(:template, account:, author: user) }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
context 'when initialized by shared link' do
|
||||
before do
|
||||
visit start_form_path(slug: template.slug)
|
||||
end
|
||||
|
||||
it 'shows start form page' do
|
||||
expect(page).to have_content('You have been invited to submit a form')
|
||||
expect(page).to have_content(template.name)
|
||||
expect(page).to have_content("Invited by #{template.account.name}")
|
||||
end
|
||||
|
||||
it 'complete the form' do
|
||||
fill_in 'Email', with: 'john.dou@example.com'
|
||||
click_button 'Start'
|
||||
|
||||
fill_in 'First Name', with: 'Adam'
|
||||
click_on 'next'
|
||||
click_on 'type_text_button'
|
||||
fill_in 'signature_text_input', with: 'Adam'
|
||||
|
||||
expect do
|
||||
click_on 'Sign and Complete'
|
||||
end.not_to(change(Submitter, :count))
|
||||
|
||||
submitter = Submitter.find_by(email: 'john.dou@example.com')
|
||||
|
||||
expect(page).to have_button('Download')
|
||||
expect(submitter.email).to eq('john.dou@example.com')
|
||||
expect(submitter.ip).to eq('127.0.0.1')
|
||||
expect(submitter.ua).to be_present
|
||||
expect(submitter.opened_at).to be_present
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(submitter.values.values).to include('Adam')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when initialized by shared email address' do
|
||||
let(:submission) { create(:submission, template:, created_by_user: user) }
|
||||
let(:submitters) { template.submitters.map { |s| create(:submitter, submission:, uuid: s['uuid']) } }
|
||||
let(:submitter) { submitters.first }
|
||||
|
||||
before do
|
||||
visit submit_form_path(slug: submitter.slug)
|
||||
end
|
||||
|
||||
it 'completes the form' do
|
||||
fill_in 'First Name', with: 'Sally'
|
||||
click_on 'next'
|
||||
click_on 'type_text_button'
|
||||
fill_in 'signature_text_input', with: 'Sally'
|
||||
click_on 'Sign and Complete'
|
||||
|
||||
submitter.reload
|
||||
|
||||
expect(page).to have_button('Download')
|
||||
expect(submitter.ip).to eq('127.0.0.1')
|
||||
expect(submitter.ua).to be_present
|
||||
expect(submitter.opened_at).to be_present
|
||||
expect(submitter.completed_at).to be_present
|
||||
expect(submitter.values.values).to include('Sally')
|
||||
end
|
||||
|
||||
it 'sends completed email' do
|
||||
fill_in 'First Name', with: 'Adam'
|
||||
click_on 'next'
|
||||
click_on 'type_text_button'
|
||||
fill_in 'signature_text_input', with: 'Adam'
|
||||
|
||||
expect do
|
||||
click_on 'Sign and Complete'
|
||||
end.to change(ProcessSubmitterCompletionJob.jobs, :size).by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,7 @@ require 'rails_helper'
|
||||
RSpec.describe 'Template' do
|
||||
let!(:account) { create(:account) }
|
||||
let!(:user) { create(:user, account:) }
|
||||
let!(:template) { create(:template, account:, author: user) }
|
||||
let!(:template) { create(:template, account:, author: user, except_field_types: %w[phone payment]) }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
|
||||
Reference in New Issue
Block a user