Skip to content

Commit

Permalink
add simple UI test
Browse files Browse the repository at this point in the history
  • Loading branch information
yonat committed Jul 4, 2018
1 parent a2115af commit d8dd600
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 8 deletions.
122 changes: 121 additions & 1 deletion Example/SelectionListDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,31 @@

/* Begin PBXBuildFile section */
0CE5A5188BFCAC3F6F40D0D2 /* Pods_SelectionListDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D788CEE015C796EAD8A632B0 /* Pods_SelectionListDemo.framework */; };
DC5EA87420B9F0EF00267D9B /* SelectionListDemoUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC5EA87320B9F0EF00267D9B /* SelectionListDemoUITests.swift */; };
DCFD34B7206A463A000EA166 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCFD34B6206A463A000EA166 /* AppDelegate.swift */; };
DCFD34B9206A463A000EA166 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCFD34B8206A463A000EA166 /* ViewController.swift */; };
DCFD34BC206A463A000EA166 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DCFD34BA206A463A000EA166 /* Main.storyboard */; };
DCFD34BE206A463A000EA166 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DCFD34BD206A463A000EA166 /* Assets.xcassets */; };
DCFD34C1206A463A000EA166 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DCFD34BF206A463A000EA166 /* LaunchScreen.storyboard */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
DC5EA87620B9F0EF00267D9B /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = DCFD34AB206A4639000EA166 /* Project object */;
proxyType = 1;
remoteGlobalIDString = DCFD34B2206A463A000EA166;
remoteInfo = SelectionListDemo;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
4D8F840EAA6211D35FF46B37 /* Pods-SelectionListDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SelectionListDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SelectionListDemo/Pods-SelectionListDemo.debug.xcconfig"; sourceTree = "<group>"; };
88A271D90EDD900707D18C5B /* Pods-SelectionListDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SelectionListDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-SelectionListDemo/Pods-SelectionListDemo.release.xcconfig"; sourceTree = "<group>"; };
D788CEE015C796EAD8A632B0 /* Pods_SelectionListDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SelectionListDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DC5EA87120B9F0EE00267D9B /* SelectionListDemoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SelectionListDemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
DC5EA87320B9F0EF00267D9B /* SelectionListDemoUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectionListDemoUITests.swift; sourceTree = "<group>"; };
DC5EA87520B9F0EF00267D9B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DCFD34B3206A463A000EA166 /* SelectionListDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SelectionListDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
DCFD34B6206A463A000EA166 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
DCFD34B8206A463A000EA166 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand All @@ -29,6 +43,13 @@
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
DC5EA86E20B9F0EE00267D9B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
DCFD34B0206A463A000EA166 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -48,10 +69,20 @@
name = Frameworks;
sourceTree = "<group>";
};
DC5EA87220B9F0EF00267D9B /* SelectionListDemoUITests */ = {
isa = PBXGroup;
children = (
DC5EA87320B9F0EF00267D9B /* SelectionListDemoUITests.swift */,
DC5EA87520B9F0EF00267D9B /* Info.plist */,
);
path = SelectionListDemoUITests;
sourceTree = "<group>";
};
DCFD34AA206A4639000EA166 = {
isa = PBXGroup;
children = (
DCFD34B5206A463A000EA166 /* SelectionListDemo */,
DC5EA87220B9F0EF00267D9B /* SelectionListDemoUITests */,
DCFD34B4206A463A000EA166 /* Products */,
E07C1637D13B3BED1D416ABA /* Pods */,
6C75C84F0C214B34108E65F5 /* Frameworks */,
Expand All @@ -62,6 +93,7 @@
isa = PBXGroup;
children = (
DCFD34B3206A463A000EA166 /* SelectionListDemo.app */,
DC5EA87120B9F0EE00267D9B /* SelectionListDemoUITests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -91,6 +123,24 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
DC5EA87020B9F0EE00267D9B /* SelectionListDemoUITests */ = {
isa = PBXNativeTarget;
buildConfigurationList = DC5EA87A20B9F0EF00267D9B /* Build configuration list for PBXNativeTarget "SelectionListDemoUITests" */;
buildPhases = (
DC5EA86D20B9F0EE00267D9B /* Sources */,
DC5EA86E20B9F0EE00267D9B /* Frameworks */,
DC5EA86F20B9F0EE00267D9B /* Resources */,
);
buildRules = (
);
dependencies = (
DC5EA87720B9F0EF00267D9B /* PBXTargetDependency */,
);
name = SelectionListDemoUITests;
productName = SelectionListDemoUITests;
productReference = DC5EA87120B9F0EE00267D9B /* SelectionListDemoUITests.xctest */;
productType = "com.apple.product-type.bundle.ui-testing";
};
DCFD34B2206A463A000EA166 /* SelectionListDemo */ = {
isa = PBXNativeTarget;
buildConfigurationList = DCFD34C5206A463A000EA166 /* Build configuration list for PBXNativeTarget "SelectionListDemo" */;
Expand Down Expand Up @@ -118,10 +168,15 @@
DCFD34AB206A4639000EA166 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastSwiftUpdateCheck = 0930;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Yonat Sharon";
TargetAttributes = {
DC5EA87020B9F0EE00267D9B = {
CreatedOnToolsVersion = 9.3.1;
ProvisioningStyle = Automatic;
TestTargetID = DCFD34B2206A463A000EA166;
};
DCFD34B2206A463A000EA166 = {
CreatedOnToolsVersion = 9.2;
ProvisioningStyle = Automatic;
Expand All @@ -142,11 +197,19 @@
projectRoot = "";
targets = (
DCFD34B2206A463A000EA166 /* SelectionListDemo */,
DC5EA87020B9F0EE00267D9B /* SelectionListDemoUITests */,
);
};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
DC5EA86F20B9F0EE00267D9B /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
DCFD34B1206A463A000EA166 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -225,6 +288,14 @@
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
DC5EA86D20B9F0EE00267D9B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DC5EA87420B9F0EF00267D9B /* SelectionListDemoUITests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
DCFD34AF206A463A000EA166 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -236,6 +307,14 @@
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
DC5EA87720B9F0EF00267D9B /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = DCFD34B2206A463A000EA166 /* SelectionListDemo */;
targetProxy = DC5EA87620B9F0EF00267D9B /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
DCFD34BA206A463A000EA166 /* Main.storyboard */ = {
isa = PBXVariantGroup;
Expand All @@ -256,6 +335,38 @@
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
DC5EA87820B9F0EF00267D9B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = SelectionListDemoUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roysharon.SelectionListDemoUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = SelectionListDemo;
};
name = Debug;
};
DC5EA87920B9F0EF00267D9B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = SelectionListDemoUITests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roysharon.SelectionListDemoUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = SelectionListDemo;
};
name = Release;
};
DCFD34C3206A463A000EA166 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -402,6 +513,15 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
DC5EA87A20B9F0EF00267D9B /* Build configuration list for PBXNativeTarget "SelectionListDemoUITests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
DC5EA87820B9F0EF00267D9B /* Debug */,
DC5EA87920B9F0EF00267D9B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
DCFD34AE206A4639000EA166 /* Build configuration list for PBXProject "SelectionListDemo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
11 changes: 4 additions & 7 deletions Example/SelectionListDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -25,24 +25,21 @@
<constraint firstAttribute="height" constant="128" id="ANB-ed-pEb"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="O5l-gN-Lvi">
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="O5l-gN-Lvi">
<rect key="frame" x="0.0" y="220" width="375" height="64"/>
<color key="backgroundColor" red="0.0" green="0.32852089410000002" blue="0.57488495110000004" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="64" id="3zZ-HT-ehr"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wks-nX-0aN" customClass="SelectionList" customModule="SelectionList">
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wks-nX-0aN" customClass="SelectionList" customModule="SelectionList">
<rect key="frame" x="0.0" y="148" width="375" height="72"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="image" keyPath="selectionImage" value="ios7-checkmark-outline.png"/>
<userDefinedRuntimeAttribute type="boolean" keyPath="allowsMultipleSelection" value="YES"/>
<userDefinedRuntimeAttribute type="image" keyPath="deselectionImage" value="ios7-circle-outline.png"/>
<userDefinedRuntimeAttribute type="boolean" keyPath="isSelectionMarkTrailing" value="NO"/>
<userDefinedRuntimeAttribute type="number" keyPath="rowHeight">
<real key="value" value="24"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
Expand Down
22 changes: 22 additions & 0 deletions Example/SelectionListDemoUITests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
36 changes: 36 additions & 0 deletions Example/SelectionListDemoUITests/SelectionListDemoUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// SelectionListDemoUITests.swift
// SelectionListDemoUITests
//
// Created by Yonat Sharon on 26.05.2018.
// Copyright © 2018 Yonat Sharon. All rights reserved.
//

import XCTest

class SelectionListDemoUITests: XCTestCase {
override func setUp() {
super.setUp()
continueAfterFailure = false
XCUIApplication().launch()
}

func testSeletion() {
let app = XCUIApplication()
let selectionList = app.tables.firstMatch

XCTAssert(selectionList.cells.element(boundBy: 1).isSelected)
XCTAssert(!selectionList.cells.element(boundBy: 3).isSelected)
XCTAssert(selectionList.cells.element(boundBy: 4).isSelected)

let firstCell = selectionList.cells.element(boundBy: 0)
XCTAssert(firstCell.isSelected)
firstCell.tap()
XCTAssert(!firstCell.isSelected)

let thirdCell = selectionList.cells.element(boundBy: 2)
XCTAssert(!thirdCell.isSelected)
thirdCell.tap()
XCTAssert(thirdCell.isSelected)
}
}
15 changes: 15 additions & 0 deletions Sources/SelectionList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import UIKit

extension SelectionList {
func setup() {
tableView.isAccessibilityElement = false
tableView.register(SelectionListCell.self, forCellReuseIdentifier: reuseIdentifier)
tableView.dataSource = self
tableView.delegate = self
Expand Down Expand Up @@ -157,6 +158,7 @@ extension SelectionList: UITableViewDataSource, UITableViewDelegate {

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath)
cell.isAccessibilityElement = true
cell.selectionStyle = .none
if let cell = cell as? SelectionListCell {
cell.selectionImage = selectionImage
Expand Down Expand Up @@ -244,6 +246,19 @@ class SelectionListCell: UITableViewCell {
super.prepareForReuse()
updateSelectionAppearance()
}

override var accessibilityTraits: UIAccessibilityTraits {
get {
if isSelected {
return super.accessibilityTraits | UIAccessibilityTraitSelected
}
return super.accessibilityTraits
}

set {
super.accessibilityTraits = newValue
}
}
}

// MARK: - Handy Extensions
Expand Down

0 comments on commit d8dd600

Please sign in to comment.