mirror of
https://github.com/docusealco/docuseal.git
synced 2026-06-23 04:10:11 +00:00
add builder 'replace' button specs
This commit is contained in:
committed by
Pete Matsyburka
parent
87265e2f22
commit
2dca7d8a8e
@@ -11,6 +11,7 @@ require 'capybara/rspec'
|
||||
require 'webmock/rspec'
|
||||
require 'sidekiq/testing'
|
||||
require 'signing_form_helper'
|
||||
require 'request_helper'
|
||||
|
||||
Sidekiq::Testing.fake!
|
||||
|
||||
@@ -54,6 +55,7 @@ RSpec.configure do |config|
|
||||
config.include FactoryBot::Syntax::Methods
|
||||
config.include Devise::Test::IntegrationHelpers
|
||||
config.include SigningFormHelper
|
||||
config.include RequestHelper
|
||||
|
||||
config.before(:each, type: :system) do
|
||||
if ENV['HEADLESS'] == 'false'
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RequestHelper
|
||||
module_function
|
||||
|
||||
def wait_for_fetch
|
||||
page.execute_script(
|
||||
<<~JS
|
||||
if (!window.fetchInitialized) {
|
||||
window.pendingFetchCount = 0;
|
||||
|
||||
const originalFetch = window.fetch;
|
||||
|
||||
window.fetch = function(...args) {
|
||||
window.pendingFetchCount++;
|
||||
|
||||
return originalFetch.apply(this, args).finally(() => {
|
||||
window.pendingFetchCount--;
|
||||
});
|
||||
};
|
||||
|
||||
window.fetchInitialized = true;
|
||||
}
|
||||
JS
|
||||
)
|
||||
|
||||
yield
|
||||
|
||||
Timeout.timeout(Capybara.default_max_wait_time) do
|
||||
loop do
|
||||
break if page.evaluate_script('window.pendingFetchCount') == 0
|
||||
|
||||
sleep 0.1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Template Builder' do
|
||||
let(:account) { create(:account) }
|
||||
let(:author) { create(:user, account:) }
|
||||
let(:template) { create(:template, account:, author:, attachment_count: 3, except_field_types: %w[phone payment]) }
|
||||
|
||||
before do
|
||||
sign_in(author)
|
||||
end
|
||||
|
||||
context 'when manage template documents' do
|
||||
before do
|
||||
visit edit_template_path(template)
|
||||
end
|
||||
|
||||
it 'replaces the document' do
|
||||
doc = find("div[id='documents_container'] div[data-document-uuid='#{template.schema[1]['attachment_uuid']}'")
|
||||
doc.click
|
||||
|
||||
expect do
|
||||
wait_for_fetch do
|
||||
doc.find('.replace-document-button').click
|
||||
doc.find('.replace-document-button input[type="file"]', visible: false)
|
||||
.attach_file(Rails.root.join('spec/fixtures/sample-image.png'))
|
||||
end
|
||||
end.to change { template.documents.count }.by(1)
|
||||
|
||||
expect(template.reload['schema'][1]['name']).to eq('sample-image')
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user