Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy image #62

Merged
merged 6 commits into from
Aug 30, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Copy snapshot function;
  • Loading branch information
Antondomashnev committed Aug 29, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit a9c6a2b99b5255d0cee87d464c2b780746801a7e
4 changes: 4 additions & 0 deletions FBSnapshotsViewer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -138,6 +138,7 @@
6DA1BF981E7755110017D47B /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DA1BF961E7755110017D47B /* Colors.swift */; };
6DA1BF991E7755110017D47B /* Storyboards.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DA1BF971E7755110017D47B /* Storyboards.swift */; };
6DA1BF9B1E7756010017D47B /* FolderEventFilterSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DA1BF9A1E7756010017D47B /* FolderEventFilterSpec.swift */; };
6DAB32C71F560A7500783A20 /* Pasteboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DAB32C61F560A7500783A20 /* Pasteboard.swift */; };
6DB94C9D1EE569BA00095C37 /* ApplicationNameExtractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB94C9C1EE569BA00095C37 /* ApplicationNameExtractor.swift */; };
6DB94C9F1EE56EFE00095C37 /* ApplicationNameExtractorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB94C9E1EE56EFE00095C37 /* ApplicationNameExtractorSpec.swift */; };
6DB94CA11EE5AB9800095C37 /* ApplicationNameExtractorFactorySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB94CA01EE5AB9800095C37 /* ApplicationNameExtractorFactorySpec.swift */; };
@@ -317,6 +318,7 @@
6DA1BF961E7755110017D47B /* Colors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; };
6DA1BF971E7755110017D47B /* Storyboards.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Storyboards.swift; sourceTree = "<group>"; };
6DA1BF9A1E7756010017D47B /* FolderEventFilterSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FolderEventFilterSpec.swift; sourceTree = "<group>"; };
6DAB32C61F560A7500783A20 /* Pasteboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pasteboard.swift; sourceTree = "<group>"; };
6DB94C9C1EE569BA00095C37 /* ApplicationNameExtractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplicationNameExtractor.swift; sourceTree = "<group>"; };
6DB94C9E1EE56EFE00095C37 /* ApplicationNameExtractorSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplicationNameExtractorSpec.swift; sourceTree = "<group>"; };
6DB94CA01EE5AB9800095C37 /* ApplicationNameExtractorFactorySpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplicationNameExtractorFactorySpec.swift; sourceTree = "<group>"; };
@@ -656,6 +658,7 @@
6D789CDD1EC3B6CC00EEF7EE /* AutoCases.swift */,
6D3003B11ED20B13000CCAC8 /* Updater.swift */,
6DD1AEA41F08093E002FCA82 /* ImageCache.swift */,
6DAB32C61F560A7500783A20 /* Pasteboard.swift */,
);
path = Protocols;
sourceTree = "<group>";
@@ -1164,6 +1167,7 @@
6D3000471EBFBE86005B6103 /* PreferencesWireframe.swift in Sources */,
6DA1BF981E7755110017D47B /* Colors.swift in Sources */,
6D5797C41F092B2000AE5D22 /* FileManager+Move.swift in Sources */,
6DAB32C71F560A7500783A20 /* Pasteboard.swift in Sources */,
6D789CE61EC3BFA900EEF7EE /* Configuration.swift in Sources */,
6DBD99DB1E7AB3D400E1714E /* FileWatcherFactory.swift in Sources */,
6D9EF95C1EF5DBD600AA15B1 /* TestResultsDisplayInfo.swift in Sources */,
24 changes: 24 additions & 0 deletions FBSnapshotsViewer/Protocols/Pasteboard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Pasteboard.swift
// FBSnapshotsViewer
//
// Created by Anton Domashnev on 29.08.17.
// Copyright © 2017 Anton Domashnev. All rights reserved.
//

import Foundation
import Cocoa

protocol Pasteboard: AutoMockable {
func copyImage(at url: URL)
}

extension NSPasteboard: Pasteboard {
func copyImage(at url: URL) {
guard let image = NSImage(contentsOf: url) else {
return
}
clearContents()
writeObjects([image])
}
}
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
//

import Foundation
import Cocoa

enum TestResultsInteractorError: Error {
case canNotSwapNotExistedTestResult
@@ -16,6 +17,7 @@ class TestResultsInteractorBuilder {
var externalViewers: ExternalViewers = ExternalViewers()
var processLauncher: ProcessLauncher = ProcessLauncher()
var swapper: SnapshotTestResultSwapper = SnapshotTestResultSwapper()
var pasteboard: Pasteboard = NSPasteboard.general()
var testResults: [SnapshotTestResult] = []

typealias BuiderClojure = (TestResultsInteractorBuilder) -> Void
@@ -30,6 +32,7 @@ class TestResultsInteractor {
fileprivate let kaleidoscopeViewer: ExternalViewer.Type
fileprivate let processLauncher: ProcessLauncher
fileprivate let swapper: SnapshotTestResultSwapper
fileprivate let pasteboard: Pasteboard
var testResults: [SnapshotTestResult]

weak var output: TestResultsInteractorOutput?
@@ -40,6 +43,7 @@ class TestResultsInteractor {
self.xcodeViewer = builder.externalViewers.xcode
self.processLauncher = builder.processLauncher
self.swapper = builder.swapper
self.pasteboard = builder.pasteboard
}
}

@@ -83,4 +87,15 @@ extension TestResultsInteractor: TestResultsInteractorInput {
output?.didFailToSwap(testResult: testResult, with: error)
}
}

func copy(testResult: SnapshotTestResult) {
var url: URL
switch testResult {
case let .failed(_, _, _, failedImagePath, _):
url = URL(fileURLWithPath: failedImagePath)
case let .recorded(_, referenceImagePath, _):
url = URL(fileURLWithPath: referenceImagePath)
}
pasteboard.copyImage(at: url)
}
}
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ protocol TestResultsInteractorInput: class, AutoMockable {
func openInKaleidoscope(testResult: SnapshotTestResult)
func openInXcode(testResult: SnapshotTestResult)
func swap(testResult: SnapshotTestResult)
func copy(testResult: SnapshotTestResult)
}

protocol TestResultsInteractorOutput: class, AutoMockable {
Original file line number Diff line number Diff line change
@@ -48,6 +48,10 @@ extension TestResultsPresenter: TestResultsModuleInterface {
}
updateUserInterface()
}

func copy(testResultDisplayInfo: TestResultDisplayInfo) {
interactor?.copy(testResult: testResultDisplayInfo.testResult)
}
}

extension TestResultsPresenter: TestResultsInteractorOutput {
Original file line number Diff line number Diff line change
@@ -14,4 +14,5 @@ protocol TestResultsModuleInterface: class, AutoMockable {
func openInXcode(testResultDisplayInfo: TestResultDisplayInfo)
func selectDiffMode(_ diffMode: TestResultsDiffMode)
func swap(_ testResults: [TestResultDisplayInfo])
func copy(testResultDisplayInfo: TestResultDisplayInfo)
}
Original file line number Diff line number Diff line change
@@ -80,6 +80,11 @@ extension TestResultsController: TestResultCellDelegate {
}

func testResultCell(_ cell: TestResultCell, copySnapshotButtonClicked: NSButton) {
guard let testResultInfo = findTestResultInfo(for: cell) else {
assertionFailure("Unexpected TestResultCellDelegate callback about copy snapshot button click")
return
}
eventHandler.copy(testResultDisplayInfo: testResultInfo.info)
}
}

44 changes: 44 additions & 0 deletions FBSnapshotsViewerTests/TestResultsControllerSpec.swift
Original file line number Diff line number Diff line change
@@ -235,5 +235,49 @@ class TestResultsControllerSpec: QuickSpec {
}
}
}

describe(".testResultCell:copySnapshotButtonClicked") {
var cell: TestResultCell!
var copySnapshotButton: NSButton!

beforeEach {
copySnapshotButton = NSButton(frame: NSRect.zero)
cell = TestResultCell(nibName: nil, bundle: nil)
}

context("when cell is not visible") {
beforeEach {
collectionView.indexPathForItemReturnValue = nil
}

it("asserts") {
expect { controller.testResultCell(cell, copySnapshotButtonClicked: copySnapshotButton) }.to(throwAssertion())
}
}

context("when test result is not presented in controller") {
beforeEach {
collectionViewOutlets.testResultsDisplayInfo = displayInfo
collectionView.indexPathForItemReturnValue = IndexPath(item: 1, section: 0)
}

it("asserts") {
expect { controller.testResultCell(cell, copySnapshotButtonClicked: copySnapshotButton) }.to(throwAssertion())
}
}

context("when test result is presented and cell is visible") {
beforeEach {
collectionViewOutlets.testResultsDisplayInfo = displayInfo
collectionView.indexPathForItemReturnValue = IndexPath(item: 0, section: 0)
controller.testResultCell(cell, copySnapshotButtonClicked: copySnapshotButton)
}

it("opens test result in xcode") {
expect(eventHandler.copy_testResultDisplayInfo_Called).to(beTrue())
expect(eventHandler.copy_testResultDisplayInfo_ReceivedTestResultDisplayInfo).to(equal(testResults[0].itemInfos[0]))
}
}
}
}
}
33 changes: 33 additions & 0 deletions FBSnapshotsViewerTests/TestResultsInteractorSpec.swift
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@ class TestResultsInteractorSpec: QuickSpec {
let xcodeViewer: TestResultsInteractor_MockExternalViewer.Type = TestResultsInteractor_MockExternalViewer.self
var processLauncher: ProcessLauncher!
var interactor: TestResultsInteractor!
var pasteboard: PasteboardMock!
var output: TestResultsInteractorOutputMock!
var swapper: TestResultsInteractor_MockSnapshotTestResultSwapper!
var testResults: [SnapshotTestResult] = []
@@ -75,6 +76,7 @@ class TestResultsInteractorSpec: QuickSpec {
let testResult2 = SnapshotTestResult.recorded(testInformation: testInformation2, referenceImagePath: "referenceImagePath2", build: build)
testResults = [testResult1, testResult2]
processLauncher = ProcessLauncher()
pasteboard = PasteboardMock()
swapper = TestResultsInteractor_MockSnapshotTestResultSwapper()
swapper.swappedTestResult = SnapshotTestResult.recorded(testInformation: testInformation1, referenceImagePath: "referenceImagePath1", build: build)
output = TestResultsInteractorOutputMock()
@@ -83,6 +85,7 @@ class TestResultsInteractorSpec: QuickSpec {
$0.externalViewers = ExternalViewers(xcodeViewer: xcodeViewer, kaleidoscopeViewer: kaleidoscopeViewer)
$0.processLauncher = processLauncher
$0.swapper = swapper
$0.pasteboard = pasteboard
}
interactor = TestResultsInteractor(builder: builder)
interactor.output = output
@@ -230,6 +233,36 @@ class TestResultsInteractorSpec: QuickSpec {
}
}
}

describe(".copy") {
context("recorded snapshot test result") {
var testResult: SnapshotTestResult!

beforeEach {
testResult = testResults[1]
interactor.copy(testResult: testResult)
}

it("copies recorded image url") {
expect(pasteboard.copyImage_at_Called).to(beTrue())
expect(pasteboard.copyImage_at_ReceivedUrl).to(equal(URL(fileURLWithPath: "referenceImagePath2")))
}
}

context("failed snapshot test result") {
var testResult: SnapshotTestResult!

beforeEach {
testResult = testResults[0]
interactor.copy(testResult: testResult)
}

it("copies failed image url") {
expect(pasteboard.copyImage_at_Called).to(beTrue())
expect(pasteboard.copyImage_at_ReceivedUrl).to(equal(URL(fileURLWithPath: "failedImagePath1")))
}
}
}

describe(".testResults") {
it("returns initialized test results") {
20 changes: 20 additions & 0 deletions FBSnapshotsViewerTests/TestResultsPresenterSpec.swift
Original file line number Diff line number Diff line change
@@ -168,5 +168,25 @@ class TestResultsPresenterSpec: QuickSpec {
expect(userInterface.show_displayInfo_ReceivedDisplayInfo?.testResultsDiffMode).to(equal(TestResultsDiffMode.diff))
}
}

describe("copy") {
var testResult: SnapshotTestResult!
var testResultDisplayInfo: TestResultDisplayInfo!
var build: Build!
var testInformation: SnapshotTestInformation!

beforeEach {
build = Build(date: Date(), applicationName: "FBSnapshotsViewer", fbReferenceImageDirectoryURLs: [URL(fileURLWithPath: "foo/bar", isDirectory: true)])
testInformation = SnapshotTestInformation(testClassName: "testClassName", testName: "MyTest", testFilePath: "testFilePath", testLineNumber: 1)
testResult = SnapshotTestResult.recorded(testInformation: testInformation, referenceImagePath: "foo/bar.png", build: build)
testResultDisplayInfo = TestResultDisplayInfo(testResult: testResult)
presenter.copy(testResultDisplayInfo: testResultDisplayInfo)
}

it("passes the message to interactor with correct test result") {
expect(interactor.copy_testResult_Called).to(beTrue())
expect(interactor.copy_testResult_ReceivedTestResult).to(equal(testResult))
}
}
}
}
34 changes: 34 additions & 0 deletions Vendor/Sourcery/CodeGenerated/AutoMockable.generated.swift
Original file line number Diff line number Diff line change
@@ -259,6 +259,20 @@ class MenuUserInterfaceMock: MenuUserInterface {
popUpOptionsMenu_Called = true
}
}
class PasteboardMock: Pasteboard {


//MARK: - copyImage

var copyImage_at_Called = false
var copyImage_at_ReceivedUrl: URL?

func copyImage(at url: URL) {

copyImage_at_Called = true
copyImage_at_ReceivedUrl = url
}
}
class PreferencesInteractorInputMock: PreferencesInteractorInput {


@@ -493,6 +507,16 @@ class TestResultsInteractorInputMock: TestResultsInteractorInput {
swap_testResult_Called = true
swap_testResult_ReceivedTestResult = testResult
}
//MARK: - copy

var copy_testResult_Called = false
var copy_testResult_ReceivedTestResult: SnapshotTestResult?

func copy(testResult: SnapshotTestResult) {

copy_testResult_Called = true
copy_testResult_ReceivedTestResult = testResult
}
}
class TestResultsInteractorOutputMock: TestResultsInteractorOutput {

@@ -559,6 +583,16 @@ class TestResultsModuleInterfaceMock: TestResultsModuleInterface {
swap___Called = true
swap___ReceivedTestResults = testResults
}
//MARK: - copy

var copy_testResultDisplayInfo_Called = false
var copy_testResultDisplayInfo_ReceivedTestResultDisplayInfo: TestResultDisplayInfo?

func copy(testResultDisplayInfo: TestResultDisplayInfo) {

copy_testResultDisplayInfo_Called = true
copy_testResultDisplayInfo_ReceivedTestResultDisplayInfo = testResultDisplayInfo
}
}
class TestResultsUserInterfaceMock: TestResultsUserInterface {