Skip to content

Commit ed51452

Browse files
author
Daniel Jacinto
authored
stop showing tfm when package is deleted or template. (#8992)
1 parent 1be0e13 commit ed51452

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

src/NuGetGallery/ViewModels/DisplayPackageViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ public bool CanDisplayFuGetLink()
141141
return IsFuGetLinksEnabled && !string.IsNullOrEmpty(FuGetUrl) && Available;
142142
}
143143

144+
public bool CanDisplayTargetFrameworks()
145+
{
146+
return IsDisplayTargetFrameworkEnabled && !Deleted && !IsDotnetNewTemplatePackageType;
147+
}
148+
144149
public bool BlockSearchEngineIndexing
145150
{
146151
get

src/NuGetGallery/Views/Packages/DisplayPackage.cshtml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265
</h1>
266266
</div>
267267

268-
@if (Model.IsDisplayTargetFrameworkEnabled)
268+
@if (Model.CanDisplayTargetFrameworks())
269269
{
270270
@Html.Partial("_SupportedFrameworksBadges", Model.PackageFrameworkCompatibility.Badges);
271271
}
@@ -523,7 +523,7 @@
523523
</a>
524524
</li>
525525

526-
if (!Model.Deleted && Model.IsDisplayTargetFrameworkEnabled)
526+
if (Model.CanDisplayTargetFrameworks())
527527
{
528528
activeBodyTab = activeBodyTab ?? "supportedframeworks";
529529
<li role="presentation" id="show-supportedframeworks-container">
@@ -644,8 +644,10 @@
644644
}
645645
</div>
646646

647+
if (Model.CanDisplayTargetFrameworks())
648+
{
647649
<div role="tabpanel" class="tab-pane @(activeBodyTab == "supportedframeworks" ? "active" : "")" id="supportedframeworks-tab">
648-
@if (Model.IsDisplayTargetFrameworkEnabled && Model.PackageFrameworkCompatibility.Table.Count > 0)
650+
@if (Model.PackageFrameworkCompatibility.Table.Count > 0)
649651
{
650652
@Html.Partial("_SupportedFrameworksTable", Model.PackageFrameworkCompatibility.Table)
651653
}
@@ -655,6 +657,7 @@
655657
<p class="frameworktableinfo-text"><i>Learn more about <a href='https://docs.microsoft.com/dotnet/standard/frameworks' aria-label="Learn more about Target Frameworks">Target Frameworks</a> and <a href='https://docs.microsoft.com/dotnet/standard/net-standard' aria-label="Learn more about .NET Standard">.NET Standard</a>.</i></p>
656658
}
657659
</div>
660+
}
658661

659662
<div role="tabpanel" class="tab-pane @(activeBodyTab == "dependencies" ? "active" : "")" id="dependencies-tab">
660663
@if (!Model.Deleted)

tests/NuGetGallery.Facts/ViewModels/DisplayPackageViewModelFacts.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,61 @@ public void CannotDisplayFuGetLinkWhenInvalid(bool isEnabled, string url, bool i
290290
Assert.False(model.CanDisplayFuGetLink());
291291
}
292292

293+
[Theory]
294+
[InlineData(true, true, true)]
295+
[InlineData(false, true, true)]
296+
[InlineData(true, false, true)]
297+
[InlineData(true, true, false)]
298+
[InlineData(false, false, true)]
299+
[InlineData(false, true, false)]
300+
[InlineData(false, false, false)]
301+
public void CannotDisplayTargetFrameworksWhenInvalid(bool isEnabled, bool isDeleted, bool isTemplate)
302+
{
303+
var package = new Package
304+
{
305+
Version = "1.0.0",
306+
NormalizedVersion = "1.0.0",
307+
PackageRegistration = new PackageRegistration
308+
{
309+
Id = "foo",
310+
Owners = Enumerable.Empty<User>().ToList(),
311+
Packages = Enumerable.Empty<Package>().ToList()
312+
}
313+
};
314+
315+
var model = CreateDisplayPackageViewModel(package, currentUser: null, packageKeyToDeprecation: null, readmeHtml: null);
316+
317+
model.IsDisplayTargetFrameworkEnabled = isEnabled;
318+
model.Deleted = isDeleted;
319+
model.IsDotnetNewTemplatePackageType = isTemplate;
320+
321+
Assert.False(model.CanDisplayTargetFrameworks());
322+
}
323+
324+
[Fact]
325+
public void CanDisplayTargetFrameworksWhenValid()
326+
{
327+
var package = new Package
328+
{
329+
Version = "1.0.0",
330+
NormalizedVersion = "1.0.0",
331+
PackageRegistration = new PackageRegistration
332+
{
333+
Id = "foo",
334+
Owners = Enumerable.Empty<User>().ToList(),
335+
Packages = Enumerable.Empty<Package>().ToList()
336+
}
337+
};
338+
339+
var model = CreateDisplayPackageViewModel(package, currentUser: null, packageKeyToDeprecation: null, readmeHtml: null);
340+
341+
model.IsDisplayTargetFrameworkEnabled = true;
342+
model.Deleted = false;
343+
model.IsDotnetNewTemplatePackageType = false;
344+
345+
Assert.True(model.CanDisplayTargetFrameworks());
346+
}
347+
293348
[Theory]
294349
[InlineData(null, null)]
295350
[InlineData("not a url", null)]

0 commit comments

Comments
 (0)