Skip to content

Commit 759a32e

Browse files
authored
test: add test target and unit tests (#39)
1 parent 4018628 commit 759a32e

6 files changed

Lines changed: 163 additions & 11 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ jobs:
2020
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2121
- uses: norio-nomura/action-swiftlint@9f4dcd7fd46b4e75d7935cf2f4df406d5cae3684 # 3.2.1
2222

23-
build-macos:
24-
name: Build · macOS
23+
test-macos:
24+
name: Test · macOS
2525
runs-on: macos-15
2626
steps:
2727
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
28-
- name: Build
29-
run: swift build -v
28+
- name: Test
29+
run: swift test -v
3030

31-
build-ios:
32-
name: Build · iOS ${{ matrix.os }}
31+
test-ios:
32+
name: Test · iOS ${{ matrix.os }}
3333
runs-on: macos-15
3434
strategy:
3535
fail-fast: false
@@ -43,9 +43,9 @@ jobs:
4343
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
4444
steps:
4545
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
46-
- name: Build
46+
- name: Test
4747
run: |
48-
xcodebuild build \
48+
xcodebuild test \
4949
-scheme SlidableImage \
5050
-destination 'platform=iOS Simulator,name=iPhone 16,OS=${{ matrix.os }}' \
5151
CODE_SIGNING_REQUIRED=NO \

PLAN.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Audit & Improvement Plan
2+
3+
## PR 1 — Modernizacja CI
4+
**Branch:** `ci/modernize-workflows`
5+
**Commit:** `ci: modernize GitHub Actions workflows`
6+
7+
- `ContinuousIntegration.yml`: `checkout@v2``checkout@v4`, `macos-latest``macos-15`, dodać `swift test`
8+
- `swiftlint.yml`: `checkout@v1``v4`, zaktualizować `norio-nomura/action-swiftlint`
9+
10+
---
11+
12+
## PR 2 — Naprawa SwiftLint
13+
**Branch:** `fix/swiftlint-config`
14+
**Commit:** `fix: repair SwiftLint configuration`
15+
16+
- Usunąć `Sources` z `excluded` (cały kod źródłowy jest wyciszony)
17+
- Usunąć zduplikowany klucz `excluded:`
18+
- Podnieść lub usunąć `line_length: 140`
19+
20+
---
21+
22+
## PR 3 — Aktualizacja wersji Swift
23+
**Branch:** `chore/update-swift-version`
24+
**Commit:** `chore: align Swift version across configuration files`
25+
26+
- `.swift-version`: `5.5``6.1`
27+
- `Package.swift`: `swift-tools-version: 5.10.0``6.1`
28+
29+
---
30+
31+
## PR 4 — Migracja Preview API
32+
**Branch:** `refactor/preview-macro`
33+
**Commit:** `refactor: migrate previews from PreviewProvider to #Preview macro`
34+
35+
- `SlidableImage.swift`, `Arrows.swift`, `Triangle.swift`: zamienić przestarzałe `PreviewProvider` na `#Preview {}`
36+
37+
---
38+
39+
## PR 5 — Zastąpienie Jazzy przez DocC
40+
**Branch:** `ci/replace-jazzy-with-docc`
41+
**Commit:** `ci: replace Jazzy documentation with DocC`
42+
43+
- Usunąć `PublishDocumentation.yml`
44+
- Dodać `docs.yml` (DocC + GitHub Pages via Actions)
45+
- Zmienić Pages source na `workflow`
46+
47+
---
48+
49+
## PR 6 — Testy
50+
**Branch:** `test/add-unit-tests`
51+
**Commit:** `test: add test target and unit tests`
52+
53+
- Dodać `testTarget` do `Package.swift`
54+
- Pokryć testami: obliczenia maski, boundary conditions, inicjalizacje
55+
56+
---
57+
58+
## PR 7 — README
59+
**Branch:** `docs/improve-readme`
60+
**Commit:** `docs: rewrite README with accurate content and examples`
61+
62+
- Naprawić literówkę `Instalation``Installation`
63+
- Zaktualizować badge CI
64+
- Dodać badge Swift Package Index
65+
- Rozszerzyć przykłady użycia
66+
- Dodać link do dokumentacji (po PR 5)
67+
68+
---
69+
70+
## Kolejność realizacji
71+
72+
```
73+
PR 1, PR 2, PR 3 ← równolegle
74+
75+
PR 4, PR 6
76+
77+
PR 5
78+
79+
PR 7
80+
```

Package.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ let package = Package(
1919
],
2020
targets: [
2121
.target(name: "SlidableImage"),
22+
.testTarget(
23+
name: "SlidableImageTests",
24+
dependencies: ["SlidableImage"]
25+
),
2226
]
2327
)

Sources/SlidableImage/SlidableImage.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public struct SlidableImage<ArrowsIcon: View, LeftView: View, RightView: View>:
4646
}
4747
}
4848

49-
private func maskSize(width: CGFloat) -> CGFloat {
50-
guard let location = location?.x else {
49+
package func maskSize(width: CGFloat, locationX: CGFloat? = nil) -> CGFloat {
50+
guard let locationX = locationX ?? location?.x else {
5151
return width / 2
5252
}
5353

54-
return width - location - Constants.arrowSize / 2
54+
return width - locationX - Constants.arrowSize / 2
5555
}
5656
}
5757

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Testing
2+
import SwiftUI
3+
@testable import SlidableImage
4+
5+
@MainActor
6+
struct SlidableImageTests {
7+
8+
private func makeSUT() -> SlidableImage<Arrows, Color, Color> {
9+
SlidableImage(arrows: { Arrows() }, leftView: { Color.red }, rightView: { Color.green })
10+
}
11+
12+
@Test func maskSizeWithoutLocation() {
13+
#expect(makeSUT().maskSize(width: 200) == 100)
14+
}
15+
16+
@Test func maskSizeWithLocationAtStart() {
17+
let result = makeSUT().maskSize(width: 200, locationX: 0)
18+
#expect(result == 200 - Constants.arrowSize / 2)
19+
}
20+
21+
@Test func maskSizeWithLocationAtCenter() {
22+
let result = makeSUT().maskSize(width: 200, locationX: 100)
23+
#expect(result == 100 - Constants.arrowSize / 2)
24+
}
25+
26+
@Test func maskSizeWithLocationAtBoundary() {
27+
let locationX = 200 - Constants.arrowSize
28+
let result = makeSUT().maskSize(width: 200, locationX: locationX)
29+
#expect(result == Constants.arrowSize / 2)
30+
}
31+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Testing
2+
import SwiftUI
3+
@testable import SlidableImage
4+
5+
struct TriangleTests {
6+
7+
@Test func pathFitsInRect() {
8+
let rect = CGRect(x: 0, y: 0, width: 100, height: 100)
9+
let path = Triangle().path(in: rect)
10+
#expect(path.boundingRect.width <= rect.width)
11+
#expect(path.boundingRect.height <= rect.height)
12+
}
13+
14+
@Test func pathBoundingRectMatchesRect() {
15+
let rect = CGRect(x: 0, y: 0, width: 50, height: 80)
16+
let path = Triangle().path(in: rect)
17+
#expect(path.boundingRect.minX >= rect.minX)
18+
#expect(path.boundingRect.minY >= rect.minY)
19+
#expect(path.boundingRect.maxX <= rect.maxX)
20+
#expect(path.boundingRect.maxY <= rect.maxY)
21+
}
22+
23+
@Test func pathWithNonZeroOrigin() {
24+
let rect = CGRect(x: 10, y: 20, width: 60, height: 80)
25+
let path = Triangle().path(in: rect)
26+
#expect(path.boundingRect.minX >= rect.minX)
27+
#expect(path.boundingRect.minY >= rect.minY)
28+
#expect(path.boundingRect.maxX <= rect.maxX)
29+
#expect(path.boundingRect.maxY <= rect.maxY)
30+
}
31+
32+
@Test func pathWithZeroSize() {
33+
let rect = CGRect.zero
34+
let path = Triangle().path(in: rect)
35+
#expect(path.boundingRect == .zero)
36+
}
37+
}

0 commit comments

Comments
 (0)