Back to Repositories

Validating Profile Settings Management in DocuSeal

This test suite validates the profile settings functionality in the DocuSeal application, covering user profile management and password update scenarios. It ensures proper handling of user data modifications and password change workflows.

Test Coverage Overview

The test suite provides comprehensive coverage of profile settings functionality:

  • User profile data display verification
  • Contact information update validation
  • Password change scenarios including successful updates and validation failures
  • Form field presence and initial value verification

Implementation Analysis

The testing approach utilizes RSpec’s system testing capabilities with a focus on user interaction simulation. It leverages factory-based test data generation and implements before hooks for authentication setup. The tests follow page object patterns for UI interaction and verification.

Technical Details

  • RSpec system tests with Rails integration
  • Factory-based test data generation
  • Capybara for page interaction
  • Authentication helper methods
  • Page object pattern implementation

Best Practices Demonstrated

The test suite exemplifies several testing best practices including context-based test organization, descriptive test naming, and proper setup isolation. It demonstrates effective use of RSpec’s let blocks for test data management and employs clear assertion patterns for result verification.

docusealco/docuseal

spec/system/profile_settings_spec.rb

            
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Profile Settings' do
  let(:user) { create(:user, account: create(:account)) }

  before do
    sign_in(user)
    visit settings_profile_index_path
  end

  it 'shows the profile settings page' do
    expect(page).to have_content('Profile')
    expect(page).to have_field('user[email]', with: user.email)
    expect(page).to have_field('user[first_name]', with: user.first_name)
    expect(page).to have_field('user[last_name]', with: user.last_name)

    expect(page).to have_content('Change Password')
    expect(page).to have_field('user[password]')
    expect(page).to have_field('user[password_confirmation]')
  end

  context 'when changes contact information' do
    it 'updates first name, last name and email' do
      fill_in 'First name', with: 'Devid'
      fill_in 'Last name', with: 'Beckham'
      fill_in 'Email', with: '[email protected]'

      all(:button, 'Update')[0].click

      user.reload

      expect(user.first_name).to eq('Devid')
      expect(user.last_name).to eq('Beckham')
      expect(user.email).to eq('[email protected]')
    end
  end

  context 'when changes password' do
    it 'updates password' do
      fill_in 'New password', with: 'newpassword'
      fill_in 'Confirm new password', with: 'newpassword'

      all(:button, 'Update')[1].click

      expect(page).to have_content('Password has been changed')
    end

    it 'does not update if password confirmation does not match' do
      fill_in 'New password', with: 'newpassword'
      fill_in 'Confirm new password', with: 'newpassword1'

      all(:button, 'Update')[1].click

      expect(page).to have_content("Password confirmation doesn't match Password")
    end
  end
end