require "integration_test_helper"

class HomepageTest < ActionDispatch::IntegrationTest
  setup do
    stub_content_store_has_item("/", schema: "special_route")
  end

  should "render the homepage" do
    visit "/"
    assert_equal 200, page.status_code
    assert_equal "Welcome to GOV.UK", page.title
  end

  context "when visiting a Welsh content item first" do
    setup do
      @payload = {
        base_path: "/cymraeg",
        content_id: "d6d6caaf-77db-47e1-8206-30cd4f3d0e3f",
        document_type: "transaction",
        locale: "cy",
        publishing_app: "publisher",
        rendering_app: "frontend",
        schema_name: "transaction",
        title: "Cymraeg",
        description: "Cynnwys Cymraeg",
        details: {
          transaction_start_link: "http://cymraeg.example.com",
          start_button_text: "Start now",
        },
      }
      stub_content_store_has_item("/cymraeg", @payload)
    end

    should "use the English locale after visiting the Welsh content" do
      visit @payload[:base_path]
      visit "/"
      assert page.has_content?(I18n.t("homepage.index.services_and_information", locale: :en))
      assert_not page.has_content?(I18n.t("homepage.index.services_and_information", locale: :cy))
    end
  end
end

require "integration_test_helper"

class HomepageTest < ActionDispatch::IntegrationTest
  setup do
    stub_content_store_has_item("/", schema: "special_route")
  end

  should "render the homepage" do
    visit "/"
    assert_equal 200, page.status_code
    assert_equal "Welcome to GOV.UK", page.title
  end

  context "when visiting a Welsh content item first" do
    setup do
      @payload = {
        base_path: "/cymraeg",
        content_id: "d6d6caaf-77db-47e1-8206-30cd4f3d0e3f",
        document_type: "transaction",
        locale: "cy",
        publishing_app: "publisher",
        rendering_app: "frontend",
        schema_name: "transaction",
        title: "Cymraeg",
        description: "Cynnwys Cymraeg",
        details: {
          transaction_start_link: "http://cymraeg.example.com",
          start_button_text: "Start now",
        },
      }
      stub_content_store_has_item("/cymraeg", @payload)
    end

    should "use the English locale after visiting the Welsh content" do
      visit @payload[:base_path]
      visit "/"
      assert page.has_content?(I18n.t("homepage.index.government_activity_description", locale: :en))
    end
  end
end

Make homepage / Welsh test less coupled to Welsh locale file
Make homepage / Welsh test less coupled to Welsh locale file

The previous iteration of this test checked that 1) English text
appeared, and 2) Welsh text did not appear.
Whilst that fulfilled the needs of the test, 2) is a bit redundant,
given that we don't render a Welsh homepage at all. It means having
to maintain a set of Welsh locales for a homepage, which never ends
up getting used.

It should be sufficient to just check that the English text displays.
I've chosen a more substanial English locale property than just
"Topics", which is the current value of `services_and_information`
and could risk being part of 'normal' page furniture (as not
everything on a Welsh page is translated).
