Skip to content

Commit 2ab91c9

Browse files
committed
Test progress labels and styles
1 parent 34c618b commit 2ab91c9

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

‎AndroidSwiftUICore/Tests/AndroidSwiftUICoreTests/ControlTests.swift‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,48 @@ struct ControlTests {
106106
#expect(isFocused(node.children[1]) == true)
107107
}
108108

109+
@Test("ProgressView keeps determinacy and shape independent")
110+
func progressViewStyle() {
111+
// no value, no style: indeterminate, and the interpreter picks circular
112+
let plain = ViewHost(ProgressView()).evaluate()
113+
#expect(plain.props["value"] == nil)
114+
#expect(plain.modifiers.first { $0.kind == "progressViewStyle" } == nil)
115+
116+
// a value is normalized against total
117+
let valued = ViewHost(ProgressView(value: 25.0, total: 100.0)).evaluate()
118+
#expect(valued.props["value"] == .double(0.25))
119+
120+
// a determinate circular bar — impossible before, since shape was
121+
// inferred from determinacy
122+
let circular = ViewHost(ProgressView(value: 0.5).progressViewStyle(.circular)).evaluate()
123+
#expect(circular.props["value"] == .double(0.5))
124+
#expect(circular.modifiers.first { $0.kind == "progressViewStyle" }?.args["style"] == .string("circular"))
125+
126+
// and an indeterminate linear one
127+
let linear = ViewHost(ProgressView().progressViewStyle(.linear)).evaluate()
128+
#expect(linear.props["value"] == nil)
129+
#expect(linear.modifiers.first { $0.kind == "progressViewStyle" }?.args["style"] == .string("linear"))
130+
}
131+
132+
@Test("ProgressView carries a label when given one")
133+
func progressViewLabel() {
134+
let titled = ViewHost(ProgressView("Loading")).evaluate()
135+
#expect(firstTextString(titled) == "Loading")
136+
#expect(titled.props["value"] == nil)
137+
138+
let both = ViewHost(ProgressView("Copying", value: 0.4)).evaluate()
139+
#expect(firstTextString(both) == "Copying")
140+
#expect(both.props["value"] == .double(0.4))
141+
142+
// the builder form takes any view
143+
let built = ViewHost(ProgressView(value: 0.1) { Text("Custom") }).evaluate()
144+
#expect(firstTextString(built) == "Custom")
145+
146+
// and the label-free forms stay label-free
147+
#expect(ViewHost(ProgressView()).evaluate().children.isEmpty)
148+
#expect(ViewHost(ProgressView(value: 0.5)).evaluate().children.isEmpty)
149+
}
150+
109151
@Test("Picker emits tagged children and maps the selection string back")
110152
func picker() {
111153
struct Screen: View {

0 commit comments

Comments
 (0)