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

Tests: Add support for specifying generic type parameters per component and remove class T #8962

Merged
merged 2 commits into from May 14, 2024

Conversation

ArieGato
Copy link
Contributor

Description

resolves #8923

Add support for specifying generic type parameters per component for generating the ApiDocsTest.generated.cs file. The default generic parameter is now string.

In TestsForApiPages.cs a dictionary has been added where the default generic type parameters of a generic component can be overridden. Type string will be used as generic type parameter when the GenericTypeDefinition has not been added to the dictionary.

private static readonly Dictionary<Type, string[]> s_genericTypeIndexCache = new()
{
    { typeof(MudSlider<>), ["decimal"]},
    { typeof(MudSwitch<>), ["bool"]}
};

This results in the following generated code for the MudSlider:

[Test]
public void MudSlider_API_Test()
{
    ctx.Services.AddSingleton<NavigationManager>(new MockNavigationManager("https://localhost:2112/", "https://localhost:2112/api/MudSlider<decimal>"));
    ctx.RenderComponent<DocsApi>(ComponentParameter.CreateParameter("Type", typeof(MudSlider<decimal>)));
}

The other generic components wille be generated with string as generic paramater(s)

[Test]
public void MudSelectItem_API_Test()
{
    ctx.Services.AddSingleton<NavigationManager>(new MockNavigationManager("https://localhost:2112/", "https://localhost:2112/api/MudSelectItem<string>"));
    ctx.RenderComponent<DocsApi>(ComponentParameter.CreateParameter("Type", typeof(MudSelectItem<string>)));
}

How Has This Been Tested?

Visually checked the generated code.

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

… generating ApiDocsTest.generated.cs file. The default generic parameter is now string.
@github-actions github-actions bot added docs Related to docs PR: needs review labels May 13, 2024
Copy link

codecov bot commented May 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.49%. Comparing base (28bc599) to head (121a9f9).
Report is 194 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8962      +/-   ##
==========================================
+ Coverage   89.82%   90.49%   +0.66%     
==========================================
  Files         412      419       +7     
  Lines       11878    12211     +333     
  Branches     2364     2385      +21     
==========================================
+ Hits        10670    11050     +380     
+ Misses        681      627      -54     
- Partials      527      534       +7     

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

Copy link
Member

@ScarletKuro ScarletKuro left a comment

Choose a reason for hiding this comment

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

Pretty simply solution, I like it.

src/MudBlazor.Docs.Compiler/TestsForApiPages.cs Outdated Show resolved Hide resolved
src/MudBlazor.Docs.Compiler/TestsForApiPages.cs Outdated Show resolved Hide resolved
src/MudBlazor.Docs.Compiler/TestsForApiPages.cs Outdated Show resolved Hide resolved
@henon henon changed the title Add support for specifying generic type parameters per component Tests: Add support for specifying generic type parameters per component and remove class T May 14, 2024
@henon henon merged commit 1f48b06 into MudBlazor:dev May 14, 2024
4 checks passed
@henon
Copy link
Collaborator

henon commented May 14, 2024

Perfect. I could have sworn that class T was also involved in the Docs api generator, but maybe I misremember. Anyhow, I am happy that it worked out so well. Thanks @ArieGato

@ArieGato
Copy link
Contributor Author

Perfect. I could have sworn that class T was also involved in the Docs api generator, but maybe I misremember. Anyhow, I am happy that it worked out so well. Thanks @ArieGato

@henon You're kind of right. There is another class T. I didn't remove it, because it is used in a lot of unit tests. Maybe that's the thing you remember.

@henon
Copy link
Collaborator

henon commented May 14, 2024

Ok, no problem, we'll deal with it later if necessary.

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

Successfully merging this pull request may close these issues.

Support code generation for Generic components with Type Constraint
3 participants