From f34d35193c22bd0bab38b5befe4160966898ca67 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Mon, 27 Feb 2023 17:02:45 -0800 Subject: [PATCH] fix bug in request reviewers --- .../APIView/APIViewUITests/SmokeTests.cs | 88 +++++++++++++++---- .../APIViewWeb/Client/src/pages/review.ts | 2 +- .../APIViewWeb/Pages/Assemblies/Review.cshtml | 82 ++++++++--------- 3 files changed, 111 insertions(+), 61 deletions(-) diff --git a/src/dotnet/APIView/APIViewUITests/SmokeTests.cs b/src/dotnet/APIView/APIViewUITests/SmokeTests.cs index 1d026428680..8e7daacde73 100644 --- a/src/dotnet/APIView/APIViewUITests/SmokeTests.cs +++ b/src/dotnet/APIView/APIViewUITests/SmokeTests.cs @@ -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() @@ -73,6 +94,7 @@ public void Dispose() _blobCommentsRepository.DeleteIfExists(); } } + public class SmokeTests : IClassFixture { SmokeTestsFixture _fixture; @@ -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()) @@ -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(); @@ -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() { diff --git a/src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts b/src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts index ff038c28176..9f26df53f60 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts +++ b/src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts @@ -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; diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml index 8528f9d4bc2..c0e64b2f837 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml @@ -160,49 +160,49 @@ @{ var anyChecked = false; } -
  • -
    -
      - @foreach (var approver in Model.PreferredApprovers) + +
    • + +
        + @foreach (var approver in Model.PreferredApprovers) + { +
      • +
        + @if (Model.Review.RequestedReviewers != null && Model.Review.RequestedReviewers.Contains(approver)) + { + + + anyChecked = true; + } + else + { + + + } +
        +
      • + } +
      +
    • + + @if (anyChecked) { -
    • -
      - @if (Model.Review.RequestedReviewers != null && Model.Review.RequestedReviewers.Contains(approver)) - { - - - anyChecked = true; - } - else - { - - - } -
      -
    • + } -
    -
    -
  • -
  • - - @if (anyChecked) - { - - } - else - { - - } - - -
  • + else + { + + } + + + + @if (Model.Review.FilterType == ReviewType.PullRequest) {