-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMenuInteractorSpec.swift
162 lines (136 loc) · 9.03 KB
/
MenuInteractorSpec.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//
// MenuInteractorSpec.swift
// FBSnapshotsViewer
//
// Created by Anton Domashnev on 10/03/2017.
// Copyright © 2017 Anton Domashnev. All rights reserved.
//
import Quick
import Nimble
import KZFileWatchers
@testable import FBSnapshotsViewer
class MenuInteractor_MockApplicationSnapshotTestResultListenerFactory: ApplicationSnapshotTestResultListenerFactory {
var mockApplicationSnapshotTestResultListener: MenuInteractor_MockApplicationSnapshotTestResultListener!
var givenLogFilePath: String!
var givenConfiguration: FBSnapshotsViewer.Configuration!
override func applicationSnapshotTestResultListener(forLogFileAt path: String, configuration: FBSnapshotsViewer.Configuration) -> ApplicationSnapshotTestResultListener {
givenLogFilePath = path
givenConfiguration = configuration
return mockApplicationSnapshotTestResultListener
}
}
class MenuInteractor_MockApplicationSnapshotTestResultListener: ApplicationSnapshotTestResultListener {
var output: ApplicationSnapshotTestResultListenerOutput!
override func startListening(outputTo completion: @escaping ApplicationSnapshotTestResultListenerOutput) {
output = completion
}
}
class MenuInteractor_MockApplicationTestLogFilesListener: ApplicationTestLogFilesListener {
var output: ApplicationTestLogFilesListenerOutput!
var listeningDerivedDataFolder: DerivedDataFolder!
var stopListeningCalled: Bool = false
override func listen(derivedDataFolder: DerivedDataFolder, outputTo completion: @escaping ApplicationTestLogFilesListenerOutput) {
listeningDerivedDataFolder = derivedDataFolder
output = completion
}
override func stopListening() {
stopListeningCalled = true
}
}
class MenuInteractorSpec: QuickSpec {
override func spec() {
let testResultsDate = Date()
let applicationName = "FBSnapshotsViewer"
let fbReferenceImageDirURL = URL(fileURLWithPath: "foo/bar", isDirectory: true)
let build = Build(date: testResultsDate, applicationName: applicationName, fbReferenceImageDirectoryURLs: [fbReferenceImageDirURL])
let testInformation1 = SnapshotTestInformation(testClassName: "testClass1", testName: "testName1", testFilePath: "testFilePath1", testLineNumber: 1)
let testResult1 = SnapshotTestResult.failed(testInformation: testInformation1, referenceImagePath: "referenceImagePath1", diffImagePath: "diffImagePath1", failedImagePath: "failedImagePath1", build: build)
let testInformation2 = SnapshotTestInformation(testClassName: "testClass2", testName: "testName2", testFilePath: "testFilePath2", testLineNumber: 1)
let testResult2 = SnapshotTestResult.failed(testInformation: testInformation2, referenceImagePath: "referenceImagePath2", diffImagePath: "diffImagePath2", failedImagePath: "failedImagePath2", build: build)
let testInformation3 = SnapshotTestInformation(testClassName: "testClass3", testName: "testName3", testFilePath: "testFilePath3", testLineNumber: 1)
let testResult3 = SnapshotTestResult.recorded(testInformation: testInformation3, referenceImagePath: "referenceImagePath3", build: build)
var configuration: FBSnapshotsViewer.Configuration!
var output: MenuInteractorOutputMock!
var interactor: MenuInteractor!
var applicationSnapshotTestResultListener: MenuInteractor_MockApplicationSnapshotTestResultListener!
var applicationSnapshotTestResultListenerFactory: MenuInteractor_MockApplicationSnapshotTestResultListenerFactory!
var applicationTestLogFilesListener: MenuInteractor_MockApplicationTestLogFilesListener!
beforeEach {
configuration = Configuration(derivedDataFolder: DerivedDataFolder.xcodeDefault)
output = MenuInteractorOutputMock()
applicationSnapshotTestResultListener = MenuInteractor_MockApplicationSnapshotTestResultListener(fileWatcher: KZFileWatchers.FileWatcher.Local(path: "testpath"), fileWatcherUpdateHandler: ApplicationSnapshotTestResultFileWatcherUpdateHandler())
applicationSnapshotTestResultListenerFactory = MenuInteractor_MockApplicationSnapshotTestResultListenerFactory()
applicationSnapshotTestResultListenerFactory.mockApplicationSnapshotTestResultListener = applicationSnapshotTestResultListener
applicationTestLogFilesListener = MenuInteractor_MockApplicationTestLogFilesListener()
interactor = MenuInteractor(applicationSnapshotTestResultListenerFactory: applicationSnapshotTestResultListenerFactory, applicationTestLogFilesListener: applicationTestLogFilesListener, configuration: configuration)
interactor.output = output
}
describe(".startXcodeBuildsListening") {
beforeEach {
interactor.startXcodeBuildsListening(derivedDataFolder: DerivedDataFolder.xcodeCustom(path: "/Users/antondomashnev/Library/Bla"))
}
it("stops the current xcodeDefault builds listening") {
expect(applicationTestLogFilesListener.stopListeningCalled).to(beTrue())
}
it("starts a new listening of the given derived data folder") {
let expectedDerivedDataFolder = DerivedDataFolder.xcodeCustom(path: "/Users/antondomashnev/Library/Bla")
expect(applicationTestLogFilesListener.listeningDerivedDataFolder).to(equal(expectedDerivedDataFolder))
}
context("when find a new test log file") {
beforeEach {
applicationTestLogFilesListener.output("/Users/antondomashnev/Library/Bla/Bla.log")
}
it("outputs it") {
expect(output.didFindNewTestLogFile_at_Called).to(beTrue())
expect(output.didFindNewTestLogFile_at_ReceivedPath).to(equal("/Users/antondomashnev/Library/Bla/Bla.log"))
}
}
}
describe(".startSnapshotTestResultListening") {
context("when start listening unique log file path") {
beforeEach {
interactor.startSnapshotTestResultListening(fromLogFileAt: "/Users/antondomashnev/Library/Bla/Bla.log")
}
it("creates listener for correct log file path") {
expect(applicationSnapshotTestResultListenerFactory.givenLogFilePath).to(equal("/Users/antondomashnev/Library/Bla/Bla.log"))
}
it("creates listener with correct configuration") {
expect(applicationSnapshotTestResultListenerFactory.givenConfiguration).to(equal(configuration))
}
context("when find new test result") {
beforeEach {
applicationSnapshotTestResultListener.output(testResult1)
}
it("outputs it") {
let build = Build(date: testResultsDate, applicationName: applicationName, fbReferenceImageDirectoryURLs: [URL(fileURLWithPath: "foo/bar", isDirectory: true)])
let testInformation = SnapshotTestInformation(testClassName: "testClass1", testName: "testName1", testFilePath: "testFilePath1", testLineNumber: 1)
let expectedTestResult = SnapshotTestResult.failed(testInformation: testInformation, referenceImagePath: "referenceImagePath1", diffImagePath: "diffImagePath1", failedImagePath: "failedImagePath1", build: build)
expect(output.didFindNewTestResult___ReceivedTestResult).to(equal(expectedTestResult))
}
}
context("when find three test results consequently") {
beforeEach {
applicationSnapshotTestResultListener.output(testResult1)
applicationSnapshotTestResultListener.output(testResult2)
applicationSnapshotTestResultListener.output(testResult3)
}
it("stores all of them") {
expect(interactor.foundTestResults.contains(where: { $0 == testResult1 })).to(beTrue())
expect(interactor.foundTestResults.contains(where: { $0 == testResult2 })).to(beTrue())
expect(interactor.foundTestResults.contains(where: { $0 == testResult3 })).to(beTrue())
}
}
}
context("when start listening already listened log file path") {
beforeEach {
interactor.startSnapshotTestResultListening(fromLogFileAt: "/Users/antondomashnev/Library/Bla/Bla1.log")
interactor.startSnapshotTestResultListening(fromLogFileAt: "/Users/antondomashnev/Library/Bla/Bla2.log")
interactor.startSnapshotTestResultListening(fromLogFileAt: "/Users/antondomashnev/Library/Bla/Bla1.log")
}
it("doesnt create duplicate listener") {
expect(applicationSnapshotTestResultListenerFactory.givenLogFilePath).to(equal("/Users/antondomashnev/Library/Bla/Bla2.log"))
}
}
}
}
}