Skip to content

Commit

Permalink
Merge pull request #1 from applidium/feature/design_review
Browse files Browse the repository at this point in the history
Feature/design review
  • Loading branch information
Jurollet authored Jan 3, 2019
2 parents 8aa0c2d + cfb56e3 commit e7b27d4
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 5 deletions.
10 changes: 10 additions & 0 deletions XCTestHTMLReport/Scripts/createTemplates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
echo `pwd`
index=`cat XCTestHTMLReport/HTML/index.html | sed 's,",\\\\",g'`
testSummary=`cat XCTestHTMLReport/HTML/test_summary.html | sed 's,",\\\\",g'`
testDesignReview=`cat XCTestHTMLReport/HTML/test_design_review.html | sed 's,",\\\\",g'`
run=`cat XCTestHTMLReport/HTML/run.html | sed 's,",\\\\",g'`
device=`cat XCTestHTMLReport/HTML/device.html | sed 's,",\\\\",g'`
test=`cat XCTestHTMLReport/HTML/test.html | sed 's,",\\\\",g'`
activity=`cat XCTestHTMLReport/HTML/activity.html | sed 's,",\\\\",g'`
screenshot=`cat XCTestHTMLReport/HTML/screenshot.html | sed 's,",\\\\",g'`
text=`cat XCTestHTMLReport/HTML/text.html | sed 's,",\\\\",g'`
designReviewScreenshot=`cat XCTestHTMLReport/HTML/design_review_screenshot.html | sed 's,",\\\\",g'`

content="
/// DO NOT EDIT! This file is autogenerated by createTemplates.sh
Expand All @@ -30,6 +32,10 @@ $run
$testSummary
\"\"\"
static let testDesignReview = \"\"\"
$testDesignReview
\"\"\"
static let test = \"\"\"
$test
\"\"\"
Expand All @@ -45,6 +51,10 @@ $screenshot
static let text = \"\"\"
$text
\"\"\"
static let designReviewScreenshot = \"\"\"
$designReviewScreenshot
\"\"\"
}
"
echo "$content" > 'XCTestHTMLReport/Classes/HTMLTemplates.swift'
12 changes: 12 additions & 0 deletions XCTestHTMLReport/XCTestHTMLReport.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
F3B7EE701F2247FA00E19B57 /* TestSummary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3B7EE6F1F2247FA00E19B57 /* TestSummary.swift */; };
F3B7EE721F224A4200E19B57 /* Test.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3B7EE711F224A4200E19B57 /* Test.swift */; };
F3B7EE7E1F233B9C00E19B57 /* HTML.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3B7EE7D1F233B9C00E19B57 /* HTML.swift */; };
F707885621D3C48900E74BBB /* TestDesignReview.swift in Sources */ = {isa = PBXBuildFile; fileRef = F707885521D3C48900E74BBB /* TestDesignReview.swift */; };
F707885821D3C59E00E74BBB /* DesignReviewScreenshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = F707885721D3C59E00E74BBB /* DesignReviewScreenshot.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -97,6 +99,10 @@
F3B7EE711F224A4200E19B57 /* Test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Test.swift; sourceTree = "<group>"; };
F3B7EE7D1F233B9C00E19B57 /* HTML.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTML.swift; sourceTree = "<group>"; };
F3C058A01F25E74C00EF51E1 /* XCTestHTMLReport-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XCTestHTMLReport-Bridging-Header.h"; sourceTree = "<group>"; };
F707885521D3C48900E74BBB /* TestDesignReview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDesignReview.swift; sourceTree = "<group>"; };
F707885721D3C59E00E74BBB /* DesignReviewScreenshot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DesignReviewScreenshot.swift; sourceTree = "<group>"; };
F707885921D3CB2600E74BBB /* design_review_screenshot.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = design_review_screenshot.html; sourceTree = "<group>"; };
F707885A21D3CE2900E74BBB /* test_design_review.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = test_design_review.html; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -139,6 +145,8 @@
F30753F0209868460079C53E /* test_summary.html */,
F30753F1209868460079C53E /* test.html */,
F30753F2209868460079C53E /* device.html */,
F707885921D3CB2600E74BBB /* design_review_screenshot.html */,
F707885A21D3CE2900E74BBB /* test_design_review.html */,
);
path = HTML;
sourceTree = "<group>";
Expand Down Expand Up @@ -224,6 +232,8 @@
F3B7EE6D1F22449100E19B57 /* TargetDevice.swift */,
F3B7EE711F224A4200E19B57 /* Test.swift */,
F3B7EE6F1F2247FA00E19B57 /* TestSummary.swift */,
F707885521D3C48900E74BBB /* TestDesignReview.swift */,
F707885721D3C59E00E74BBB /* DesignReviewScreenshot.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -321,6 +331,7 @@
F3B7EE6E1F22449100E19B57 /* TargetDevice.swift in Sources */,
D980EDD4209123E400CABFE7 /* JUnitReport.swift in Sources */,
F3B7EE701F2247FA00E19B57 /* TestSummary.swift in Sources */,
F707885621D3C48900E74BBB /* TestDesignReview.swift in Sources */,
F3B7EE6C1F2242DC00E19B57 /* Summary.swift in Sources */,
F306675E1F2A1BEC00EDE682 /* BackgroundColor.swift in Sources */,
B12D2AA11FC69B0700DE78C6 /* NSData+GZIP.m in Sources */,
Expand All @@ -339,6 +350,7 @@
F353A1471F9B454D00E5A528 /* Run.swift in Sources */,
F30667641F2A1BEC00EDE682 /* Rainbow.swift in Sources */,
F30667551F2A1BE200EDE682 /* Style.swift in Sources */,
F707885821D3C59E00E74BBB /* DesignReviewScreenshot.swift in Sources */,
F30667651F2A1BEC00EDE682 /* String+Rainbow.swift in Sources */,
F3190E622098647300BC991B /* JUnitRepresentable.swift in Sources */,
F30667561F2A1BE200EDE682 /* XcodeColorsSupport.swift in Sources */,
Expand Down
61 changes: 59 additions & 2 deletions XCTestHTMLReport/XCTestHTMLReport/Classes/HTMLTemplates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,34 @@ struct HTMLTemplates
flex: 1;
}
#design-review {
display: none;
background-color: #F2F2F2;
flex: 1;
flex-direction: column;
overflow-y: scroll;
}
.design_review {
display: flex;
flex: 1;
flex-wrap: wrap;
}
.design_review_item {
display: flex;
flex: 1;
flex-direction: column;
align-items: center;
justify-content: space-evenly;
margin: auto;
padding: 16px;
}
.design_review_screenshot {
height: 600px;
}
.icon {
background-size: 14px 14px;
height: 14px;
Expand Down Expand Up @@ -533,6 +561,7 @@ struct HTMLTemplates
<ul id=\"test-log-toolbar\" class=\"toolbar centered-toolbar toggle-toolbar\">
<li class=\"selected\" onclick=\"showTests(this);\">Tests</li>
<li onclick=\"showLogs(this);\">Logs</li>
<li onclick=\"showDesignReview(this);\">Design Review</li>
</ul>
</header>
<div id=\"container\">
Expand Down Expand Up @@ -854,14 +883,26 @@ struct HTMLTemplates
function showLogs(el) {
selectedElement(el);
setDisplayToElementsWithSelector('#logs', 'flex');
setDisplayToElementsWithSelector('.tests', 'none');
setDisplayToElementsWithSelector('#logs', 'flex');
setDisplayToElementsWithSelector('#design-review', 'none');
setDisplayToElementsWithSelector('#right-sidebar', 'none');
}
function showTests(el) {
selectedElement(el);
setDisplayToElementsWithSelector('#logs', 'none');
setDisplayToElementsWithSelector('.tests', 'flex');
setDisplayToElementsWithSelector('#logs', 'none');
setDisplayToElementsWithSelector('#design-review', 'none');
setDisplayToElementsWithSelector('#right-sidebar', 'flex');
}
function showDesignReview(el) {
selectedElement(el);
setDisplayToElementsWithSelector('.tests', 'none');
setDisplayToElementsWithSelector('#logs', 'none');
setDisplayToElementsWithSelector('#design-review', 'flex');
setDisplayToElementsWithSelector('#right-sidebar', 'none');
}
document.querySelectorAll('.device-info')[0].classList.add(\"selected\");
Expand Down Expand Up @@ -905,6 +946,9 @@ struct HTMLTemplates
</div>
<iframe id=\"logs-iframe\" src=\"logs-[[DEVICE_IDENTIFIER]].txt\"></iframe>
</div>
<div id=\"design-review\">
[[TEST_DESIGN_REVIEW]]
</div>
</div>
"""

Expand All @@ -914,6 +958,12 @@ struct HTMLTemplates
</div>
"""

static let testDesignReview = """
<div class=\"design_review\" id=\"[[UUID]]\">
[[DESIGN_REVIEW_SCREENSHOTS]]
</div>
"""

static let test = """
<div class=\"[[ITEM_CLASS]] [[ICON_CLASS]] [[HAS_ACTIVITIES_CLASS]]\">
<span class=\"icon left test-result-icon\"></span>
Expand Down Expand Up @@ -962,5 +1012,12 @@ struct HTMLTemplates
<span class=\"icon preview-icon\" data=\"[[PATH]]/Attachments/[[FILENAME]]\" onclick=\"showText('[[PATH]]/Attachments/[[FILENAME]]')\"></span>
</p>
"""

static let designReviewScreenshot = """
<p class=\"design_review_item list-item\">
<img class=\"design_review_screenshot\" src=\"[[PATH]]/Attachments/[[FILENAME]]\" id=\"screenshot-[[FILENAME]]\" style=\"margin-bottom: 4px\" />
[[NAME]]
</p>
"""
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// DesignReviewScreenshot.swift
// XCTestHTMLReport
//
// Created by Julien Rollet on 26/12/2018.
// Copyright © 2018 Tito. All rights reserved.
//

import Foundation

struct DesignReviewScreenshot: HTML
{
private struct Constants {
static let defaultName = "kXCTAttachmentLegacyScreenImageData"
}

var filename: String
var path: String
var name: String?

init?(screenshotsPath: String, dict: [String : Any])
{
path = screenshotsPath
filename = dict["Filename"] as! String
name = dict["Name"] as? String

let typeRaw = dict["UniformTypeIdentifier"] as! String
guard isAllowed(typeRaw) else { return nil }
}

var fallbackDisplayName: String {
return "Screenshot"
}

var displayName: String {
guard let name = self.name else { return fallbackDisplayName }
return name
}

// PRAGMA MARK: - HTML

var htmlTemplate: String {
return HTMLTemplates.designReviewScreenshot
}

var htmlPlaceholderValues: [String: String] {
return [
"PATH": path,
"FILENAME": filename,
"NAME": displayName
]
}

// PRAGMA MARK: - Private

private func isAllowed(_ rawType: String) -> Bool {
return (rawType == "public.jpeg" || rawType == "public.png")
&& name != Constants.defaultName
}
}

8 changes: 7 additions & 1 deletion XCTestHTMLReport/XCTestHTMLReport/Classes/Models/Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct Run: HTML

var runDestination: RunDestination
var testSummaries: [TestSummary]
var testDesignReviews: [TestDesignReview]
var status: Status {
return testSummaries.reduce(true, { (accumulator: Bool, summary: TestSummary) -> Bool in
return accumulator && summary.status == .success
Expand Down Expand Up @@ -77,6 +78,7 @@ struct Run: HTML

let testableSummaries = dict!["TestableSummaries"] as! [[String: Any]]
testSummaries = testableSummaries.map { TestSummary(screenshotsPath: screenshotsPath, dict: $0) }
testDesignReviews = testableSummaries.map { TestDesignReview(screenshotsPath: screenshotsPath, dict: $0) }
runDestination.status = status

Logger.substep("Parsing Activity Logs")
Expand Down Expand Up @@ -143,7 +145,11 @@ struct Run: HTML
"N_OF_TESTS": String(numberOfTests),
"N_OF_PASSED_TESTS": String(numberOfPassedTests),
"N_OF_FAILED_TESTS": String(numberOfFailedTests),
"TEST_SUMMARIES": testSummaries.map { $0.html }.joined()
"TEST_SUMMARIES": testSummaries.map { $0.html }.joined(),
"TEST_DESIGN_REVIEW": testDesignReviews.compactMap {
guard !$0.screenshots.isEmpty else { return nil }
return $0.html
}.joined()
]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// TestDesignReview.swift
// XCTestHTMLReport
//
// Created by Julien Rollet on 26/12/2018.
// Copyright © 2018 Tito. All rights reserved.
//

import Foundation

struct TestDesignReview: HTML
{
let uuid: String
let screenshotsPath: String
var screenshots: [DesignReviewScreenshot]

init(screenshotsPath: String, dict: [String : Any])
{
uuid = NSUUID().uuidString
self.screenshotsPath = screenshotsPath
screenshots = []
screenshots.append(contentsOf: populateScreenshots(from: dict))
}

// PRAGMA MARK: - HTML

var htmlTemplate = HTMLTemplates.testDesignReview

var htmlPlaceholderValues: [String: String] {
return [
"UUID": uuid,
"DESIGN_REVIEW_SCREENSHOTS": screenshots.map { $0.html }.joined(),
]
}

// PRAGMA MARK: - Private

private func populateScreenshots(from dict: [String : Any]) -> [DesignReviewScreenshot] {
let rawTests = dict["Tests"] as! [[String: Any]]
var allScreenshots = reduceIntoScreenshots(
rawTests, exploringFunction: self.extractScreenshots(from:)
)
allScreenshots.sort {
$0.displayName.compare($1.displayName, options: .numeric) == .orderedAscending
}
return allScreenshots
}

private func extractScreenshots(from dict: [String: Any]) -> [DesignReviewScreenshot] {
var extractedScreenshots: [DesignReviewScreenshot] = []

if let rawSubTests = dict["Subtests"] as? [[String : Any]] {
let subTestsScreenshots = reduceIntoScreenshots(
rawSubTests, exploringFunction: self.extractScreenshots(from:)
)
extractedScreenshots.append(contentsOf: subTestsScreenshots)
}

if let rawActivities = dict["ActivitySummaries"] as? [[String : Any]] {
let activitiesScreenshots = reduceIntoScreenshots(
rawActivities, exploringFunction: self.extractScreenshots(fromActivity:)
)
extractedScreenshots.append(contentsOf: activitiesScreenshots)
}
return extractedScreenshots
}

private func extractScreenshots(fromActivity activity: [String: Any]) -> [DesignReviewScreenshot] {
var extractedScreenshots: [DesignReviewScreenshot] = []

if let rawAttachments = activity["Attachments"] as? [[String : Any]] {
let screenshots = rawAttachments.compactMap {
DesignReviewScreenshot(screenshotsPath: screenshotsPath, dict: $0)
}
extractedScreenshots.append(contentsOf: screenshots)
}

if let rawSubActivities = activity["SubActivities"] as? [[String : Any]] {
let subActivitiesScreenshots = reduceIntoScreenshots(
rawSubActivities, exploringFunction: self.extractScreenshots(fromActivity:)
)
extractedScreenshots.append(contentsOf: subActivitiesScreenshots)
}
return extractedScreenshots
}

private func reduceIntoScreenshots(_ dicts: [[String : Any]],
exploringFunction: ([String : Any]) -> [DesignReviewScreenshot]) -> [DesignReviewScreenshot] {
return dicts.reduce([]) {
var accumulatedScreenshots: [DesignReviewScreenshot] = []
accumulatedScreenshots.append(contentsOf: $0)
accumulatedScreenshots.append(contentsOf: exploringFunction($1))
return accumulatedScreenshots
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p class="design_review_item list-item">
<img class="design_review_screenshot" src="[[PATH]]/Attachments/[[FILENAME]]" id="screenshot-[[FILENAME]]" style="margin-bottom: 4px" />
[[NAME]]
</p>
Loading

0 comments on commit e7b27d4

Please sign in to comment.