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

Add get involved tests to replace Smokey tests #2473

Merged
merged 3 commits into from
Jun 29, 2022

Conversation

kevindew
Copy link
Member

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

The /government/get-involved page was previously tested in a rather unusual way where there weren't any real tests for the endpoint in this application but there was an unusually thorough set of tests in Smokey. This isn't ideal because the Smokey tests are expensive and unnecessary since the logic is in this app.

This rewrites the tests to allow for the majority of the Smokey tests to be removed.

Copy link
Contributor

@benthorner benthorner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice 👏.

I've checked the tests against the page and they (now) line up, except for the new edge case I mentioned in a comment - not really worth blocking on though.

Some of the smoke tests are looking in finer detail than we are here (example). Much of this is static / declarative so I don't think we actually need to replicate it.

There is some functionality that's not covered at all e.g.

However, this is still a net improvement and we're at least implicitly testing much of the code doesn't break. I don't think it's worth adding more tests right now.

}
stub_search(body)
stub_request(:get, /\A#{Plek.current.find('search')}\/search.json/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about DRYing up the URL into a variable?

It's a relatively complex sequence to read over and again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good shout, I've set it as a helper method.

app/views/content_items/get_involved.html.erb Show resolved Hide resolved
@@ -53,14 +53,14 @@
<%= render "govuk_publishing_components/components/big_number", {
number: @open_consultation_count,
label: t('get_involved.open_consultations'),
href: "/government/organisations#ministerial_departments"
href: "/search/policy-papers-and-consultations?content_store_document_type=open_consultations"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great digging here - it's rare both the code and the test are broken!

@kevindew kevindew force-pushed the rewrite-get-involved-tests branch from c9c338b to b802b2d Compare June 29, 2022 15:40
@kevindew
Copy link
Member Author

Thanks @benthorner for the review. I've made a change and I'll plan to merge if it clears CI, shout if it raises any concerns.

You're right we could do more, there is lots of nuances for this. I'd think they'd be ripe for a wider refactoring where presumably some tested helpers should be introduced.

kevindew added 3 commits June 29, 2022 18:18
This changes the previous tests, which tested a number of controller
methods, into a set of tests that take the more idiomatic Rails approach
of testing the controllers via requests.

The motivation for this work was to enable the retirement of a large
set of tests for this set of pages done through Smokey [1]. These Smokey
tests are unconventional as they seem to be used as a the primary means
to test these pages - this is not a reliable or scalable approach given
they're in a separate repository. Nor is it necessary as the logic is
within this application.

[1]: https://github.com/alphagov/smokey/blob/7553a432259d785fb6d4fb81cfd4fe3572185ad3/features/apps/government_frontend.feature#L23-L140
I intend to remove the majority of Smokey tests for this page so this
warning will no longer be applicable.
These links were incorrect, presumably they are an artefact from what
was used to copy+paste from originally.

Interestingly these links actually have explicit tests in Smokey [1].
But it turns out they don't actually test correctly as they don't have
an expect step [2].

As it is quite unusual to test at the fidelity of individual links in
HTML (they're just testing you typed the same thing afterall) I've not
added replacement tests.

[1]: https://github.com/alphagov/smokey/blob/7553a432259d785fb6d4fb81cfd4fe3572185ad3/features/apps/government_frontend.feature#L23-L47
[2]: https://github.com/alphagov/smokey/blob/7553a432259d785fb6d4fb81cfd4fe3572185ad3/features/step_definitions/get_involved_page_steps.rb#L39-L41
@kevindew kevindew force-pushed the rewrite-get-involved-tests branch from b802b2d to fb039c6 Compare June 29, 2022 17:18
@kevindew kevindew merged commit 0fe01bc into main Jun 29, 2022
@kevindew kevindew deleted the rewrite-get-involved-tests branch June 29, 2022 17:37
kevindew added a commit to alphagov/smokey that referenced this pull request Jun 29, 2022
Tests for the get-involved page have been written in government-frontend
now [1], so we can now remove these features that don't meet the Smokey
eligibility criteria.

[1]: alphagov/government-frontend#2473
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

Successfully merging this pull request may close these issues.

2 participants