Back to Repositories

Testing Account Settings Management Workflow in DocuSeal

This test suite validates account settings functionality in a web application, focusing on managing company details, localization preferences, and application configuration. It ensures proper handling of account customization and multilingual support.

Test Coverage Overview

The test suite provides comprehensive coverage of account settings management:

  • Verification of pre-filled account settings display
  • Account details update functionality testing
  • Language switching and localization validation
  • Encrypted configuration handling for app URL

Implementation Analysis

The testing approach utilizes RSpec’s system testing capabilities with a focus on user interaction simulation. It implements factory-based test data setup and leverages Rails’ authentication system for user context.

Key patterns include:
  • Factory-based test data preparation
  • Before hooks for authentication setup
  • Explicit state verification after actions
  • Localization testing with multiple languages

Technical Details

Testing tools and configuration:

  • RSpec for test framework
  • Factory setup for account and user models
  • Encrypted configuration handling
  • Capybara for page interaction
  • Rails authentication integration

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Isolated test scenarios with clear setup
  • Comprehensive state verification
  • Proper separation of concerns
  • Effective use of let blocks for test data
  • Clear and maintainable test structure

docusealco/docuseal

spec/system/account_settings_spec.rb

            
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Account Settings' do
  let!(:account) { create(:account) }
  let!(:user) { create(:user, account:) }
  let!(:encrypted_config) { create(:encrypted_config, account:, key: EncryptedConfig::APP_URL_KEY, value: 'https://www.test.com') }

  before do
    sign_in(user)
    visit settings_account_path
  end

  it 'shows pre-filled account settings page' do
    expect(page).to have_content('Account')
    expect(page).to have_field('Company name', with: account.name)
    expect(page).to have_field('Time zone', with: account.timezone)
    expect(page).to have_field('Language', with: account.locale)
    expect(page).to have_field('App URL', with: encrypted_config.value)
  end

  it 'updates the account settings' do
    fill_in 'Company name', with: 'New Company Name'
    fill_in 'App URL', with: 'https://example.com'
    select '(GMT+01:00) Berlin', from: 'Time zone'
    select 'Español', from: 'Language'

    click_button 'Update'

    account.reload
    encrypted_config.reload

    expect(account.name).to eq('New Company Name')
    expect(account.timezone).to eq('Berlin')
    expect(account.locale).to eq('es-ES')
    expect(encrypted_config.value).to eq('https://example.com')
  end

  it 'changes the account language' do
    select 'Deutsch', from: 'Language'

    click_button 'Update'

    account.reload
    encrypted_config.reload

    expect(account.locale).to eq('de-DE')
    expect(page).to have_content('Konto')
    expect(page).to have_field('Firmenname', with: account.name)
    expect(page).to have_field('Zeitzone', with: account.timezone)
    expect(page).to have_field('Sprache', with: account.locale)
    expect(page).to have_field('App-URL', with: encrypted_config.value)
    expect(page).to have_button('Aktualisieren')
  end
end