Skip to content

Commit

Permalink
Lint tests and package
Browse files Browse the repository at this point in the history
  • Loading branch information
r-dent committed Feb 19, 2024
1 parent 44f3692 commit 2c7ee52
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export PATH=\"$PATH:/opt/homebrew/bin\"\nif which swiftlint > /dev/null; then\n swiftlint lint ../Sources\n swiftlint lint \"Example App\" --config ../.swiftlint.yml\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\n exit 0\nfi\n";
shellScript = "export PATH=\"$PATH:/opt/homebrew/bin\"\nif which swiftlint > /dev/null; then\n swiftlint lint ../Sources\n swiftlint lint ../Tests\n swiftlint ../Package.swift\n swiftlint lint \"Example App\" --config ../.swiftlint.yml\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\n exit 0\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let package = Package(
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing",
from: "1.12.0"
),
)
],
targets: [
.target(
Expand Down
12 changes: 6 additions & 6 deletions Tests/StreamDeckSDKTests/Helper/StreamDeckClientMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
public final class StreamDeckClientMock {
public typealias Key = (index: Int, image: UIImage)
public typealias WindowImage = (rect: CGRect, image: UIImage)
public typealias Color = (red: UInt8, green: UInt8, blue: UInt8)
public typealias Color = (red: UInt8, green: UInt8, blue: UInt8) // swiftlint:disable:this large_tuple
public typealias FillKey = (index: Int, color: Color)

final class Recorder {
Expand All @@ -31,7 +31,7 @@ public final class StreamDeckClientMock {
self?.brightnesses.append(brightness)
}
.store(in: &cancellables)

mock.keys
.sink { [weak self] key in
self?.keys.append(key)
Expand Down Expand Up @@ -132,12 +132,12 @@ extension StreamDeckClientMock: StreamDeckClientProtocol {
inputEventHandler = handler
subscribedToInputEventsSubject.send(true)
}

public func setBrightness(_ brightness: Int) {
lock.lock(); defer { lock.unlock() }
brightnessSubject.send(brightness)
}

public func setKeyImage(_ data: Data, at index: Int) {
lock.lock(); defer { lock.unlock() }
guard let image = UIImage(data: data, scale: 1) else { return }
Expand All @@ -155,13 +155,13 @@ extension StreamDeckClientMock: StreamDeckClientProtocol {
guard let image = UIImage(data: data, scale: 1) else { return }
windowSubject.send((rect: rect, image: image))
}

public func setScreenImage(_ data: Data) {
lock.lock(); defer { lock.unlock() }
guard let image = UIImage(data: data, scale: 1) else { return }
screenSubject.send(image)
}

public func fillScreen(red: UInt8, green: UInt8, blue: UInt8) {
lock.lock(); defer { lock.unlock() }
fillScreenSubject.send((red: red, green: green, blue: blue))
Expand Down
2 changes: 0 additions & 2 deletions Tests/StreamDeckSDKTests/Helper/StreamDeckRobot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,4 @@ final class StreamDeckRobot {
) { $0.count == imageCount + 1 }
}
}


}
80 changes: 42 additions & 38 deletions Tests/StreamDeckSDKTests/Helper/TestViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,6 @@ import SwiftUI
enum TestViews {

final class SimpleEventModel: ObservableObject {
enum Event: Equatable, CustomStringConvertible {
case none, press(Bool), rotate(Int), fling(InputEvent.Direction), touch(CGPoint)

var description: String {
switch self {
case .none: "none"
case let .press(pressed): pressed ? "pressed" : "released"
case let .rotate(steps): "steps \(steps)"
case let .fling(direction): "fling \(direction.description)"
case let .touch(point): "touch(\(point.x),\(point.y))"
}
}

}

@Published var lastEvent: Event = .none
}

Expand Down Expand Up @@ -90,11 +75,13 @@ enum TestViews {
StreamDeckKeypadLayout { _ in
SimpleKey()
}
}) { context in
},
windowView: { _ in
StreamDeckDialAreaLayout { _ in
SimpleDialView()
}
}
)
}
}

Expand All @@ -108,34 +95,51 @@ enum TestViews {
keyAreaView: { _ in
StreamDeckKeypadLayout { _ in SimpleKey() }
}
) { context in
ZStack {
StreamDeckDialAreaLayout(
rotate: { _, steps in
model.lastEvent = .rotate(steps)
},
press: { _, isPressed in
model.lastEvent = .press(isPressed)
},
touch: { point in
model.lastEvent = .touch(point)
},
fling: { _, _, direction in
model.lastEvent = .fling(direction)
}
) { _ in SimpleDialView() }

Text(model.lastEvent.description)
}
.onChange(of: model.lastEvent) { _, _ in
context.updateRequired()
windowView: { context in
ZStack {
StreamDeckDialAreaLayout(
rotate: { _, steps in
model.lastEvent = .rotate(steps)
},
press: { _, isPressed in
model.lastEvent = .press(isPressed)
},
touch: { point in
model.lastEvent = .touch(point)
},
fling: { _, _, direction in
model.lastEvent = .fling(direction)
}
) { _ in SimpleDialView() }

Text(model.lastEvent.description)
}
.onChange(of: model.lastEvent) { _, _ in
context.updateRequired()
}
}
}
)
}
}

}

extension TestViews.SimpleEventModel {
enum Event: Equatable, CustomStringConvertible {
case none, press(Bool), rotate(Int), fling(InputEvent.Direction), touch(CGPoint)

var description: String {
switch self {
case .none: "none"
case let .press(pressed): pressed ? "pressed" : "released" // swiftlint:disable:this colon
case let .rotate(steps): "steps \(steps)"
case let .fling(direction): "fling \(direction.description)"
case let .touch(point): "touch(\(point.x),\(point.y))"
}
}
}
}

extension InputEvent.Direction: CustomStringConvertible {
public var description: String {
switch self {
Expand Down
1 change: 0 additions & 1 deletion Tests/StreamDeckSDKTests/StreamDeckLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ final class StreamDeckLayoutTests: XCTestCase {
robot.assertEqual(\.screens.count, 1)
robot.assertEqual(\.keys.count, 2)


await robot.assertSnapshot(\.screens[0], as: .image, named: "fullscreen")
await robot.assertSnapshot(\.keys[0].image, as: .image, named: "key_down")
await robot.assertSnapshot(\.keys[1].image, as: .image, named: "key_up")
Expand Down
2 changes: 1 addition & 1 deletion Tests/StreamDeckSDKTests/StreamDeckTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ final class StreamDeckTests: XCTestCase {
let closeExpectation = expectation(description: "closed")
device.onClose { closeExpectation.fulfill() }
device.close()

wait(for: [closeExpectation], timeout: 1)

XCTAssertTrue(device.isClosed)
Expand Down
1 change: 0 additions & 1 deletion Tests/StreamDeckSDKTests/VersionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ final class VersionTests: XCTestCase {
}

}

0 comments on commit 2c7ee52

Please sign in to comment.