Back to Repositories

Testing Settings Navigation and Self-Hosting Configuration in Maybe Finance

This test suite validates settings functionality in the Maybe Finance application, focusing on user settings navigation and self-hosting configuration. The tests ensure proper sidebar navigation, settings access, and self-hosting feature management.

Test Coverage Overview

The test suite provides comprehensive coverage of settings-related functionality:

  • Navigation through settings menu items and path verification
  • Self-hosting configuration options and invite code generation
  • Clipboard integration for invite code copying
  • User session management and authentication

Implementation Analysis

The implementation uses Minitest’s system testing capabilities with VCR for external request handling. The tests employ a structured approach with setup methods for user authentication and settings navigation paths definition.

Key patterns include:
  • Helper methods for common actions like sidebar navigation
  • VCR cassettes for managing external dependencies
  • Stubbing configuration for self-hosted mode testing

Technical Details

Testing tools and configuration:

  • ApplicationSystemTestCase as the base test class
  • VCR for HTTP interaction recording
  • Capybara for browser simulation
  • Fixtures for user data management
  • Custom helper methods for UI interaction

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Isolated test setup with proper user authentication
  • Comprehensive path verification
  • Explicit element selection and interaction
  • Clear separation of concerns with helper methods
  • Proper handling of asynchronous operations

maybe-finance/maybe

test/system/settings_test.rb

            
require "application_system_test_case"

class SettingsTest < ApplicationSystemTestCase
  setup do
    sign_in @user = users(:family_admin)

    @settings_links = [
      [ "Account", settings_profile_path ],
      [ "Preferences", settings_preferences_path ],
      [ "Accounts", accounts_path ],
      [ "Tags", tags_path ],
      [ "Categories", categories_path ],
      [ "Merchants", merchants_path ],
      [ "Imports", imports_path ],
      [ "What's new", changelog_path ],
      [ "Feedback", feedback_path ]
    ]
  end

  test "can access settings from sidebar" do
    VCR.use_cassette("git_repository_provider/fetch_latest_release_notes") do
      open_settings_from_sidebar
      assert_selector "h1", text: "Account"
      assert_current_path settings_profile_path, ignore_query: true

      @settings_links.each do |name, path|
        click_link name
        assert_selector "h1", text: name
        assert_current_path path
      end
    end
  end

  test "can update self hosting settings" do
    Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
    open_settings_from_sidebar
    assert_selector "li", text: "Self hosting"
    click_link "Self hosting"
    assert_current_path settings_hosting_path
    assert_selector "h1", text: "Self-Hosting"
    check "setting_require_invite_for_signup", allow_label_click: true
    click_button "Generate new code"
    assert_selector 'span[data-clipboard-target="source"]', visible: true, count: 1 # invite code copy widget
    copy_button = find('button[data-action="clipboard#copy"]', match: :first) # Find the first copy button (adjust if needed)
    copy_button.click
    assert_selector 'span[data-clipboard-target="iconSuccess"]', visible: true, count: 1 # text copied and icon changed to checkmark
  end

  private

    def open_settings_from_sidebar
      find("#user-menu").click
      click_link "Settings"
    end
end