forked from WeTransfer/Diagnostics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTMLGeneratingTests.swift
54 lines (45 loc) · 1.97 KB
/
HTMLGeneratingTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// HTMLGeneratingTests.swift
// DiagnosticsTests
//
// Created by Antoine van der Lee on 02/12/2019.
// Copyright © 2019 WeTransfer. All rights reserved.
//
import XCTest
@testable import Diagnostics
final class HTMLGeneratingTests: XCTestCase {
/// It should generate HTML for diagnostic chapters correctly.
func testDiagnosticsChapterHTML() {
let chapter = DiagnosticsChapter(title: "TITLE", diagnostics: "CONTENT")
let expectedHTML = "<div class=\"chapter\"><span class=\"anchor\" id=\"\(chapter.title.lowercased())\"></span><h3>\(chapter.title)</h3><div class=\"chapter-content\">\(chapter.diagnostics.html())</div></div>"
XCTAssertEqual(chapter.html(), expectedHTML)
}
/// It should correctly transform a Dictionary to HTML.
func testDictionaryHTML() {
let dict = ["App Name": "Collect by WeTransfer"]
let expectedHTML = "<table><tr><th>\(dict.keys.first!)</th><td>\(dict.values.first!)</td></tr></table>"
XCTAssertEqual(dict.html(), expectedHTML)
}
/// It should correctly transform a Dictionary to HTML.
func testKeyValuePairsHTML() {
let dict: KeyValuePairs<String, String> = ["App Name": "Collect by WeTransfer"]
let expectedHTML = "<table><tr><th>\(dict.first!.key)</th><td>\(dict.first!.value)</td></tr></table>"
XCTAssertEqual(dict.html(), expectedHTML)
}
/// It should correctly transform a String to HTML.
func testStringHTML() {
let value = "CONTENT"
let expectedHTML = "CONTENT"
XCTAssertEqual(value.html(), expectedHTML)
}
/// It should use a custom formatter if set.
func testCustomFormatter() {
let chapter = DiagnosticsChapter(title: UUID().uuidString, diagnostics: UUID().uuidString, formatter: MockHTMLFormatter.self)
XCTAssertTrue(chapter.html().contains("MOCKED"))
}
}
struct MockHTMLFormatter: HTMLFormatting {
static func format(_ diagnostics: Diagnostics) -> HTML {
return "MOCKED"
}
}