Back to Repositories

Testing Dashboard Template Management in DocuSeal

This test suite validates the functionality of the dashboard page in a DocuSeal application, focusing on template management and user interactions. The tests cover both empty state handling and template listing scenarios, ensuring proper access control and user experience.

Test Coverage Overview

The test suite provides comprehensive coverage of the dashboard functionality:

  • Empty state validation when no templates exist
  • Template listing and visibility controls
  • Template creation workflow
  • User authorization and account-specific access

Implementation Analysis

The implementation utilizes RSpec’s system testing capabilities with a behavior-driven approach. The tests leverage factory patterns for test data generation and employ context blocks for organizing different test scenarios. The suite demonstrates effective use of let blocks for setup and expectations for verification.

Technical Details

  • Testing Framework: RSpec
  • Test Type: System Tests
  • Key Dependencies: Rails Helper, Factory Bot
  • Setup Requirements: User authentication, Account creation
  • Test Data: Factory-generated templates and users

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Proper test isolation using before blocks
  • Clear context separation for different scenarios
  • Effective use of factory patterns for test data
  • Explicit expectations for UI elements and state changes
  • Clean setup and teardown management

docusealco/docuseal

spec/system/dashboard_spec.rb

            
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Dashboard Page' do
  let!(:account) { create(:account) }
  let!(:user) { create(:user, account:) }

  before do
    sign_in(user)
  end

  context 'when are no templates' do
    it 'shows empty state' do
      visit root_path

      expect(page).to have_link('Create', href: new_template_path)
    end
  end

  context 'when there are templates' do
    let!(:authors) { create_list(:user, 5, account:) }
    let!(:templates) { authors.map { |author| create(:template, account:, author:) } }
    let!(:other_template) { create(:template, account: create(:user).account) }

    before do
      visit root_path
    end

    it 'shows the list of templates' do
      templates.each do |template|
        expect(page).to have_content(template.name)
        expect(page).to have_content(template.author.full_name)
      end

      expect(page).to have_content('Templates')
      expect(page).to have_no_content(other_template.name)
      expect(page).to have_link('Create', href: new_template_path)
    end

    it 'initializes the template creation process' do
      click_link 'Create'

      within('#modal') do
        fill_in 'template[name]', with: 'New Template'

        expect do
          click_button 'Create'
        end.to change(Template, :count).by(1)

        expect(page).to have_current_path(edit_template_path(Template.last), ignore_query: true)
      end
    end
  end
end