-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Kyome22/auto-update
Added Unit Test
- Loading branch information
Showing
15 changed files
with
283 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Test | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- "main" | ||
paths-ignore: | ||
- "**/README.md" | ||
|
||
jobs: | ||
unit-test: | ||
name: Unit Test | ||
runs-on: macos-14 | ||
env: | ||
DEVELOPER_DIR: "/Applications/Xcode_16.app/Contents/Developer" | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Show Xcode version | ||
run: xcodebuild -version | ||
|
||
- name: Run Test | ||
working-directory: ShiftWindowPackages | ||
run: | | ||
xcodebuild -scheme ShiftWindowPackages-Package test \ | ||
-destination "platform=macOS,arch=arm64" \ | ||
-resultBundlePath TestResults/result_bundle |\ | ||
xcpretty -c && exit ${PIPESTATUS[0]} | ||
- name: Archive test results | ||
if: success() || failure() | ||
uses: kishikawakatsumi/xcresulttool@v1 | ||
with: | ||
path: TestResults/result_bundle.xcresult | ||
show-passed-tests: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
# Mac | ||
.DS_Store | ||
|
||
# Xcode | ||
xcuserdata/ | ||
*.xcuserstate | ||
*.xccheckout | ||
|
||
# Swift Package Manager | ||
Packages.resolved | ||
.swiftpm/ | ||
.build/ | ||
ShiftWindowPackages/Package.resolved | ||
|
||
# Test | ||
TestResults/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
ShiftWindowPackages/Sources/DataLayer/Dependency/CGDirectDisplayClient.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
CGDirectDisplayClient.swift | ||
DataLayer | ||
|
||
Created by Takuto Nakamura on 2024/11/06. | ||
Copyright 2022 Takuto Nakamura (Kyome22) | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import CoreGraphics | ||
|
||
public struct CGDirectDisplayClient: DependencyClient { | ||
public var bounds: @Sendable (CGDirectDisplayID) -> CGRect | ||
|
||
public static let liveValue = Self( | ||
bounds: { CGDisplayBounds($0) } | ||
) | ||
|
||
public static let testValue = Self( | ||
bounds: { _ in CGRect.zero } | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
ShiftWindowPackages/Tests/DomainTests/LoggerServiceTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import DataLayer | ||
import os | ||
import XCTest | ||
|
||
@testable import Domain | ||
|
||
final class LoggerServiceTests: XCTestCase { | ||
func test_bootstrapは一度しか実行されない() async throws { | ||
let count = OSAllocatedUnfairLock(initialState: 0) | ||
var mock: LoggingSystemClient = .testValue | ||
mock.bootstrap = { _ in | ||
count.withLock { $0 += 1 } | ||
} | ||
let sut = LogService(mock) | ||
await sut.bootstrap() | ||
await sut.bootstrap() | ||
let actual = count.withLock { $0 } | ||
XCTAssertEqual(actual, 1) | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
ShiftWindowPackages/Tests/DomainTests/ShiftServiceTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import DataLayer | ||
import os | ||
import XCTest | ||
|
||
@testable import Domain | ||
|
||
final class ShiftServiceTests: XCTestCase { | ||
func test_getValidFrame_MainScreenが取得不能_nilが返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.getValidFrame() | ||
XCTAssertNil(actual) | ||
} | ||
|
||
func test_getValidFrame_MainScreenが取得可能_Dockが下部に存在_有効領域が返される() async { | ||
var nsScreenClient = NSScreenClient.testValue | ||
nsScreenClient.mainScreen = { NSScreenMock(x: 0, y: 0, width: 100, height: 95) } | ||
var cgDirectDisplayClient = CGDirectDisplayClient.testValue | ||
cgDirectDisplayClient.bounds = { _ in CGRect(x: 0, y: 0, width: 100, height: 100) } | ||
var nsAppClient = NSAppClient.testValue | ||
nsAppClient.mainMenu = { NSMenuMock() } | ||
let sut = ShiftService(cgDirectDisplayClient, .testValue, nsAppClient, nsScreenClient, .testValue) | ||
let actual = await sut.getValidFrame() | ||
XCTAssertEqual(actual, CGRect(x: 0, y: 5, width: 100, height: 95)) | ||
} | ||
|
||
func test_getValidFrame_MainScreenが取得可能_Dockが右側に存在_有効領域が返される() async { | ||
var nsScreenClient = NSScreenClient.testValue | ||
nsScreenClient.mainScreen = { NSScreenMock(x: 0, y: 0, width: 95, height: 95) } | ||
var cgDirectDisplayClient = CGDirectDisplayClient.testValue | ||
cgDirectDisplayClient.bounds = { _ in CGRect(x: 0, y: 0, width: 100, height: 100) } | ||
var nsAppClient = NSAppClient.testValue | ||
nsAppClient.mainMenu = { NSMenuMock() } | ||
let sut = ShiftService(cgDirectDisplayClient, .testValue, nsAppClient, nsScreenClient, .testValue) | ||
let actual = await sut.getValidFrame() | ||
XCTAssertEqual(actual, CGRect(x: 0, y: 5, width: 94, height: 95)) | ||
} | ||
|
||
func test_getValidFrame_MainScreenが取得可能_Dockが左側に存在_有効領域が返される() async { | ||
var nsScreenClient = NSScreenClient.testValue | ||
nsScreenClient.mainScreen = { NSScreenMock(x: 5, y: 0, width: 95, height: 95) } | ||
var cgDirectDisplayClient = CGDirectDisplayClient.testValue | ||
cgDirectDisplayClient.bounds = { _ in CGRect(x: 0, y: 0, width: 100, height: 100) } | ||
var nsAppClient = NSAppClient.testValue | ||
nsAppClient.mainMenu = { NSMenuMock() } | ||
let sut = ShiftService(cgDirectDisplayClient, .testValue, nsAppClient, nsScreenClient, .testValue) | ||
let actual = await sut.getValidFrame() | ||
XCTAssertEqual(actual, CGRect(x: 6, y: 5, width: 94, height: 95)) | ||
} | ||
|
||
func test_makeNewFrame_幅が負_nilが返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.makeNewFrame(shiftType: .maximize, validFrame: CGRect(x: 0, y: 0, width: -1, height: 0)) | ||
XCTAssertNil(actual) | ||
} | ||
|
||
func test_makeNewFrame_高さが負_nilが返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.makeNewFrame(shiftType: .maximize, validFrame: CGRect(x: 0, y: 0, width: 0, height: -1)) | ||
XCTAssertNil(actual) | ||
} | ||
|
||
func test_makeNewFrame_上側1/2_領域が返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.makeNewFrame(shiftType: .topHalf, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
XCTAssertEqual(actual, CGRect(x: 0, y: 0, width: 100, height: 50)) | ||
} | ||
|
||
func test_makeNewFrame_下側1/2_領域が返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.makeNewFrame(shiftType: .bottomHalf, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
XCTAssertEqual(actual, CGRect(x: 0, y: 50, width: 100, height: 50)) | ||
} | ||
|
||
func test_makeNewFrame_左側1/2_領域が返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.makeNewFrame(shiftType: .leftHalf, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
XCTAssertEqual(actual, CGRect(x: 0, y: 0, width: 50, height: 100)) | ||
} | ||
|
||
func test_makeNewFrame_右側1/2_領域が返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.makeNewFrame(shiftType: .rightHalf, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
XCTAssertEqual(actual, CGRect(x: 50, y: 0, width: 50, height: 100)) | ||
} | ||
|
||
func test_makeNewFrame_左側1/3_領域が返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.makeNewFrame(shiftType: .leftThird, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
XCTAssertEqual(actual, CGRect(x: 0, y: 0, width: 33, height: 100)) | ||
} | ||
|
||
func test_makeNewFrame_左側2/3_領域が返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.makeNewFrame(shiftType: .leftTwoThirds, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
XCTAssertEqual(actual, CGRect(x: 0, y: 0, width: 66, height: 100)) | ||
} | ||
|
||
func test_makeNewFrame_中央1/3_領域が返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.makeNewFrame(shiftType: .middleThird, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
XCTAssertEqual(actual, CGRect(x: 33, y: 0, width: 33, height: 100)) | ||
} | ||
|
||
func test_makeNewFrame_右側2/3_領域が返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.makeNewFrame(shiftType: .rightTwoThirds, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
XCTAssertEqual(actual, CGRect(x: 33, y: 0, width: 67, height: 100)) | ||
} | ||
|
||
func test_makeNewFrame_右側1/3_領域が返される() async { | ||
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue) | ||
let actual = await sut.makeNewFrame(shiftType: .rightThird, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
XCTAssertEqual(actual, CGRect(x: 66, y: 0, width: 34, height: 100)) | ||
} | ||
} | ||
|
||
fileprivate class NSScreenMock: NSScreen { | ||
let _visibleFrame: NSRect | ||
|
||
init(x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat) { | ||
_visibleFrame = NSRect(x: x, y: y, width: width, height: height) | ||
super.init() | ||
} | ||
|
||
override var visibleFrame: NSRect { _visibleFrame } | ||
} | ||
|
||
fileprivate class NSMenuMock: NSMenu { | ||
override var menuBarHeight: CGFloat { 5 } | ||
} |
Oops, something went wrong.