Skip to content

Commit

Permalink
UI tests (#46)
Browse files Browse the repository at this point in the history
* Add UI tests

* Use Fastlane to run tests

* Enable parallel testing
  • Loading branch information
ohitsdaniel authored Feb 23, 2021
1 parent 27c2c73 commit db23344
Show file tree
Hide file tree
Showing 31 changed files with 1,017 additions and 80 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ jobs:
bundler --version
- name: Run tests
run: make test

- name: danger
env:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bundle exec danger
run: make test

- name: Clean up
run: make cleanup
3 changes: 2 additions & 1 deletion Dangerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
xcov.report(
scheme: 'swift-composable-navigator-Package',
workspace: 'Example/Example.xcworkspace',
scheme: 'Example',
derived_data_path: './Build',
html_report: false,
include_targets: 'ComposableNavigator.framework, ComposableNavigatorTCA.framework, ComposableDeeplinking.framework'
Expand Down
261 changes: 229 additions & 32 deletions Example/Example.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@
"version": "0.2.0"
}
},
{
"package": "Logger",
"repositoryURL": "https://github.com/shibapm/Logger",
"state": {
"branch": null,
"revision": "53c3ecca5abe8cf46697e33901ee774236d94cce",
"version": "0.2.3"
}
},
{
"package": "PackageConfig",
"repositoryURL": "https://github.com/shibapm/PackageConfig.git",
"state": {
"branch": null,
"revision": "bf90dc69fa0792894b08a0b74cf34029694ae486",
"version": "0.13.0"
}
},
{
"package": "Rocket",
"repositoryURL": "https://github.com/shibapm/Rocket",
"state": {
"branch": null,
"revision": "25613f7ffd16105c74417c1b4eb4c93fd04e2cdf",
"version": "1.1.0"
}
},
{
"package": "swift-case-paths",
"repositoryURL": "https://github.com/pointfreeco/swift-case-paths",
Expand All @@ -36,6 +63,24 @@
"revision": "c466812aa2e22898f27557e2e780d3aad7a27203",
"version": "1.8.2"
}
},
{
"package": "SwiftShell",
"repositoryURL": "https://github.com/kareman/SwiftShell",
"state": {
"branch": null,
"revision": "a6014fe94c3dbff0ad500e8da4f251a5d336530b",
"version": "5.1.0-beta.1"
}
},
{
"package": "Yams",
"repositoryURL": "https://github.com/jpsim/Yams",
"state": {
"branch": null,
"revision": "c947a306d2e80ecb2c0859047b35c73b8e1ca27f",
"version": "2.0.0"
}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1210"
version = "1.3">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand All @@ -28,6 +28,18 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<TestPlans>
<TestPlanReference
reference = "container:UnitTests.xctestplan">
</TestPlanReference>
<TestPlanReference
reference = "container:UITests.xctestplan">
</TestPlanReference>
<TestPlanReference
reference = "container:FullTests.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -59,6 +71,16 @@
ReferencedContainer = "container:..">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "23C9A49625E3A140005942F8"
BuildableName = "ExampleUITests.xctest"
BlueprintName = "ExampleUITests"
ReferencedContainer = "container:Example.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
10 changes: 10 additions & 0 deletions Example/Example.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
77 changes: 77 additions & 0 deletions Example/Example/Accessibility/AccessibilityIdentifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import SwiftUI

struct AccessibilityIdentifier {
let value: String
}

extension View {
func accessibility(identifier: AccessibilityIdentifier) -> some View {
accessibility(identifier: identifier.value)
}
}

extension AccessibilityIdentifier {
enum HomeScreen {
static let settingsNavigationBarItem = AccessibilityIdentifier(value: "home.settings.open")

static func detail(for id: String) -> AccessibilityIdentifier {
AccessibilityIdentifier(value: "detail.\(id)")
}

static func detailSettings(for id: String) -> AccessibilityIdentifier {
AccessibilityIdentifier(value: "detail.\(id).settings")
}
}

struct SettingsScreen {
let prefix: String

var shortcutsSheet: AccessibilityIdentifier {
AccessibilityIdentifier(value: "\(prefix).settings.shortcuts.sheet")
}

var shortcutsPush: AccessibilityIdentifier {
AccessibilityIdentifier(value: "\(prefix).settings.shortcuts.push")
}
}

struct DetailScreen {
let id: String

var shortcuts: AccessibilityIdentifier {
AccessibilityIdentifier(value: "detail.\(id).shortcuts")
}

var settings: AccessibilityIdentifier {
AccessibilityIdentifier(value: "detail.\(id).settings")
}
}

struct NavigationShortcuts {
let prefix: String

var detailShortcuts: AccessibilityIdentifier {
AccessibilityIdentifier(value: "\(prefix).detailShortcuts")
}

var detailSettings: AccessibilityIdentifier {
AccessibilityIdentifier(value: "\(prefix).detailSettings")
}

var detailSettingsShortcutsPush: AccessibilityIdentifier {
AccessibilityIdentifier(value: "\(prefix).detailSettingsShortcutsPush")
}

var detailSettingsShortcutsSheet: AccessibilityIdentifier {
AccessibilityIdentifier(value: "\(prefix).detailSettingsShortcutsSheet")
}

var homeSettings: AccessibilityIdentifier {
AccessibilityIdentifier(value: "\(prefix).homeSettings")
}

var home: AccessibilityIdentifier {
AccessibilityIdentifier(value: "\(prefix).home")
}
}
}
51 changes: 32 additions & 19 deletions Example/Example/Detail Screen/DetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,32 @@ struct DetailScreen: Screen {
store: Store<DetailState, DetailAction>,
settingsStore: Store<SettingsState, SettingsAction>
) -> some PathBuilder {
PathBuilders.screen(
DetailScreen.self,
content: {
DetailView(
store: store
PathBuilders.if(
screen: { (screen: DetailScreen) in
PathBuilders.screen(
DetailScreen.self,
content: {
DetailView(
store: store
)
},
nesting: PathBuilders.anyOf(
SettingsScreen.builder(
store: settingsStore,
entrypoint: "detail.\(screen.detailID)"
)
.onDismiss(of: SettingsScreen.self) {
print("Detail settings dismissed")
},
NavigationShortcutsScreen.builder(
store: store.scope(
state: \.navigationShortcuts,
action: DetailAction.navigationShortcuts
)
)
},
nesting: PathBuilders.anyOf(
SettingsScreen.builder(
store: settingsStore
)
.onDismiss(of: SettingsScreen.self) {
print("Detail settings dismissed")
},
NavigationShortcutsScreen.builder(
store: store.scope(
state: \.navigationShortcuts,
action: DetailAction.navigationShortcuts
)
)
)
}
)
}
}
Expand All @@ -79,8 +84,13 @@ struct DetailView: View {
},
label: { Text("Go to [home/detail?id=\(viewStore.id)/shortcuts]") }
)
.accessibility(
identifier: AccessibilityIdentifier.DetailScreen(id: viewStore.id).shortcuts
)

NavigationShortcuts()
NavigationShortcuts(
accessibilityIdentifiers: AccessibilityIdentifier.NavigationShortcuts(prefix: "detail.\(viewStore.id).shortcuts")
)
Spacer()
}
Spacer()
Expand All @@ -91,6 +101,9 @@ struct DetailView: View {
action: { viewStore.send(.settingsButtonTapped(currentID))},
label: { Image(systemName: "gear") }
)
.accessibility(
identifier: AccessibilityIdentifier.DetailScreen(id: viewStore.id).settings
)
)
.navigationBarTitle("Detail for \(viewStore.id)")
}
Expand Down
6 changes: 1 addition & 5 deletions Example/Example/ExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ struct ExampleApp: App {

init() {
dataSource = Navigator.Datasource(
path: [
HomeScreen().eraseToAnyScreen(),
DetailScreen(detailID: "0").eraseToAnyScreen(),
SettingsScreen().eraseToAnyScreen()
]
root: HomeScreen()
)

navigator = Navigator(dataSource: dataSource).debug()
Expand Down
10 changes: 9 additions & 1 deletion Example/Example/Home Screen/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ struct HomeView: View {
Text("Element \(element)")
}
)
.accessibility(identifier: AccessibilityIdentifier.HomeScreen.detail(for: element))

Spacer()
Image(systemName: "gear")
.foregroundColor(.gray)
Expand All @@ -73,6 +75,8 @@ struct HomeView: View {
.openSettings(for: element, on: currentScreenID)
)
}
.accessibility(addTraits: [.isButton])
.accessibility(identifier: AccessibilityIdentifier.HomeScreen.detailSettings(for: element))
}
}
)
Expand All @@ -85,6 +89,7 @@ struct HomeView: View {
action: { viewStore.send(.settingsButtonTapped) },
label: { Image(systemName: "gear") }
)
.accessibility(identifier: AccessibilityIdentifier.HomeScreen.settingsNavigationBarItem)
)
.navigationBarTitle("Example App")
}
Expand Down Expand Up @@ -145,7 +150,10 @@ struct HomeScreen: Screen {
}
}
),
SettingsScreen.builder(store: settingsStore)
SettingsScreen.builder(
store: settingsStore,
entrypoint: "home"
)
)
.onDismiss { (screen: DetailScreen) in
print("Dismissed \(screen)")
Expand Down
Loading

0 comments on commit db23344

Please sign in to comment.