Feature: Household settings
  As a signed-in user
  I want to create, join, manage, or leave a household
  So that I can share a batch-cooking plan with the people I cook with

  Scenario: Creates a household
    Given I am signed in as "Alice" "Martin"
    And creating a household will succeed
    When I visit "/parametres/foyer"
    And I fill in the "houseName" field with "Chez Alice"
    And I click the button "Créer"
    Then the household creation request should have been made with name "Chez Alice"
    And I should see "ABCD2345"

  Scenario: Joins a household by invite code
    Given I am signed in as "Alice" "Martin"
    And joining a household will succeed
    When I visit "/parametres/foyer"
    And I fill in the "inviteCode" field with "abcd2345"
    And I click the button "Rejoindre"
    Then the household join request should have been made with invite code "ABCD2345"
    And I should see "Bob Dupont"

  Scenario: Autosaves the household name
    Given I am signed in as "Alice" "Martin"
    And my household id is 1
    And the household request returns the two-member household
    And renaming the household will succeed
    When I visit "/parametres/foyer"
    And I clear the "houseName" field
    And I fill in the "houseName" field with "Chez les Martin"
    Then the household rename request should have been made with name "Chez les Martin"
    And I should see "Enregistré ✓"

  Scenario: Removes a member
    Given I am signed in as "Alice" "Martin"
    And my household id is 1
    And the household request returns the two-member household
    And removing Bob from the household will succeed
    When I visit "/parametres/foyer"
    And I click "Retirer" for the member "Bob Dupont"
    Then the member removal request should have been made
    And I should not see "Bob Dupont"

  Scenario: Deletes the household after confirming
    Given I am signed in as "Alice" "Martin"
    And my household id is 1
    And the household request returns the two-member household
    And deleting the household will succeed
    When I visit "/parametres/foyer"
    And I click the button "Supprimer le foyer"
    And I click the button "Confirmer la suppression"
    Then the household deletion request should have been made
    And I should see "Créer un foyer"

  Scenario: Shows and saves the household's enabled recipe sources
    Given I am signed in as "Alice" "Martin"
    And my household id is 1
    And the household request returns the two-member household
    And the sources reference list has options
    And the household's enabled sources are empty
    And saving the source selection will succeed
    When I visit "/parametres/foyer"
    And I scroll to the section "Sources disponibles"
    Then I should see the section "Sources disponibles"
    And I should see "TheMealDB"
    And I should see "Officielle"
    And I should see "Marmiton"
    And I should see "Non officielle"
    When I check the checkbox "TheMealDB"
    Then the source selection update request should have been made with source id 1
    And I should see "Enregistré ✓"

  Scenario: Hides the sources section entirely when no source is implemented yet
    Given I am signed in as "Alice" "Martin"
    And my household id is 1
    And the household request returns the two-member household
    And the sources reference list is empty
    And the household's enabled sources are empty
    When I visit "/parametres/foyer"
    Then I should not see "Sources de recettes"

  Scenario: Leaves the household
    Given I am signed in as "Bob" "Dupont"
    And my user id is 2
    And my household id is 1
    And the household request returns the two-member household
    And leaving the household will succeed
    When I visit "/parametres/foyer"
    And I click the button "Quitter le foyer"
    Then the household leave request should have been made
