Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit 1ae5779

Browse files
committed
Add filters to test results list in VisualAssertion.Dashboard #8
- add filter by status
1 parent c4d3282 commit 1ae5779

File tree

9 files changed

+114
-24
lines changed

9 files changed

+114
-24
lines changed

Src/VisualAssertions.Dashboard/Content/sb-admin/css/sb-admin.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,8 @@ ul.alert-dropdown {
224224

225225
.panel-yellow > a:hover {
226226
color: #df8a13;
227+
}
228+
229+
.top-offset {
230+
margin-top: 20px;
227231
}

Src/VisualAssertions.Dashboard/Controllers/HomeController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public ActionResult GetTestsFromSessionSession(long sessionId, string browserNam
3333
return View("TestResultList", tests);
3434
}
3535

36+
public ActionResult GetTestsFromSessionInStatus(long sessionId, string browserName, TestResultStatus status)
37+
{
38+
var tests = this.testResultService.GetTestsFromSessionInStatus(sessionId, browserName, status);
39+
return View("TestResultsInStatus", tests);
40+
}
41+
3642
public ActionResult GetTestResult(long testId)
3743
{
3844
var test = this.testResultService.GetTestResult(testId);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Tellurium.VisualAssertions.Infrastructure;
5+
using Tellurium.VisualAssertions.Screenshots.Domain;
6+
7+
namespace Tellurium.VisualAssertions.Dashboard.Services.TestResults.Queries
8+
{
9+
public class FindTestResultsFromSession : IQueryAll<TestResult>
10+
{
11+
private readonly long sessionId;
12+
private readonly string browserName;
13+
private readonly TestResultStatus resultStatus;
14+
15+
public FindTestResultsFromSession(long sessionId, string browserName, TestResultStatus resultStatus)
16+
{
17+
this.sessionId = sessionId;
18+
this.browserName = browserName;
19+
this.resultStatus = resultStatus;
20+
}
21+
22+
public List<TestResult> GetQuery(IQueryable<TestResult> query)
23+
{
24+
var testFromSession = query.Where(x=>x.TestSession.Id == sessionId)
25+
.Where(x=>x.BrowserName == browserName);
26+
27+
switch (resultStatus)
28+
{
29+
case TestResultStatus.All:
30+
return testFromSession.ToList();
31+
case TestResultStatus.Passed:
32+
return testFromSession.Where(x=>x.TestPassed).ToList();
33+
case TestResultStatus.Failed:
34+
return testFromSession.Where(x => x.TestPassed == false).ToList();
35+
default:
36+
throw new ArgumentOutOfRangeException();
37+
}
38+
}
39+
}
40+
}

Src/VisualAssertions.Dashboard/Services/TestResults/TestResultService.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ public Bitmap GetScreenshot(long testId, ScreenshotType screenshotType)
8787

8888
public TestResultListViewModel GetTestsFromSession(long sessionId, string browserName)
8989
{
90-
var testSession = this.testSessionRepository.Get(sessionId);
91-
var testResults = testSession.TestResults.Where(x => x.BrowserName == browserName).ToList();
90+
var query = new FindTestResultsFromSession(sessionId, browserName, TestResultStatus.All);
91+
var testResults = this.testRepository.FindAll(query);
92+
var failedCount = testResults.Count(x => x.TestPassed == false);
9293
return new TestResultListViewModel()
9394
{
94-
TestSessionId = testSession.Id,
95+
AllCount = testResults.Count,
96+
FailedCount = failedCount,
97+
PassedCount = testResults.Count-failedCount,
98+
TestSessionId = sessionId,
9599
BrowserName = browserName,
96100
TestResults = testResults.ConvertAll(MapToTestResultListItemDTO)
97101
};
@@ -154,6 +158,16 @@ public TestResultListItemDTO GetTestResultPreview(long testSessionId, long patte
154158
var testResult = this.testRepository.FindOne(query);
155159
return MapToTestResultListItemDTO(testResult);
156160
}
161+
162+
public TestResultsInStatusViewModel GetTestsFromSessionInStatus(long sessionId, string browserName, TestResultStatus status)
163+
{
164+
var query = new FindTestResultsFromSession(sessionId, browserName, status);
165+
var testResults = this.testRepository.FindAll(query);
166+
return new TestResultsInStatusViewModel()
167+
{
168+
TestResults = testResults.ConvertAll(MapToTestResultListItemDTO)
169+
};
170+
}
157171
}
158172

159173
public interface ITestResultService
@@ -167,6 +181,7 @@ public interface ITestResultService
167181
ProjectListViewModel GetProjectsList();
168182
TestResultDetailsViewModel GetTestResultDetails(long testResultId);
169183
TestResultListItemDTO GetTestResultPreview(long testSessionId, long patternId);
184+
TestResultsInStatusViewModel GetTestsFromSessionInStatus(long sessionId, string browserName, TestResultStatus status);
170185
}
171186

172187
public enum ScreenshotType
@@ -182,11 +197,26 @@ public class TestResultDetailsViewModel
182197
public bool TestPassed { get; set; }
183198
}
184199

200+
public enum TestResultStatus
201+
{
202+
All,
203+
Passed,
204+
Failed
205+
}
206+
185207
public class TestResultListViewModel
186208
{
187209
public List<TestResultListItemDTO> TestResults { get; set; }
188210
public long TestSessionId { get; set; }
189211
public string BrowserName { get; set; }
212+
public int AllCount { get; set; }
213+
public int PassedCount { get; set; }
214+
public int FailedCount { get; set; }
215+
}
216+
217+
public class TestResultsInStatusViewModel
218+
{
219+
public List<TestResultListItemDTO> TestResults { get; set; }
190220
}
191221

192222
public class TestResultListItemDTO

Src/VisualAssertions.Dashboard/Views/Home/TestResultInfo.cshtml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
<div class="panel @rowClass test-row" id="@rowId">
1111
<div class="panel-heading ">
1212
<div class="row">
13-
<div class="col-md-10 test-row-expander" @widget.GetAttributeString()>
13+
<div class="col-md-9 test-row-expander" @widget.GetAttributeString()>
1414
<span class="glyphicon glyphicon-menu-right"></span>
1515
@Model.ScreenshotName
1616
</div>
17-
<div class="col-md-2">
18-
@(Html.ActionLink<TestCaseController>(c=>c.GetTestCase(Model.TestCaseId),"Edit pattern", new { @class = "btn btn-primary" }))
19-
@if (Model.CanShowMarkAsPattern)
20-
{
21-
@(Ajax.ChangeActionLink<HomeController>(c => c.MarkAsPattern(Model.TestResultId), "Mark as pattern", "Do you really want to mark this as pattern?", rowId, new {@class = "btn btn-primary"}))
22-
}
17+
<div class="col-md-3">
18+
<div class="pull-right">
19+
@(Html.ActionLink<TestCaseController>(c => c.GetTestCase(Model.TestCaseId), "Edit pattern", new { @class = "btn btn-primary" }))
20+
@if (Model.CanShowMarkAsPattern)
21+
{
22+
@(Ajax.ChangeActionLink<HomeController>(c => c.MarkAsPattern(Model.TestResultId), "Mark as pattern", "Do you really want to mark this as pattern?", rowId, new { @class = "btn btn-primary" }))
23+
}
24+
</div>
2325
</div>
2426
</div>
2527
</div>

Src/VisualAssertions.Dashboard/Views/Home/TestResultList.cshtml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
ViewBag.Title = "Tests Results";
77
Layout = "~/Views/_Layout.cshtml";
88
}
9-
10-
<div class="row">
11-
<div class="col-md-12">
9+
<div class="container-fluid">
10+
<div class="row">
11+
@(Ajax.ActionLink<HomeController>(c => c.GetTestsFromSessionInStatus(Model.TestSessionId, Model.BrowserName, TestResultStatus.All), "All tests: " +Model.AllCount, "TestResultsList", new { @class = "btn btn-primary" }))
12+
@(Ajax.ActionLink<HomeController>(c => c.GetTestsFromSessionInStatus(Model.TestSessionId, Model.BrowserName, TestResultStatus.Passed), "Passed tests: "+Model.PassedCount, "TestResultsList", new { @class = "btn btn-success" }))
13+
@(Ajax.ActionLink<HomeController>(c => c.GetTestsFromSessionInStatus(Model.TestSessionId, Model.BrowserName, TestResultStatus.Failed), "Failed tests: "+Model.FailedCount, "TestResultsList", new { @class = "btn btn-danger" }))
14+
</div>
15+
<div class="row">
1216
@(Ajax.ChangeActionLink<HomeController>(c => c.MarkAllAsPattern(Model.TestSessionId, Model.BrowserName), "Mark all as pattern", "Do you really want to replace patter for all cases?", htmlAttributes: new { @class = "btn btn-primary pull-right" }))
1317
</div>
18+
<div id="TestResultsList" class="row top-offset">
19+
@foreach (var testResultInfo in Model.TestResults)
20+
{
21+
Html.RenderPartial("TestResultInfo", testResultInfo);
22+
}
23+
</div>
24+
1425
</div>
15-
@foreach (var testResultInfo in Model.TestResults)
16-
{
17-
Html.RenderPartial("TestResultInfo", testResultInfo);
18-
}
19-
20-
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@model TestResultsInStatusViewModel
2+
3+
@foreach (var testResultInfo in Model.TestResults)
4+
{
5+
Html.RenderPartial("TestResultInfo", testResultInfo);
6+
}

Src/VisualAssertions.Dashboard/Views/_Layout.cshtml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,6 @@
296296
<h1 class="page-header">
297297
Dashboard <small>@ViewBag.Title</small>
298298
</h1>
299-
<ol class="breadcrumb">
300-
<li class="active">
301-
<i class="fa fa-dashboard"></i> Dashboard
302-
</li>
303-
</ol>
304299
</div>
305300
</div>
306301
<!-- /.row -->

Src/VisualAssertions.Dashboard/VisualAssertions.Dashboard.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
<Compile Include="Models\Home\BrowserPatternDTO.cs" />
197197
<Compile Include="Services\TestCase\TestCaseService.cs" />
198198
<Compile Include="Services\TestResults\Queries\FindTestResultForPatternInSession.cs" />
199+
<Compile Include="Services\TestResults\Queries\FindTestResultsFromSession.cs" />
199200
<Compile Include="Services\TestResults\TestCaseCategoriesListViewModel.cs" />
200201
<Compile Include="Services\TestResults\TestResultService.cs" />
201202
<Compile Include="Global.asax.cs">
@@ -264,6 +265,7 @@
264265
<Content Include="Views\TestCase\CategoriesList.cshtml" />
265266
<Content Include="Views\Home\TestResultInfoPreloaded.cshtml" />
266267
<Content Include="Views\TestCase\TestCase.cshtml" />
268+
<Content Include="Views\Home\TestResultsInStatus.cshtml" />
267269
<None Include="Web.Debug.config">
268270
<DependentUpon>Web.config</DependentUpon>
269271
</None>

0 commit comments

Comments
 (0)