//
//  XCTestCase+SnapshotTests.swift
//  CriticalMapsSnapshotTests
//
//  Created by MAXIM TSVETKOV on 05.10.19.
//  Copyright © 2019 Pokus Labs. All rights reserved.
//

@testable import CriticalMaps
import SnapshotTesting
import XCTest

extension XCTestCase {
    func assertViewSnapshot(for themes: [Theme] = [.light, .dark],
                            matching value: UIView,
                            with size: CGSize? = nil,
                            file: StaticString = #file,
                            testName: String = #function,
                            line: UInt = #line) {
        themes.forEach { theme in
            MockThemeController.shared.changeTheme(to: theme)
            MockThemeController.shared.applyTheme()
            assertSnapshot(matching: value,
                           as: .image(precision: 0.99, size: size),
                           named: theme.displayName,
                           file: file,
                           testName: testName,
                           line: line)
        }
    }
}

private extension Theme {
    var displayName: String {
        switch self {
        case .light:
            return "Light"
        case .dark:
            return "Dark"
        }
    }
}

//
//  XCTestCase+SnapshotTests.swift
//  CriticalMapsSnapshotTests
//
//  Created by MAXIM TSVETKOV on 05.10.19.
//  Copyright © 2019 Pokus Labs. All rights reserved.
//

@testable import CriticalMaps
import SnapshotTesting
import XCTest

extension XCTestCase {
    func assertViewSnapshot(for themes: [Theme] = [.light, .dark],
                            matching value: UIView,
                            with size: CGSize? = nil,
                            file: StaticString = #file,
                            testName: String = #function,
                            line: UInt = #line) {
        themes.forEach { theme in
            MockThemeController.shared.changeTheme(to: theme)
            MockThemeController.shared.applyTheme()
            assertSnapshot(matching: value,
                           as: .image(size: size),
                           named: theme.displayName,
                           file: file,
                           testName: testName,
                           line: line)
        }
    }
}

private extension Theme {
    var displayName: String {
        switch self {
        case .light:
            return "Light"
        case .dark:
            return "Dark"
        }
    }
}

--- 
+++ 
@@ -21,7 +21,7 @@
             MockThemeController.shared.changeTheme(to: theme)
             MockThemeController.shared.applyTheme()
             assertSnapshot(matching: value,
-                           as: .image(size: size),
+                           as: .image(precision: 0.99, size: size),
                            named: theme.displayName,
                            file: file,
                            testName: testName,
Test if Snapshots succeed on CI with 99% Precision
