forked from XCTestHTMLReport/XCTestHTMLReport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from applidium/feature/design_review
Feature/design review
- Loading branch information
Showing
10 changed files
with
298 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
XCTestHTMLReport/XCTestHTMLReport/Classes/Models/DesignReviewScreenshot.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
XCTestHTMLReport/XCTestHTMLReport/Classes/Models/TestDesignReview.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
XCTestHTMLReport/XCTestHTMLReport/HTML/design_review_screenshot.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.