Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests that check the output of time_ago_in_words are unable to access translations #2679

Open
hannako opened this issue Jan 27, 2023 · 0 comments

Comments

@hannako
Copy link
Contributor

hannako commented Jan 27, 2023

Service manual frontend is soon to be retired, and the first step in that process was importing the templates, helpers and specs from the existing repo into this application. See #2583

Imported integration tests that check for the output of a rails helper are failing and have been skipped.

Original test in service manual frontend

test "shows the time it was saved if it hasn't been published yet" do
    now = "2015-10-10T09:00:00+00:00"
    last_saved_at = "2015-10-10T08:55:00+00:00"

    travel_to(now) do
      example = simulate_example_as_first_edition_on_draft_stack(
        govuk_content_schema_example(
          "service_manual_guide",
          "service_manual_guide",
          updated_at: last_saved_at,
        ),
      )
      base_path = example.fetch("base_path")
      stub_content_store_has_item(base_path, example)
      visit base_path

      within(".app-change-history") do
        assert page.has_content?("5 minutes ago")
      end
    end
  end

Running that test in service manual frontend passes. But running that test once imported to this application results in translation missing: en.datetime.distance_in_words.x_days:

test_shows_the_time_it_was_saved_if_it_hasn't_been_published_yetERROR (2.10s)
Minitest::UnexpectedError:         
Capybara::ExpectationNotMet: expected to find text "5 minutes ago" in 
"From:\nAgile delivery community\nLast updated\ntranslation missing: en.datetime.distance_in_words.x_days ago\nLast update:\n9 October 2015\nThis is our latest change\n+ Show all page updates (2)\n9 September 2015\nThis is another change\n1 September 2015\nGuidance first published"

Details

  • time_ago_in_words is method defined in ActionView::DateHelper
  • as per the Rails docs, that helper has built in I18n support, accessing translations from this locale file.
  • Adding a debugger to the test, and inspecting I18n.backed.translations[:en][:datetime] confirms that those keys are available to the helper, but something in the configuration of the test suite is preventing the helper using them.

NOTE: Once the migration PR is merged, links to the test and the files calling the helper will be added to this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant