Skip to content

Commit ef1f124

Browse files
committed
test: fix tests with typos in buttons and initial states
Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
1 parent 7a54796 commit ef1f124

File tree

6 files changed

+30
-35
lines changed

6 files changed

+30
-35
lines changed

DesignToolbox/DesignToolbox/Pages/Components/Checkbox/CheckboxPicker/CheckboxPickerPage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct CheckboxPickerPage: View {
3838

3939
private struct CheckboxPickerDemo: View {
4040

41-
@State private var selections: [String] = ["Choice_1"] // cf configurationModel.populate()
41+
@State private var selections: [String] = []
4242
@ObservedObject var configurationModel: CheckboxPickerConfigurationModel
4343
@Environment(\.theme) private var theme
4444

DesignToolbox/DesignToolbox/Resources/Localizable.xcstrings

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -897,19 +897,19 @@
897897
"localizations" : {
898898
"ar" : {
899899
"stringUnit" : {
900-
"state" : "translated",
900+
"state" : "needs_review",
901901
"value" : "Checkbox Item"
902902
}
903903
},
904904
"en" : {
905905
"stringUnit" : {
906906
"state" : "translated",
907-
"value" : "Checkbox item"
907+
"value" : "Checkbox Item"
908908
}
909909
},
910910
"fr" : {
911911
"stringUnit" : {
912-
"state" : "translated",
912+
"state" : "needs_review",
913913
"value" : "Checkbox Item"
914914
}
915915
}
@@ -2347,23 +2347,24 @@
23472347
"localizations" : {
23482348
"ar" : {
23492349
"stringUnit" : {
2350-
"state" : "translated",
2350+
"state" : "needs_review",
23512351
"value" : "Switch Item"
23522352
}
23532353
},
23542354
"en" : {
23552355
"stringUnit" : {
23562356
"state" : "translated",
2357-
"value" : "Switch item"
2357+
"value" : "Switch Item"
23582358
}
23592359
},
23602360
"fr" : {
23612361
"stringUnit" : {
2362-
"state" : "translated",
2362+
"state" : "needs_review",
23632363
"value" : "Switch Item"
23642364
}
23652365
}
2366-
}
2366+
},
2367+
"shouldTranslate" : false
23672368
},
23682369
"app_tokens_border_description_text" : {
23692370
"comment" : "Tokens - Border",

DesignToolbox/DesignToolboxUITests/Components/Checkboxes/CheckboxItemUITests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ final class CheckboxItemUITests: AppTestCase {
2626
let app = launchApp()
2727
goToComponentsSheet(app)
2828
tapButton(withWording: "app_components_checkbox_label", app)
29+
waitForButtonToAppear(withWording: "Checkbox Item", app)
2930
tapButton(withWording: "Checkbox Item", app)
3031

3132
let checkbox = otherElements(withA11yIdentifier: A11YIdentifiers.componentCheckboxItem, app).firstMatch

DesignToolbox/DesignToolboxUITests/Components/Checkboxes/CheckboxPickerUITests.swift

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import XCTest
1919
/// Tests the accessibility identifiers, labels or values of the items depending to their states and user actions.
2020
final class CheckboxPickerUITests: AppTestCase {
2121

22-
/// Select several items and checks if the counter in the root item is updated with the suitable value
22+
/// Select several items and checks if the counter in the root item is updated with the suitable values.
23+
/// beware, we test the accessiiblity value here as until now label is not dynamically updated with count.
2324
@MainActor func testCheckboxPickerRootItemCount() throws {
2425

2526
// GIVEN
@@ -29,27 +30,23 @@ final class CheckboxPickerUITests: AppTestCase {
2930
tapButton(withWording: "app_components_checkbox_label", app)
3031
tapButton(withWording: "app_components_checkboxPicker_label", app)
3132

32-
// By default, one element is selected in the picker, wording cannot be used as is
33-
var expectedPickerRootItemString = wording(for: "app_components_checkboxPicker_root") + " (1)"
34-
assertStaticTextExists(expectedPickerRootItemString, app)
33+
// By default, no element is selected in the picker, wording cannot be used as is
34+
check(value: pickerRootItemA11yValue(with: 0), ofElementWithIdentifier: pickerRootItemA11yIdentifier(with: 0), app)
3535

3636
// WHEN, THEN
3737

38-
// Select all
3938
tapImage(withName: "dog.fill", app)
4039
tapImage(withName: "waterbottle.fill", app)
41-
expectedPickerRootItemString = wording(for: "app_components_checkboxPicker_root") + " (3)"
42-
assertStaticTextExists(expectedPickerRootItemString, app)
40+
check(value: pickerRootItemA11yValue(with: 2), ofElementWithIdentifier: pickerRootItemA11yIdentifier(with: 2), app)
4341

44-
// Unselect some
4542
tapImage(withName: "dog.fill", app)
46-
expectedPickerRootItemString = wording(for: "app_components_checkboxPicker_root") + " (2)"
47-
assertStaticTextExists(expectedPickerRootItemString, app)
43+
check(value: pickerRootItemA11yValue(with: 1), ofElementWithIdentifier: pickerRootItemA11yIdentifier(with: 1), app)
4844

49-
// Unselect all
5045
tapImage(withName: "flame", app)
51-
tapImage(withName: "waterbottle.fill", app)
52-
expectedPickerRootItemString = wording(for: "app_components_checkboxPicker_root")
46+
check(value: pickerRootItemA11yValue(with: 2), ofElementWithIdentifier: pickerRootItemA11yIdentifier(with: 2), app)
47+
48+
tapImage(withName: "dog.fill", app)
49+
check(value: pickerRootItemA11yValue(with: 3), ofElementWithIdentifier: pickerRootItemA11yIdentifier(with: 3), app)
5350
}
5451

5552
/// Given the checkbox picker of the demo app,
@@ -71,25 +68,13 @@ final class CheckboxPickerUITests: AppTestCase {
7168
tapButton(withWording: "app_components_checkbox_label", app)
7269
tapButton(withWording: "app_components_checkboxPicker_label", app)
7370

74-
check(value: selectedA11Yvalue, ofElementWithIdentifier: firstItemA11YIdentifier, app)
75-
check(value: unselectedA11Yvalue, ofElementWithIdentifier: secondItemA11YIdentifier, app)
76-
check(value: unselectedA11Yvalue, ofElementWithIdentifier: thirdItemA11YIdentifier, app)
77-
78-
// WHEN
79-
80-
var itemToSelect = otherElements(withA11yIdentifier: firstItemA11YIdentifier, app).firstMatch
81-
itemToSelect.tap()
82-
83-
// THEN
84-
85-
check(value: pickerRootItemA11yValue(with: 0), ofElementWithLabel: rootItemA11YLabel, app)
8671
check(value: unselectedA11Yvalue, ofElementWithIdentifier: firstItemA11YIdentifier, app)
8772
check(value: unselectedA11Yvalue, ofElementWithIdentifier: secondItemA11YIdentifier, app)
8873
check(value: unselectedA11Yvalue, ofElementWithIdentifier: thirdItemA11YIdentifier, app)
8974

9075
// WHEN
9176

92-
itemToSelect = otherElements(withA11yIdentifier: firstItemA11YIdentifier, app).firstMatch
77+
var itemToSelect = otherElements(withA11yIdentifier: firstItemA11YIdentifier, app).firstMatch
9378
itemToSelect.tap()
9479

9580
// THEN

DesignToolbox/DesignToolboxUITests/Components/Switches/SwitchItemUITests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ final class SwitchItemUITests: AppTestCase {
2828
swipeFromDownToUp(app)
2929
swipeFromDownToUp(app)
3030
tapButton(withWording: "app_components_switch_label", app)
31+
waitForButtonToAppear(withWording: "Switch Item", app)
3132
tapButton(withWording: "Switch Item", app)
3233

3334
let switchItem = otherElements(withA11yIdentifier: A11YIdentifiers.componentSwitchItem, app).firstMatch

DesignToolbox/DesignToolboxUITests/Utils/AppTestCase.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ open class AppTestCase: XCTestCase {
117117

118118
// MARK: - Helpers
119119

120+
@MainActor func waitForButtonToAppear(withWording key: String, _ app: XCUIApplication, _ timeout: TimeInterval = 5) {
121+
let wording = wording(for: key)
122+
let buttonToWaitFor = app.buttons[wording]
123+
let doesButtonExist = buttonToWaitFor.waitForExistence(timeout: timeout)
124+
XCTAssertTrue(doesButtonExist, "The button with wording '\(wording)' did not appear after \(timeout) seconds")
125+
}
126+
120127
/// Checks if the first element with this a11y identifier exists and has the wording with the given value as key
121128
@MainActor func check(value: String, ofElementWithIdentifier identifier: String, _ app: XCUIApplication) {
122129
let element = otherElements(withA11yIdentifier: identifier, app).firstMatch
@@ -126,7 +133,7 @@ open class AppTestCase: XCTestCase {
126133
XCTAssertTrue(currentValue == expectedValue,
127134
"The expected accessible value for the element is '\(expectedValue)' and not '\(currentValue)'")
128135
} else {
129-
XCTFail("The value to comapre does not exist!")
136+
XCTFail("The value to compare does not exist!")
130137
}
131138
} else {
132139
XCTFail("The element does not exists or the demo has been changed since!")

0 commit comments

Comments
 (0)