Repository navigation
Expand file tree
/
Copy pathGradientActivityIndicatorView+ViewModelTests.swift
More file actions
172 lines (130 loc) · 4.06 KB
/
Copy pathGradientActivityIndicatorView+ViewModelTests.swift
File metadata and controls
172 lines (130 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// GradientActivityIndicatorView+ViewModelTests.swift
// GradientLoadingBarTests
//
// Created by Felix Mau on 26.08.19.
// Copyright © 2019 Felix Mau. All rights reserved.
//
import Testing
import UIKit
@testable import GradientLoadingBar
@MainActor
struct `GradientActivityIndicatorView+ViewModelTests` {
// swiftlint:disable:previous type_name
// MARK: - Types
typealias ViewModel = GradientActivityIndicatorView.ViewModel
// MARK: - Test Property `isHidden`
@Test
func `WHEN initialized THEN isHidden should be false`() {
// When
let viewModel = ViewModel()
// Then
#expect(!viewModel.isHidden)
}
// MARK: - Test Property `isAnimating`
@Test
func `WHEN isHidden is false THEN isAnimating should be true`() {
// Given
let viewModel = ViewModel()
// When
viewModel.isHidden = false
// Then
#expect(viewModel.isAnimating)
}
@Test
func `WHEN isHidden is true THEN isAnimating should be false`() {
// Given
let viewModel = ViewModel()
// When
viewModel.isHidden = true
// Then
#expect(!viewModel.isAnimating)
}
// MARK: - Test Property `bounds`
@Test
func `WHEN initialized THEN bounds should be zero`() {
// When
let viewModel = ViewModel()
// Then
#expect(viewModel.bounds == .zero)
}
// MARK: - Test Property `gradientLayerFrame`
@Test
func `WHEN setting bounds THEN gradientLayerFrame should be updated with correct width`() {
// Given
let viewModel = ViewModel()
let size = CGSize(
width: .random(in: 1 ... 100_000),
height: .random(in: 1 ... 100_000),
)
// When
viewModel.bounds = CGRect(origin: .zero, size: size)
// Then
let expectedFrame = CGRect(
origin: .zero,
size: CGSize(width: size.width * 3, height: size.height),
)
#expect(viewModel.gradientLayerFrame == expectedFrame)
}
// MARK: - Test Property `animationFromValue`
@Test
func `WHEN setting bounds THEN animationFromValue should be updated with correct value`() {
// Given
let viewModel = ViewModel()
let size = CGSize(
width: .random(in: 1 ... 100_000),
height: .random(in: 1 ... 100_000),
)
// When
viewModel.bounds = CGRect(origin: .zero, size: size)
// Then
#expect(viewModel.animationFromValue == size.width * -2)
}
// MARK: - Test Property `animationToValue`
@Test
func `WHEN initialized THEN animationToValue should be zero`() {
// When
let viewModel = ViewModel()
// Then
#expect(viewModel.animationToValue == 0)
}
// MARK: - Test Property `gradientColors`
@Test
func `WHEN initialized THEN gradientColors should equal default colors`() {
// When
let viewModel = ViewModel()
// Then
#expect(viewModel.gradientColors == UIColor.GradientLoadingBar.gradientColors)
}
// MARK: - Test Property `gradientLayerColors`
@Test
func `WHEN setting gradientColors with a single color THEN gradientLayerColors should equal the single color`() {
// Given
let viewModel = ViewModel()
let gradientColors: [UIColor] = [.red]
// When
viewModel.gradientColors = gradientColors
// Then
let expectedGradientLayerColors = [UIColor.red].map(\.cgColor)
#expect(viewModel.gradientLayerColors == expectedGradientLayerColors)
}
@Test
func `WHEN setting gradientColors THEN gradientLayerColors should equal the infinite gradient colors`() {
// Given
let viewModel = ViewModel()
let gradientColors: [UIColor] = [.red, .yellow, .green]
// When
viewModel.gradientColors = gradientColors
// Then
let expectedGradientLayerColors = [UIColor.red, .yellow, .green, .yellow, .red, .yellow, .green].map(\.cgColor)
#expect(viewModel.gradientLayerColors == expectedGradientLayerColors)
}
// MARK: - Test Property `progressAnimationDuration`
@Test
func `WHEN initialized THEN progressAnimationDuration should contain default duration`() {
// When
let viewModel = ViewModel()
// Then
#expect(viewModel.progressAnimationDuration == TimeInterval.GradientLoadingBar.progressDuration)
}
}