Skip to content

Commit addc235

Browse files
committed
Add a test for initializing DownView with a custom template bundle
1 parent b043c74 commit addc235

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

Down.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
8AFAEB071E6E331700E09B68 /* DownViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D41689B21CFFE28200E5802B /* DownViewTests.swift */; };
6565
8AFAEB081E6E331700E09B68 /* NSAttributedStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4F948DB1D00A4A800C9C0F6 /* NSAttributedStringTests.swift */; };
6666
8AFAEB091E6E331700E09B68 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D438696B1D00D27700E95A1F /* StringTests.swift */; };
67+
907C64651EC133780095FEE1 /* TestDownView.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 907C64621EC120530095FEE1 /* TestDownView.bundle */; };
6768
90A40A9C1EC03292004F2E91 /* Down.framework in Copy Bundled Frameworks */ = {isa = PBXBuildFile; fileRef = 8A569F401E6B3E50008BE2AC /* Down.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
6869
/* End PBXBuildFile section */
6970

@@ -94,6 +95,7 @@
9495
/* Begin PBXFileReference section */
9596
8A569F401E6B3E50008BE2AC /* Down.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Down.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9697
8AFAEAFB1E6E32E900E09B68 /* DownTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DownTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
98+
907C64621EC120530095FEE1 /* TestDownView.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = TestDownView.bundle; sourceTree = "<group>"; };
9799
90A40A951EC02FF6004F2E91 /* Down-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Down-Info.plist"; sourceTree = "<group>"; };
98100
90A40A961EC02FF6004F2E91 /* DownTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "DownTests-Info.plist"; sourceTree = "<group>"; };
99101
90A40A981EC0309A004F2E91 /* Deployment-Targets.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Deployment-Targets.xcconfig"; sourceTree = "<group>"; };
@@ -171,6 +173,14 @@
171173
/* End PBXFrameworksBuildPhase section */
172174

173175
/* Begin PBXGroup section */
176+
907C64611EC120530095FEE1 /* Fixtures */ = {
177+
isa = PBXGroup;
178+
children = (
179+
907C64621EC120530095FEE1 /* TestDownView.bundle */,
180+
);
181+
path = Fixtures;
182+
sourceTree = "<group>";
183+
};
174184
90A40A971EC0309A004F2E91 /* Configurations */ = {
175185
isa = PBXGroup;
176186
children = (
@@ -232,6 +242,7 @@
232242
children = (
233243
D4201EC51CFA59A5008EEC6E /* BindingTests.swift */,
234244
D41689B21CFFE28200E5802B /* DownViewTests.swift */,
245+
907C64611EC120530095FEE1 /* Fixtures */,
235246
D4F948DB1D00A4A800C9C0F6 /* NSAttributedStringTests.swift */,
236247
D438696B1D00D27700E95A1F /* StringTests.swift */,
237248
);
@@ -377,6 +388,7 @@
377388
buildConfigurationList = 8AFAEB031E6E32E900E09B68 /* Build configuration list for PBXNativeTarget "DownTests" */;
378389
buildPhases = (
379390
8AFAEAF71E6E32E900E09B68 /* Sources */,
391+
907C64641EC133740095FEE1 /* Resources */,
380392
8AFAEAF81E6E32E900E09B68 /* Frameworks */,
381393
90A40A9B1EC03282004F2E91 /* Copy Bundled Frameworks */,
382394
);
@@ -437,6 +449,14 @@
437449
);
438450
runOnlyForDeploymentPostprocessing = 0;
439451
};
452+
907C64641EC133740095FEE1 /* Resources */ = {
453+
isa = PBXResourcesBuildPhase;
454+
buildActionMask = 2147483647;
455+
files = (
456+
907C64651EC133780095FEE1 /* TestDownView.bundle in Resources */,
457+
);
458+
runOnlyForDeploymentPostprocessing = 0;
459+
};
440460
/* End PBXResourcesBuildPhase section */
441461

442462
/* Begin PBXSourcesBuildPhase section */

Tests/DownViewTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,33 @@ class DownViewTests: XCTestCase {
6565
}
6666
}
6767

68+
func testInstantiationWithCustomTemplateBundle() {
69+
let expect1 = expectation(description: "DownView accepts and uses a custom theme bundle")
70+
guard
71+
let bundle = Bundle(for: type(of: self)).url(forResource: "TestDownView", withExtension: "bundle"),
72+
let templateBundle = Bundle(url: bundle)
73+
else {
74+
XCTFail("Test template bundle not found in test target!")
75+
return
76+
}
77+
78+
var downView: DownView?
79+
downView = try? DownView(frame: .zero, markdownString: "## [Down](https://github.com/iwasrobbed/Down)", templateBundle: templateBundle, didLoadSuccessfully: {
80+
self._pageContents(for: downView!) { (htmlString) in
81+
XCTAssertTrue(htmlString!.contains("css/down.min.css"))
82+
XCTAssertTrue(htmlString!.contains("https://github.com/iwasrobbed/Down"))
83+
XCTAssertTrue(htmlString!.contains("But also, custom HTML!"))
84+
85+
expect1.fulfill()
86+
}
87+
})
88+
89+
waitForExpectations(timeout: 10) { (error: Error?) in
90+
if let error = error {
91+
XCTFail("waitForExpectationsWithTimeout errored: \(error)")
92+
}
93+
}
94+
}
6895
}
6996

7097
fileprivate extension DownViewTests {

Tests/Fixtures/TestDownView.bundle/css/down.min.css

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=640"/>
6+
<link charset="utf-8" href="css/down.min.css" rel="stylesheet">
7+
<script charset="utf-8" src="js/highlight.min.js" type="text/javascript"></script>
8+
<script charset="utf-8" src="js/down.js" type="text/javascript"></script>
9+
<title></title>
10+
</head>
11+
<body>
12+
DOWN_HTML
13+
But also, custom HTML!
14+
</body>
15+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hljs.initHighlightingOnLoad();

Tests/Fixtures/TestDownView.bundle/js/highlight.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)