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

Refactor Autosuggest component test file to new format #3327

Open
wants to merge 45 commits into
base: main
Choose a base branch
from

Conversation

precious-onyenaucheya-ons
Copy link
Contributor

@precious-onyenaucheya-ons precious-onyenaucheya-ons commented Sep 4, 2024

What is the context of this PR?

Fixes: ONSdigital/design-team#134
This PR involves refactoring of the autosuggest test document to follow the Given, When, Then testing approach.

How to review this PR

Functionality:

  • Run the test suite using: yarn test --testNamePattern="FOR: Macro: Autosuggest"

Does this testing refactor meet the following success criteria:

  • Clearly structured.
  • Follows naming conventions.
  • Consistent.
  • Concise.
  • Suited to our codebase.
  • Compatible with existing testing framework.

Look at the refactored code in relation to:

  • The original test document.
  • The macro file.
  • The macro options file.

Checklist

This needs to be completed by the person raising the PR.

  • I have selected the correct Assignee
  • I have linked the correct Issue

@precious-onyenaucheya-ons precious-onyenaucheya-ons added the Tech improvements Tech debt, cleanup, code standardisation etc. label Sep 4, 2024
Copy link

netlify bot commented Sep 4, 2024

Deploy Preview for ons-design-system-preview ready!

Name Link
🔨 Latest commit 5060c41
🔍 Latest deploy log https://app.netlify.com/sites/ons-design-system-preview/deploys/673b34fa90dbf100081cd24c
😎 Deploy Preview https://deploy-preview-3327--ons-design-system-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@precious-onyenaucheya-ons precious-onyenaucheya-ons changed the title Feature/134/autosuggest testing refactor Refactor autosuggest test document Sep 4, 2024
Copy link
Contributor

@rmccar rmccar left a comment

Choose a reason for hiding this comment

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

I think some more work needs to be done here, use one of the other PRs as a template. We are missing the "FOR" and "THEN" in some cases

src/components/autosuggest/_macro.spec.js Outdated Show resolved Hide resolved
src/components/autosuggest/_macro.spec.js Outdated Show resolved Hide resolved
src/components/autosuggest/_macro.spec.js Outdated Show resolved Hide resolved
src/components/autosuggest/autosuggest.spec.js Outdated Show resolved Hide resolved
@precious-onyenaucheya-ons precious-onyenaucheya-ons changed the title Refactor autosuggest test document Refactor autosuggest component test file to new format Sep 12, 2024
@rmccar rmccar changed the title Refactor autosuggest component test file to new format Refactor Autosuggest component test file to new format Sep 27, 2024
Copy link
Contributor

@rmccar rmccar left a comment

Choose a reason for hiding this comment

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

Just some minor comments that I think make sense with the testing rules we have set in the documentation

src/components/autosuggest/_macro.spec.js Outdated Show resolved Hide resolved
src/components/autosuggest/_macro.spec.js Outdated Show resolved Hide resolved
@rmccar rmccar added the Do not merge Don't merge this PR until this label is removed label Oct 2, 2024
@rmccar rmccar removed the Do not merge Don't merge this PR until this label is removed label Oct 9, 2024
Copy link
Contributor

@rmccar rmccar left a comment

Choose a reason for hiding this comment

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

Ive realised we are missing tests for the language and resultsThreshold params. I think we should add these

Comment on lines 84 to 86
test('THEN: it has language set to "en-gb"', () => {
expect($('.ons-autosuggest').attr('data-lang')).toBe('en-gb');
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Only required params should be inside this "when" unless you are testing defaults. I don't think this param is required and theres probably a few others too such as the result threshold one. I think we need to review these, keep the ones that test defaults move the others. Then for the ones that have defaults make sure the defaults are tested here and have another test to test what you pass in is overriding that default

Copy link
Contributor

@rmccar rmccar Nov 13, 2024

Choose a reason for hiding this comment

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

I think the params still need to be reviewed. Theres still some params in there that aren't required

Copy link
Contributor

@rmccar rmccar left a comment

Choose a reason for hiding this comment

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

I think you need to check the required the params in the documentation some of these in the required describe aren't required still. Also the "params none" describe you've added actually passes in a lot of params because it uses EXAMPLE_AUTOSUGGEST. I don't think we need this describe though, we should be testing these things with the required params because we expect those params to be passed in

src/components/autosuggest/_macro.spec.js Outdated Show resolved Hide resolved
src/components/autosuggest/_macro.spec.js Show resolved Hide resolved
@@ -18,4 +18,4 @@
| input | `Input` [_(ref)_](/components/input) | true | Configuration object for the input |
| language | string | false | The ISO 639-1 Code will override the default language in page. Please note that only 'en', 'cy' and 'ni' is currently supported |
| resultsThreshold | float | false | Option to adjust the search threshold and fuzziness. Accepts a range from 0 to 1, where 0 provides the closest match and 1 allows for more distant matches. Defaults to 0.2. |
| id | string | false | The `id` of the input |
| id | string | true | The `id` of the input |
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is a correction rather than an alteration since I can't see a change in the code to require this field and there is no mention in the ticket itself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tech improvements Tech debt, cleanup, code standardisation etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testing refactor - Autosuggest
4 participants