Feature: Browsing external recipe sources
  As a signed-in user
  I want to browse the recipes available from my household's enabled sources
  So that I can find new recipes to import, or jump straight to ones I already have

  Background:
    Given I am signed in as "Alice" "Martin"
    And my household id is 1
    And the disliked ingredients list is empty
    And the planning request returns nothing

  Scenario: Shows no source tab when the household hasn't enabled any
    Given the recipe catalog contains nothing
    And the sources reference list has options
    And the household's enabled sources are empty
    When I visit "/recettes"
    Then I should not see "TheMealDB"

  Scenario: Browses an enabled source, distinguishing already-imported items from new ones
    Given the recipe catalog contains nothing
    And the sources reference list has options
    And the household has enabled TheMealDB
    And browsing TheMealDB returns some items
    And recipe 2's detail is available
    When I visit "/recettes"
    And I click the button "TheMealDB"
    Then I should see the source item "Chicken Handi"
    And I should see the source item "Fish Pie"
    And the source item "Chicken Handi" should be marked as already imported

    When I click the source item "Chicken Handi"
    Then the URL should include "/recettes/2"
    And the recipe detail panel heading should be "Omelette"

  Scenario: Previews a not-yet-imported item, highlighting its detected techniques
    Given the recipe catalog contains nothing
    And the sources reference list has options
    And the household has enabled TheMealDB
    And browsing TheMealDB returns some items
    And previewing TheMealDB item "9999" is available
    When I visit "/recettes"
    And I click the button "TheMealDB"
    And I click the source item "Fish Pie"
    Then the URL should include "/recettes/sources/theMealDb/9999"
    And the recipe detail panel heading should be "Fish Pie"
    And I should see the highlighted technique "Cuire"

  Scenario: Loads further pages automatically, with no "load more" button
    Given the recipe catalog contains nothing
    And the sources reference list has options
    And the household has enabled TheMealDB
    And browsing TheMealDB returns two pages of items
    When I visit "/recettes"
    And I click the button "TheMealDB"
    Then I should see the source item "Chicken Handi"
    And I should see the source item "Beef Wellington"
    And I should not see "Voir plus"

  Scenario: Offers a retry when loading the next page fails
    Given the recipe catalog contains nothing
    And the sources reference list has options
    And the household has enabled TheMealDB
    And browsing TheMealDB's next page fails once, then succeeds
    When I visit "/recettes"
    And I click the button "TheMealDB"
    Then I should see the source item "Chicken Handi"
    And I should see a message to retry loading more
    When I click the button "Réessayer"
    Then I should see the source item "Beef Wellington"

  Scenario: Deep-links straight to a not-yet-imported item's own page, with no import affordance at all
    Given the recipe catalog contains nothing
    And the sources reference list has options
    And the household has enabled TheMealDB
    And browsing TheMealDB returns some items
    And previewing TheMealDB item "9999" is available
    When I visit "/recettes/sources/theMealDb/9999"
    Then the recipe detail panel heading should be "Fish Pie"
    And I should not see "Importer cette recette"
    And I should see a discreet link to the item's original page
