Skip to content

Commit

Permalink
fix bug in request reviewers (#5578)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu authored Feb 28, 2023
1 parent 8f65722 commit 003d2d3
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 61 deletions.
88 changes: 69 additions & 19 deletions src/dotnet/APIView/APIViewUITests/SmokeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ public SmokeTestsFixture()
_ = _blobOriginalContainerClient.CreateIfNotExistsAsync(PublicAccessType.BlobContainer);
_ = _blobUsageSampleRepository.CreateIfNotExistsAsync(PublicAccessType.BlobContainer);
_ = _blobCommentsRepository.CreateIfNotExistsAsync(PublicAccessType.BlobContainer);

// Upload Reviews Automatically
var cSharpFileName = $"azure.identity.1.9.0-beta.1.nupkg";
var cSharpFilePath = Path.Combine(_testPkgsPath, cSharpFileName);
Task.Run(() => SubmitAPIReview(cSharpFileName, cSharpFilePath, this._uri, "Auto Review - Test")).Wait();
}

private async Task SubmitAPIReview(string packageName, string filePath, string uri, string apiLabel)
{
using (var multiPartFormData = new MultipartFormDataContent())
{
var fileInfo = new FileInfo(filePath);
var fileStreamContent = new StreamContent(File.OpenRead(filePath));
fileStreamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
multiPartFormData.Add(fileStreamContent, name: "file", fileName: packageName);
var stringContent = new StringContent(apiLabel);
multiPartFormData.Add(stringContent, name: "label");

var response = await _httpClient.PostAsync(uri, multiPartFormData);
response.EnsureSuccessStatusCode();
}
}

public void Dispose()
Expand All @@ -73,6 +94,7 @@ public void Dispose()
_blobCommentsRepository.DeleteIfExists();
}
}

public class SmokeTests : IClassFixture<SmokeTestsFixture>
{
SmokeTestsFixture _fixture;
Expand All @@ -89,8 +111,6 @@ public async Task SmokeTest_CSharp()
var pkgName = "azure.identity";
var fileAName = $"{pkgName}.1.8.0.nupkg";
var fileAPath = Path.Combine(_fixture._testPkgsPath, fileAName);
var fileBName = $"{pkgName}.1.9.0-beta.1.nupkg";
var fileBPath = Path.Combine(_fixture._testPkgsPath, fileBName);

// Test Manual Upload
using (IWebDriver driver = new ChromeDriver())
Expand All @@ -110,7 +130,6 @@ public async Task SmokeTest_CSharp()
}

// Test Auto Upload
await SubmitAPIReview(fileBName, fileBPath, _fixture._uri, "Auto Review - Test");
using (IWebDriver driver = new ChromeDriver())
{
driver.Manage().Window.Maximize();
Expand Down Expand Up @@ -144,28 +163,59 @@ public async Task SmokeTest_CSharp()
}
}

private void PageErrorAssertion(IWebDriver driver)
{
Assert.NotEqual("Error - apiview.dev", driver.Title);
Assert.NotEqual("Internal Server Error", driver.Title);
}

private async Task SubmitAPIReview(string packageName, string filePath, string uri, string apiLabel)
[Fact]
public async Task SmokeTest_Request_Reviewers()
{
using (var multiPartFormData = new MultipartFormDataContent())
using (IWebDriver driver = new ChromeDriver())
{
var fileInfo = new FileInfo(filePath);
var fileStreamContent = new StreamContent(File.OpenRead(filePath));
fileStreamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
multiPartFormData.Add(fileStreamContent, name: "file", fileName: packageName);
var stringContent = new StringContent(apiLabel);
multiPartFormData.Add(stringContent, name: "label");
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(WaitTime);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(WaitTime);
driver.Navigate().GoToUrl(_fixture._endpoint);

var response = await _fixture._httpClient.PostAsync(uri, multiPartFormData);
response.EnsureSuccessStatusCode();
// Select C# language
var languageSelector = driver.FindElement(By.Id("language-filter-select"));
var languageSelectElement = new SelectElement(languageSelector);
languageSelectElement.SelectByText("C#");
var reviewNames = driver.FindElements(By.ClassName("review-name"));
Assert.Equal("Reviews - apiview.dev", driver.Title);

reviewNames[0].Click();
PageErrorAssertion(driver);

var requestReviewersCollapse = driver.FindElement(By.Id("requestReviewersCollapse"));
if (!requestReviewersCollapse.GetAttribute("class").Contains(" show"))
{
var requestReviewersCollapseTrigger = driver.FindElement(By.XPath("//a[@href='#requestReviewersCollapse']"));
requestReviewersCollapseTrigger.Click();
}

var possibleReviwers = driver.FindElements(By.XPath("//ul[@id='requestReviewersCollapse']/form/li/ul/li[@class='list-group-item']/div/input"));

foreach(var reviewer in possibleReviwers)
{
Assert.False(reviewer.Selected);
reviewer.Click();
Assert.True(reviewer.Selected);
}

driver.FindElement(By.Id("submitReviewRequest")).Click();
driver.Navigate().Refresh();

possibleReviwers = driver.FindElements(By.XPath("//ul[@id='requestReviewersCollapse']/form/li/ul/li[@class='list-group-item']/div/input"));
foreach (var reviewer in possibleReviwers)
{
Assert.True(reviewer.Selected);
}
}
}

private void PageErrorAssertion(IWebDriver driver)
{
Assert.NotEqual("Error - apiview.dev", driver.Title);
Assert.NotEqual("Internal Server Error", driver.Title);
}

[Fact(Skip = "Test is too Flaky")]
public void ReviewFilterOptionsWorkWithoutErrors()
{
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ $(() => {

/* BUTTON FOR REQUEST REVIEW (CHANGES BETWEEN REQUEST ALL AND REQUEST SELECTED IN THE REQUEST APPROVAL SECTION)
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
$('.selectDropdownForRequest').on("click", function () {
$('.selectReviewerForRequest').on("click", function () {
var reviewers = document.getElementsByName('reviewers');
var button = document.getElementById('submitReviewRequest') as HTMLInputElement | null;
var anyChecked = false;
Expand Down
82 changes: 41 additions & 41 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -160,49 +160,49 @@
@{
var anyChecked = false;
}
<li class="list-group-item">
<form asp-resource="@Model.Review" asp-page-handler="RequestReviewers" method="post">
<ul class="list-group list-group-flush">
@foreach (var approver in Model.PreferredApprovers)
<form asp-resource="@Model.Review" asp-page-handler="RequestReviewers" method="post">
<li class="list-group-item">

<ul class="list-group list-group-flush">
@foreach (var approver in Model.PreferredApprovers)
{
<li class="list-group-item">
<div class="form-check">
@if (Model.Review.RequestedReviewers != null && Model.Review.RequestedReviewers.Contains(approver))
{
<input class="form-check-input selectReviewerForRequest" type="checkbox" name="reviewers" value="@approver" id="@(approver)CheckBox" checked>
<label class="form-check-label" for="@(approver)CheckBox">
<img username="@approver" size="28" width="28" class="comment-icon align-self-start mr-2" />
@approver
</label>
anyChecked = true;
}
else
{
<input class="form-check-input selectReviewerForRequest" type="checkbox" name="reviewers" value="@approver" id="@(approver)CheckBox">
<label class="form-check-label" for="@(approver)CheckBox">
<img username="@approver" size="28" width="28" class="comment-icon align-self-start mr-2" />
@approver
</label>
}
</div>
</li>
}
</ul>
<li class="list-group-item">
<span>
@if (anyChecked)
{
<li class="list-group-item">
<div class="form-check">
@if (Model.Review.RequestedReviewers != null && Model.Review.RequestedReviewers.Contains(approver))
{
<input class="form-check-input selectDropdownForRequest" type="checkbox" name="reviewers" value="@approver" id="@(approver)CheckBox" checked>
<label class="form-check-label" for="@(approver)CheckBox">
<img username="@approver" size="28" width="28" class="comment-icon align-self-start mr-2" />
@approver
</label>
anyChecked = true;
}
else
{
<input class="form-check-input selectDropdownForRequest" type="checkbox" name="reviewers" value="@approver" id="@(approver)CheckBox">
<label class="form-check-label" for="@(approver)CheckBox">
<img username="@approver" size="28" width="28" class="comment-icon align-self-start mr-2" />
@approver
</label>
}
</div>
</li>
<button class="btn btn-sm btn-outline-primary" id="submitReviewRequest" onclick="document.getElementById('submitRequestForReview').click()" disabled>Request Selected</button>
}
</ul>
</form>
</li>
<li class="list-group-item">
<span>
@if (anyChecked)
{
<button class="btn btn-sm btn-outline-primary" id="submitReviewRequest" onclick="document.getElementById('submitRequestForReview').click()" disabled>Request Selected</button>
}
else
{
<button class="btn btn-sm btn-outline-primary" id="submitReviewRequest" onclick="var r = document.getElementsByName('reviewers'); r.forEach((e) => e.checked = true); document.getElementById('submitRequestForReview').click();">Request All</button>
}
<button type="submit" id="submitRequestForReview" hidden></button>
</span>
</li>
else
{
<button class="btn btn-sm btn-outline-primary" id="submitReviewRequest" onclick="var r = document.getElementsByName('reviewers'); r.forEach((e) => e.checked = true); document.getElementById('submitRequestForReview').click();">Request All</button>
}
<button type="submit" id="submitRequestForReview" hidden></button>
</span>
</li>
</form>
</ul>
@if (Model.Review.FilterType == ReviewType.PullRequest)
{
Expand Down

0 comments on commit 003d2d3

Please sign in to comment.