Skip to content

Commit

Permalink
[Readme]Add message for readme during validation (#8608)
Browse files Browse the repository at this point in the history
* add message for readme during validation & unit test
  • Loading branch information
lyndaidaii authored Jun 8, 2021
1 parent 820656c commit 17d0302
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ private DisplayPackageViewModel SetupInternal(
viewModel.ReadMeImagesRewritten = readmeResult != null ? readmeResult.ImagesRewritten : false;
viewModel.ReadmeImageSourceDisallowed = readmeResult != null ? readmeResult.ImageSourceDisallowed : false;
viewModel.HasEmbeddedIcon = package.HasEmbeddedIcon;
viewModel.HasEmbeddedReadmeFile = package.HasEmbeddedReadme;

return viewModel;
}
Expand Down
9 changes: 9 additions & 0 deletions src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,15 @@
)
}

if (Model.HasEmbeddedReadmeFile)
{
@ViewHelpers.AlertWarning(
@<text>
The readme will become available once package validation has completed successfully.
</text>
)
}

if (Model.ValidatingTooLong)
{
@ViewHelpers.AlertWarning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,58 @@ public void HasNewerReleaseDoesNotConsiderUnlistedVersions()
Assert.False(hasNewerRelease);
}

[Fact]
public void HasEmbeddedReadmeFileTrueIfPackageHasEmbeddedReadme()
{
var package = new Package
{
Key = 123,
Version = "1.0.0",
HasReadMe = true,
EmbeddedReadmeType = EmbeddedReadmeFileType.Markdown,
PackageRegistration = new PackageRegistration
{
Owners = Enumerable.Empty<User>().ToList(),
}
};

package.PackageRegistration.Packages = new[] { package };

var viewModel = CreateDisplayPackageViewModel(package, currentUser: null, packageKeyToDeprecation: null, readmeHtml: null);

//Act
var hasEmbeddedReadmeFile = viewModel.HasEmbeddedReadmeFile;

//Assert
Assert.True(hasEmbeddedReadmeFile);
}

[Fact]
public void HasEmbeddedReadmeFileFalseIfPackageHasLegacyReadme()
{
var package = new Package
{
Key = 123,
Version = "1.0.0",
HasReadMe = true,
EmbeddedReadmeType = EmbeddedReadmeFileType.Absent,
PackageRegistration = new PackageRegistration
{
Owners = Enumerable.Empty<User>().ToList(),
}
};

package.PackageRegistration.Packages = new[] { package };

var viewModel = CreateDisplayPackageViewModel(package, currentUser: null, packageKeyToDeprecation: null, readmeHtml: null);

//Act
var hasEmbeddedReadmeFile = viewModel.HasEmbeddedReadmeFile;

//Assert
Assert.False(hasEmbeddedReadmeFile);
}

private Package CreateTestPackage(string version, string dependencyVersion = null)
{
var package = new Package
Expand Down

0 comments on commit 17d0302

Please sign in to comment.