Skip to content

Commit da0f6fc

Browse files
authored
Merge pull request #1741 from StoDevX/accessibility-homescreen-buttons
Make homescreen buttons be buttons
2 parents 5832c29 + 1b8014d commit da0f6fc

File tree

4 files changed

+91
-56
lines changed

4 files changed

+91
-56
lines changed

fastlane/platforms/ios.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@
66

77
desc 'Take screenshots'
88
lane :screenshot do
9-
snapshot(devices: ['iPhone 7 Plus', 'iPhone 6', 'iPhone 5s'],
9+
devices = [
10+
'iPhone 7 Plus',
11+
'iPhone 6',
12+
'iPhone 5s',
13+
# 'iPhone 4s',
14+
'iPad Pro (9.7-inch)',
15+
'iPad Pro (12.9-inch)',
16+
]
17+
snapshot(devices: devices,
1018
languages: ['en-US'],
1119
scheme: ENV['GYM_SCHEME'],
12-
project: ENV['GYM_PROJECT'])
20+
project: ENV['GYM_PROJECT'],
21+
# concurrent_simulators: false,
22+
number_of_retries: 0)
1323
end
1424

1525
desc 'Builds the app'

ios/AllAboutOlafUITests/AllAboutOlafUITests.swift

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,80 +39,81 @@ class AllAboutOlafUITests: XCTestCase {
3939
}
4040

4141
func testOpenMenusScreen() {
42-
app.otherElements["Menus"].tap()
42+
app.buttons["Menus"].tap()
4343
sleep(5)
4444
snapshot("01MenusScreenStavMenu")
4545
}
4646

4747
func testOpenSisScreen() {
48-
app.otherElements["SIS"].tap()
48+
app.buttons["SIS"].tap()
4949
sleep(1)
5050
snapshot("02SisScreen")
5151
}
5252

5353
func testOpenBuildingHoursScreen() {
54-
app.otherElements["Building Hours"].tap()
54+
app.buttons["Building Hours"].tap()
5555
sleep(1)
5656
snapshot("03BuildingHoursScreen")
5757
}
5858

5959
func testOpenWebcamsScreen() {
60-
app.otherElements["Streaming Media"].tap()
61-
app.tabBars.buttons["Webcams"].tap()
60+
app.buttons["Streaming Media"].tap()
61+
app.otherElements["  Webcams"].tap()
6262
sleep(1)
6363
snapshot("04WebcamsScreen")
6464
}
6565

6666
func testOpenCalendarScreen() {
67-
app.otherElements["Calendar"].tap()
67+
app.buttons["Calendar"].tap()
6868
sleep(5)
6969
snapshot("05CalendarScreen")
7070
}
7171

7272
func testOpenDirectoryScreen() {
73-
app.otherElements["Directory"].tap()
73+
app.buttons["Directory"].tap()
7474
sleep(5)
7575
snapshot("06DirectoryScreen")
7676
}
7777

7878
func testOpenStreamingMediaScreen() {
79-
app.otherElements["Streaming Media"].tap()
79+
app.buttons["Streaming Media"].tap()
8080
sleep(1)
8181
snapshot("07StreamingMediaScreen")
8282
}
8383

8484
func testOpenNewsScreen() {
85-
app.otherElements["News"].tap()
85+
app.buttons["News"].tap()
8686
sleep(5)
8787
snapshot("08NewsScreen")
8888
}
8989

9090
func testOpenCampusMapScreen() {
91-
app.otherElements["  Campus Map"].tap()
91+
app.buttons["Campus Map"].tap()
92+
9293
sleep(5)
9394
snapshot("09CampusMapScreen")
9495
}
9596

9697
func testOpenImportantContactsScreen() {
97-
app.otherElements["Important Contacts"].tap()
98+
app.buttons["Important Contacts"].tap()
9899
sleep(1)
99100
snapshot("10ImportantContactsScreen")
100101
}
101102

102103
func testOpenTransportationScreen() {
103-
app.otherElements["Transportation"].tap()
104+
app.buttons["Transportation"].tap()
104105
sleep(1)
105106
snapshot("11TransportationScreen")
106107
}
107108

108109
func testOpenCampusDictionaryScreen() {
109-
app.otherElements["Campus Dictionary"].tap()
110+
app.buttons["Campus Dictionary"].tap()
110111
sleep(1)
111112
snapshot("12CampusDictionaryScreen")
112113
}
113114

114115
func testOpenStudentOrgsScreen() {
115-
app.otherElements["Student Orgs"].tap()
116+
app.buttons["Student Orgs"].tap()
116117
sleep(5)
117118
snapshot("13StudentOrgsScreen")
118119
}

ios/fastlane/SnapshotHelper.swift

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
// -----------------------------------------------------
10-
// IMPORTANT: When modifying this file, make sure to
10+
// IMPORTANT: When modifying this file, make sure to
1111
// increment the version number at the very
1212
// bottom of the file to notify users about
1313
// the new SnapshotHelper.swift
@@ -32,20 +32,48 @@ func snapshot(_ name: String, waitForLoadingIndicator: Bool = true) {
3232
Snapshot.snapshot(name, waitForLoadingIndicator: waitForLoadingIndicator)
3333
}
3434

35+
enum SnapshotError: Error, CustomDebugStringConvertible {
36+
case cannotDetectUser
37+
case cannotFindHomeDirectory
38+
case cannotFindSimulatorHomeDirectory
39+
case cannotAccessSimulatorHomeDirectory(String)
40+
41+
var debugDescription: String {
42+
switch self {
43+
case .cannotDetectUser:
44+
return "Couldn't find Snapshot configuration files - can't detect current user "
45+
case .cannotFindHomeDirectory:
46+
return "Couldn't find Snapshot configuration files - can't detect `Users` dir"
47+
case .cannotFindSimulatorHomeDirectory:
48+
return "Couldn't find simulator home location. Please, check SIMULATOR_HOST_HOME env variable."
49+
case .cannotAccessSimulatorHomeDirectory(let simulatorHostHome):
50+
return "Can't prepare environment. Simulator home location is inaccessible. Does \(simulatorHostHome) exist?"
51+
}
52+
}
53+
}
54+
3555
open class Snapshot: NSObject {
56+
static var app: XCUIApplication!
57+
static var cacheDirectory: URL!
58+
static var screenshotsDirectory: URL? {
59+
return cacheDirectory.appendingPathComponent("screenshots", isDirectory: true)
60+
}
3661

3762
open class func setupSnapshot(_ app: XCUIApplication) {
38-
setLanguage(app)
39-
setLocale(app)
40-
setLaunchArguments(app)
63+
do {
64+
let cacheDir = try pathPrefix()
65+
Snapshot.cacheDirectory = cacheDir
66+
Snapshot.app = app
67+
setLanguage(app)
68+
setLocale(app)
69+
setLaunchArguments(app)
70+
} catch let error {
71+
print(error)
72+
}
4173
}
4274

4375
class func setLanguage(_ app: XCUIApplication) {
44-
guard let prefix = pathPrefix() else {
45-
return
46-
}
47-
48-
let path = prefix.appendingPathComponent("language.txt")
76+
let path = cacheDirectory.appendingPathComponent("language.txt")
4977

5078
do {
5179
let trimCharacterSet = CharacterSet.whitespacesAndNewlines
@@ -57,11 +85,7 @@ open class Snapshot: NSObject {
5785
}
5886

5987
class func setLocale(_ app: XCUIApplication) {
60-
guard let prefix = pathPrefix() else {
61-
return
62-
}
63-
64-
let path = prefix.appendingPathComponent("locale.txt")
88+
let path = cacheDirectory.appendingPathComponent("locale.txt")
6589

6690
do {
6791
let trimCharacterSet = CharacterSet.whitespacesAndNewlines
@@ -76,11 +100,7 @@ open class Snapshot: NSObject {
76100
}
77101

78102
class func setLaunchArguments(_ app: XCUIApplication) {
79-
guard let prefix = pathPrefix() else {
80-
return
81-
}
82-
83-
let path = prefix.appendingPathComponent("snapshot-launch_arguments.txt")
103+
let path = cacheDirectory.appendingPathComponent("snapshot-launch_arguments.txt")
84104
app.launchArguments += ["-FASTLANE_SNAPSHOT", "YES", "-ui_testing"]
85105

86106
do {
@@ -105,12 +125,18 @@ open class Snapshot: NSObject {
105125

106126
sleep(1) // Waiting for the animation to be finished (kind of)
107127

108-
#if os(tvOS)
109-
XCUIApplication().childrenMatchingType(.Browser).count
110-
#elseif os(OSX)
128+
#if os(OSX)
111129
XCUIApplication().typeKey(XCUIKeyboardKeySecondaryFn, modifierFlags: [])
112130
#else
113-
XCUIDevice.shared().orientation = .unknown
131+
let screenshot = app.windows.firstMatch.screenshot()
132+
guard let simulator = ProcessInfo().environment["SIMULATOR_DEVICE_NAME"], let screenshotsDir = screenshotsDirectory else { return }
133+
let path = screenshotsDir.appendingPathComponent("\(simulator)-\(name).png")
134+
do {
135+
try screenshot.pngRepresentation.write(to: path)
136+
} catch let error {
137+
print("Problem writing screenshot: \(name) to \(path)")
138+
print(error)
139+
}
114140
#endif
115141
}
116142

@@ -127,30 +153,26 @@ open class Snapshot: NSObject {
127153
}
128154
}
129155

130-
class func pathPrefix() -> URL? {
156+
class func pathPrefix() throws -> URL? {
131157
let homeDir: URL
132-
//on OSX config is stored in /Users/<username>/Library
133-
//and on iOS/tvOS/WatchOS it's in simulator's home dir
158+
// on OSX config is stored in /Users/<username>/Library
159+
// and on iOS/tvOS/WatchOS it's in simulator's home dir
134160
#if os(OSX)
135161
guard let user = ProcessInfo().environment["USER"] else {
136-
print("Couldn't find Snapshot configuration files - can't detect current user ")
137-
return nil
162+
throw SnapshotError.cannotDetectUser
138163
}
139164

140165
guard let usersDir = FileManager.default.urls(for: .userDirectory, in: .localDomainMask).first else {
141-
print("Couldn't find Snapshot configuration files - can't detect `Users` dir")
142-
return nil
166+
throw SnapshotError.cannotFindHomeDirectory
143167
}
144168

145169
homeDir = usersDir.appendingPathComponent(user)
146170
#else
147171
guard let simulatorHostHome = ProcessInfo().environment["SIMULATOR_HOST_HOME"] else {
148-
print("Couldn't find simulator home location. Please, check SIMULATOR_HOST_HOME env variable.")
149-
return nil
172+
throw SnapshotError.cannotFindSimulatorHomeDirectory
150173
}
151174
guard let homeDirUrl = URL(string: simulatorHostHome) else {
152-
print("Can't prepare environment. Simulator home location is inaccessible. Does \(simulatorHostHome) exist?")
153-
return nil
175+
throw SnapshotError.cannotAccessSimulatorHomeDirectory(simulatorHostHome)
154176
}
155177
homeDir = URL(fileURLWithPath: homeDirUrl.path)
156178
#endif
@@ -170,4 +192,4 @@ extension XCUIElement {
170192

171193
// Please don't remove the lines below
172194
// They are used to detect outdated configuration files
173-
// SnapshotHelperVersion [1.4]
195+
// SnapshotHelperVersion [1.5]

source/views/home/button.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ import type {ViewType} from '../views'
77
import {Touchable} from '../components/touchable'
88
import * as c from '../components/colors'
99

10-
export function HomeScreenButton({
11-
view,
12-
onPress,
13-
}: {
10+
type Props = {
1411
view: ViewType,
1512
onPress: () => any,
16-
}) {
13+
}
14+
15+
export function HomeScreenButton({view, onPress}: Props) {
1716
const style = {backgroundColor: view.tint}
1817

1918
return (
2019
<Touchable
2120
highlight={false}
2221
onPress={onPress}
2322
style={[styles.rectangle, style]}
23+
accessibilityLabel={view.title}
24+
accessibilityTraits="button"
25+
accessibilityComponentType="button"
2426
>
2527
<Icon name={view.icon} size={32} style={styles.rectangleButtonIcon} />
2628
<Text style={styles.rectangleButtonText}>{view.title}</Text>

0 commit comments

Comments
 (0)