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

test: add and use util to inject one metadata manager #893

Merged

Conversation

davidlj95
Copy link
Owner

@davidlj95 davidlj95 commented Oct 7, 2024

Issue or need

A trick is used right now for existing metadata manager tests in order to unit test the metadata manager (its setter, actually).
This is done because metadata managers are provided as part of a multi provider for the NgxMetaMetadataManager token / abstract class.

So can't inject one specifically.

The trick has been to export the setter factory (that comes with dependencies as arguments). Then, when unit testing, manually inject the needed dependencies.

This is not ideal because it doesn't reflect real use (where automatic injection is done).

And now is an impediment for a subsequent refactor removing the deps usage by calls to inject in the factory. Then, a way is needed to unit test metadata managers without manually injecting. As otherwise, an error will appear about using inject in a non-injection context.

Proposed changes

Introduce injectOneMetadataManager util for tests. Which will inject the only metadata manager existing. Or throw otherwise.

injectMetadataManagers has been internally exported in order to use it for that util too.

Then, use that util around to avoid the trick.

Other changes: unite undefined / null test cases in a describe + for loop.

Quick reminders

  • 🤝 I will follow Code of Conduct
  • No existing pull request already does almost same changes
  • 👁️ Contributing docs are something I've taken a look at
  • 📝 Commit messages convention has been followed
  • 💬 TSDoc comments have been added or updated indicating API visibility if API surface has changed.
  • 🧪 Tests have been added if needed. For instance, if adding new features or fixing a bug. Or removed if removing features.
  • ⚙️ API Report has been updated if API surface is altered.

Copy link
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @davidlj95 and the rest of your teammates on Graphite Graphite

@davidlj95 davidlj95 force-pushed the stacked/test-add-and-use-util-to-inject-one-metadata-manager branch from e1e8e71 to 67254c6 Compare October 7, 2024 18:43
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.46%. Comparing base (b49c0ff) to head (d6723b8).
Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #893   +/-   ##
=======================================
  Coverage   99.46%   99.46%           
=======================================
  Files          79       79           
  Lines         372      372           
  Branches       73       73           
=======================================
  Hits          370      370           
  Partials        2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Oct 7, 2024

📦 Bundle size (Angular v17)

Git ref: d6723b84f92b713176dc0c5bfe878406a0116e61

Module file Size Base size Difference
ngx-meta-core.mjs 2812 bytes (2.8KiB) 2812 bytes (2.8KiB) No change
ngx-meta-json-ld.mjs 224 bytes (224B) 224 bytes (224B) No change
ngx-meta-open-graph.mjs 984 bytes (984B) 984 bytes (984B) No change
ngx-meta-routing.mjs 449 bytes (449B) 449 bytes (449B) No change
ngx-meta-standard.mjs 990 bytes (990B) 990 bytes (990B) No change
ngx-meta-twitter-card.mjs 514 bytes (514B) 514 bytes (514B) No change
Total 5973 bytes (5.9KiB) 5973 bytes (5.9KiB) No change

Copy link

github-actions bot commented Oct 7, 2024

📦 Bundle size (Angular v18)

Git ref: d6723b84f92b713176dc0c5bfe878406a0116e61

Module file Size Base size Difference
ngx-meta-core.mjs 2812 bytes (2.8KiB) 2812 bytes (2.8KiB) No change
ngx-meta-json-ld.mjs 224 bytes (224B) 224 bytes (224B) No change
ngx-meta-open-graph.mjs 984 bytes (984B) 984 bytes (984B) No change
ngx-meta-routing.mjs 449 bytes (449B) 449 bytes (449B) No change
ngx-meta-standard.mjs 990 bytes (990B) 990 bytes (990B) No change
ngx-meta-twitter-card.mjs 514 bytes (514B) 514 bytes (514B) No change
Total 5973 bytes (5.9KiB) 5973 bytes (5.9KiB) No change

Copy link

github-actions bot commented Oct 7, 2024

📦 Bundle size (Angular v16)

Git ref: d6723b84f92b713176dc0c5bfe878406a0116e61

Module file Size Base size Difference
ngx-meta-core.mjs 3255 bytes (3.2KiB) 3255 bytes (3.2KiB) No change
ngx-meta-json-ld.mjs 368 bytes (368B) 368 bytes (368B) No change
ngx-meta-open-graph.mjs 1263 bytes (1.3KiB) 1263 bytes (1.3KiB) No change
ngx-meta-routing.mjs 641 bytes (641B) 641 bytes (641B) No change
ngx-meta-standard.mjs 1087 bytes (1.1KiB) 1087 bytes (1.1KiB) No change
ngx-meta-twitter-card.mjs 645 bytes (645B) 645 bytes (645B) No change
Total 7259 bytes (7.1KiB) 7259 bytes (7.1KiB) No change

Copy link

github-actions bot commented Oct 7, 2024

📦 Bundle size (Angular v15)

Git ref: d6723b84f92b713176dc0c5bfe878406a0116e61

Module file Size Base size Difference
ngx-meta-core.mjs 3220 bytes (3.2KiB) 3220 bytes (3.2KiB) No change
ngx-meta-json-ld.mjs 353 bytes (353B) 353 bytes (353B) No change
ngx-meta-open-graph.mjs 1233 bytes (1.3KiB) 1233 bytes (1.3KiB) No change
ngx-meta-routing.mjs 626 bytes (626B) 626 bytes (626B) No change
ngx-meta-standard.mjs 1072 bytes (1.1KiB) 1072 bytes (1.1KiB) No change
ngx-meta-twitter-card.mjs 630 bytes (630B) 630 bytes (630B) No change
Total 7134 bytes (7.0KiB) 7134 bytes (7.0KiB) No change

@davidlj95 davidlj95 force-pushed the stacked/test-add-and-use-util-to-inject-one-metadata-manager branch from 67254c6 to d6723b8 Compare October 7, 2024 18:49
@davidlj95 davidlj95 enabled auto-merge (squash) October 7, 2024 18:49
@davidlj95 davidlj95 merged commit 19d988d into main Oct 7, 2024
34 checks passed
@davidlj95 davidlj95 deleted the stacked/test-add-and-use-util-to-inject-one-metadata-manager branch October 7, 2024 18:55
Copy link

github-actions bot commented Oct 8, 2024

🎉 This PR is included in version 1.0.0-beta.16 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

1 participant