Skip to content

Commit

Permalink
Add FontColor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuzukihashi committed Mar 13, 2020
1 parent b9102ed commit 21c305a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion DemoApp/DemoApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct ContentView: View {

Text("NeumorphismUI DemoApp")
.font(.title)
.foregroundColor(self.neumorphism.color.darkerColor())
.foregroundColor(self.neumorphism.fontColor(lightColor: Color(hex: "CBCDD9"), darkColor: Color(hex: "332C58")))

RoundedRectangle(cornerRadius: 1)
.fill(self.neumorphism.color.darkerColor())
Expand Down Expand Up @@ -73,6 +73,7 @@ struct ContentView: View {

struct ContentView_Previews: PreviewProvider {
static let neumorphism = NeumorphismManager(
isDark: true,
lightColor: Color(hex: "C1D2EB"),
darkColor: Color(hex: "2C292C")
)
Expand Down
11 changes: 9 additions & 2 deletions Tests/Mock/NeumorphismManagerMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@ import SwiftUI

@available(iOS 13.0, *)
class NeumorphismManagerMock: NeumorphismManagable {
var isDark = false

var fontColorCallCount = 0
var fontColorArgs: (lightColor: Color?, darkColor: Color?)?
func fontColor(lightColor: Color?, darkColor: Color?) -> Color {
func fontColor(lightColor: Color? = nil, darkColor: Color? = nil) -> Color {
fontColorCallCount += 1
fontColorArgs?.lightColor = lightColor
fontColorArgs?.darkColor = darkColor
return lightColor ?? Color.white
if isDark {
return lightColor ?? Color.white
} else {
return darkColor ?? Color.black
}
}

var changeModeCallCount = 0
func changeMode() {
changeModeCallCount += 1
isDark.toggle()
}
}
13 changes: 13 additions & 0 deletions Tests/NeumorphismUITests/NeumorphismManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import XCTest
import SwiftUI
@testable import NeumorphismUI

@available(iOS 13.0, *)
class NeumorphismManagerTests: XCTestCase {

var mock: NeumorphismManagerMock!
Expand All @@ -15,4 +16,16 @@ class NeumorphismManagerTests: XCTestCase {

XCTAssertEqual(mock.changeModeCallCount, 1)
}

func test_fontColor() {
mock.isDark = true
var color = mock.fontColor()

XCTAssertEqual(color, Color.white)

mock.isDark = false
color = mock.fontColor()

XCTAssertEqual(color, Color.black)
}
}

0 comments on commit 21c305a

Please sign in to comment.