Browse Source

Fix tests and delete unused code in Onboarding screen.

pull/101/head
Abhishek Banthia 3 years ago
parent
commit
b7b163fe33
  1. 19
      Clocker/Clocker.xcodeproj/project.pbxproj
  2. 23
      Clocker/ClockerUITests/AboutUsTests.swift
  3. 2
      Clocker/ClockerUITests/CopyToClipboardTests.swift
  4. 10
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  5. 79
      Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift
  6. 72
      Clocker/Onboarding/FinalOnboardingViewController.swift
  7. 1
      Clocker/Panel/UI/TimezoneDataSource.swift
  8. 4
      Clocker/Panel/UI/Toasty.swift

19
Clocker/Clocker.xcodeproj/project.pbxproj

@ -15,7 +15,6 @@
3531F7C326936C8300DF0111 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3531F7C026936C6E00DF0111 /* GoogleService-Info.plist */; };
3531F7C426936C8300DF0111 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3531F7C026936C6E00DF0111 /* GoogleService-Info.plist */; };
3531F7C526936C8400DF0111 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3531F7C026936C6E00DF0111 /* GoogleService-Info.plist */; };
3531F7F52693882300DF0111 /* Keys.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3531F7F42693882300DF0111 /* Keys.plist */; };
3531F80626938D7700DF0111 /* GoogleUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3531F7FC26938D7600DF0111 /* GoogleUtilities.framework */; };
3531F80726938D7700DF0111 /* GoogleUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3531F7FC26938D7600DF0111 /* GoogleUtilities.framework */; };
3531F80826938D7700DF0111 /* GoogleUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3531F7FC26938D7600DF0111 /* GoogleUtilities.framework */; };
@ -54,7 +53,6 @@
35B2FEC0259A186F005DA84D /* StartupKit in Frameworks */ = {isa = PBXBuildFile; productRef = 35B2FEBF259A186F005DA84D /* StartupKit */; };
35B2FEDD259A2291005DA84D /* CoreLoggerKit in Frameworks */ = {isa = PBXBuildFile; productRef = 35B2FEDC259A2291005DA84D /* CoreLoggerKit */; };
35B2FEF1259A2DB1005DA84D /* CoreModelKit in Frameworks */ = {isa = PBXBuildFile; productRef = 35B2FEF0259A2DB1005DA84D /* CoreModelKit */; };
35C11E2124873A550031F18C /* VersionUpdateHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C11E2024873A550031F18C /* VersionUpdateHandler.swift */; };
35C36EF122595F14002FA5C6 /* OnboardingPermissionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36EE822595F13002FA5C6 /* OnboardingPermissionsViewController.swift */; };
35C36EF222595F14002FA5C6 /* OnboardingWelcomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36EE922595F13002FA5C6 /* OnboardingWelcomeViewController.swift */; };
35C36EF322595F14002FA5C6 /* WelcomeView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 35C36EEA22595F13002FA5C6 /* WelcomeView.xib */; };
@ -121,6 +119,8 @@
35C36FA22259ED6D002FA5C6 /* RemindersHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F9F2259ED6D002FA5C6 /* RemindersHandler.swift */; };
35C36FA42259EEC2002FA5C6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36FA32259EEC2002FA5C6 /* AppDelegate.swift */; };
35E65125268EDD2E00E3E1E3 /* Toasty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35E65124268EDD2E00E3E1E3 /* Toasty.swift */; };
9A0385BB269E3434003B5E72 /* StandardMenubarHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */; };
9A066A04269A2BF600C3F1FB /* Keys.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9A066A03269A2BF600C3F1FB /* Keys.plist */; };
9A0A1C8C20903DBD0012003B /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A9E87651C1FEDC500A7A2DF /* CoreLocation.framework */; };
9A13BAD61CA87F08007C6CBE /* Panel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9A13BAD81CA87F08007C6CBE /* Panel.xib */; };
9A13BAE01CA882FA007C6CBE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9A13BAE21CA882FA007C6CBE /* InfoPlist.strings */; };
@ -347,6 +347,8 @@
35C36F9F2259ED6D002FA5C6 /* RemindersHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemindersHandler.swift; sourceTree = "<group>"; };
35C36FA32259EEC2002FA5C6 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = SOURCE_ROOT; };
35E65124268EDD2E00E3E1E3 /* Toasty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toasty.swift; sourceTree = "<group>"; };
9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardMenubarHandlerTests.swift; sourceTree = "<group>"; };
9A066A03269A2BF600C3F1FB /* Keys.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Keys.plist; path = Internal/Keys.plist; sourceTree = "<group>"; };
9A13BAD71CA87F08007C6CBE /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/Panel.xib; sourceTree = "<group>"; };
9A13BAE11CA882FA007C6CBE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
9A13BAEB1CA88A76007C6CBE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
@ -854,6 +856,7 @@
children = (
C20839C921515C1E00C86589 /* ClockerUnitTests.swift */,
C20839CB21515C1F00C86589 /* Info.plist */,
9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */,
);
path = ClockerUnitTests;
sourceTree = "<group>";
@ -882,6 +885,7 @@
DD4F7BF913C30F9F00825C6E = {
isa = PBXGroup;
children = (
9A066A03269A2BF600C3F1FB /* Keys.plist */,
35B2FEE4259A2C25005DA84D /* CoreModelKit */,
35B2FED4259A2244005DA84D /* CoreLoggerKit */,
35B2FEB1259A1649005DA84D /* StartupKit */,
@ -1163,7 +1167,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3531F7F72693882300DF0111 /* Keys.plist in Resources */,
3531F7C526936C8400DF0111 /* GoogleService-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -1172,7 +1175,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9ABF454F268FCF10002C779B /* Keys.plist in Resources */,
9A8B256A232EFAD300204CAD /* Localizable.strings in Resources */,
9AA522C023415BDD00C9E005 /* InfoPlist.strings in Resources */,
3531F7C426936C8300DF0111 /* GoogleService-Info.plist in Resources */,
@ -1195,6 +1197,7 @@
3531F7C226936C6E00DF0111 /* GoogleService-Info.plist in Resources */,
35C36F17225961DA002FA5C6 /* DateTools.bundle in Resources */,
35C36EF322595F14002FA5C6 /* WelcomeView.xib in Resources */,
9A066A04269A2BF600C3F1FB /* Keys.plist in Resources */,
35C36EF822595F14002FA5C6 /* Onboarding.storyboard in Resources */,
35C36F612259DE67002FA5C6 /* NotesPopover.xib in Resources */,
9A3169C11D2CC5AA0079FDF8 /* com.abhishek.ClockerHelper.plist in Resources */,
@ -1238,6 +1241,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9A0385BB269E3434003B5E72 /* StandardMenubarHandlerTests.swift in Sources */,
C20839CA21515C1E00C86589 /* ClockerUnitTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -1338,7 +1342,6 @@
35C36F662259DF4C002FA5C6 /* UpcomingEventView.swift in Sources */,
35C36EF522595F14002FA5C6 /* OnboardingSearchController.swift in Sources */,
35C36F592259DD8A002FA5C6 /* TimezoneCellView.swift in Sources */,
35C11E2124873A550031F18C /* VersionUpdateHandler.swift in Sources */,
35C36F15225961DA002FA5C6 /* TimeChunk.swift in Sources */,
35C36F482259D892002FA5C6 /* NetworkManager.swift in Sources */,
9A8605AE1BEC148400A810A4 /* main.m in Sources */,
@ -1535,7 +1538,7 @@
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 96;
CURRENT_PROJECT_VERSION = 97;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
@ -2104,7 +2107,7 @@
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 96;
CURRENT_PROJECT_VERSION = 97;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
@ -2186,7 +2189,7 @@
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 96;
CURRENT_PROJECT_VERSION = 97;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;

23
Clocker/ClockerUITests/AboutUsTests.swift

@ -34,7 +34,7 @@ class AboutUsTests: XCTestCase {
tapAboutTab()
let appDisplayName = "CFBundleDisplayName".localizedString()
let expectedVersion = "\(appDisplayName) 21.07.02 (96)"
let expectedVersion = "\(appDisplayName) 21.07.03 (97)"
guard let presentVersion = app.windows["Clocker"].staticTexts["ClockerVersion"].value as? String else {
XCTFail("Present version not present")
@ -46,24 +46,9 @@ class AboutUsTests: XCTestCase {
app.checkBoxes["ClockerPrivateFeedback"].click()
app.buttons["Send Feedback"].click()
let expectedInformativeText = "Please enter some feedback."
XCTAssertTrue(app.staticTexts["InformativeText"].exists)
guard let infoText = app.staticTexts["InformativeText"].value as? String else {
XCTFail("InformativeText label was unexpectedly absent")
return
}
XCTAssertEqual(infoText, expectedInformativeText)
sleep(5)
guard let newInfoText = app.staticTexts["InformativeText"].value as? String else {
XCTFail("InformativeText label was unexpectedly absent")
return
}
XCTAssertTrue(newInfoText.isEmpty)
XCTAssertFalse(app.progressIndicators["ProgressIndicator"].exists)
sleep(2) // Wait for Toast to disappear
// Close window
app.windows["Clocker Feedback"].buttons["Cancel"].click()

2
Clocker/ClockerUITests/CopyToClipboardTests.swift

@ -44,7 +44,7 @@ class CopyToClipboardTests: XCTestCase {
let expectedValue = "\(customLabel) - \(time)"
// Tap to copy!
cell.tap()
cell.click()
let clipboard = NSPasteboard.general.string(forType: .string) ?? "Empty Pasteboard"
XCTAssert(expectedValue == clipboard, "Clipboard value (\(clipboard)) doesn't match expected result")

10
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -143,11 +143,11 @@ class ClockerUnitTests: XCTestCase {
// The below test might fail outside California or if DST is active!
// CI is calibrated to be on LA timezone!
func testTimeDifference() {
XCTAssertTrue(operations.timeDifference() == ", 10h 30m ahead", "Difference was unexpectedly: \(operations.timeDifference())")
XCTAssertTrue(californiaOperations.timeDifference() == ", 2h behind", "Difference was unexpectedly: \(californiaOperations.timeDifference())")
XCTAssertTrue(floridaOperations.timeDifference() == ", an hour ahead", "Difference was unexpectedly: \(floridaOperations.timeDifference())")
XCTAssertTrue(aucklandOperations.timeDifference() == ", 17h ahead", "Difference was unexpectedly: \(aucklandOperations.timeDifference())")
XCTAssertTrue(omahaOperations.timeDifference() == "", "Difference was unexpectedly: \(omahaOperations.timeDifference())")
XCTAssertTrue(operations.timeDifference() == ", 9h 30m ahead", "Difference was unexpectedly: \(operations.timeDifference())")
XCTAssertTrue(californiaOperations.timeDifference() == ", 3h behind", "Difference was unexpectedly: \(californiaOperations.timeDifference())")
XCTAssertTrue(floridaOperations.timeDifference() == "", "Difference was unexpectedly: \(floridaOperations.timeDifference())")
XCTAssertTrue(aucklandOperations.timeDifference() == ", 16h ahead", "Difference was unexpectedly: \(aucklandOperations.timeDifference())")
XCTAssertTrue(omahaOperations.timeDifference() == ", an hour behind", "Difference was unexpectedly: \(omahaOperations.timeDifference())")
}
func testSunriseSunset() {

79
Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift

@ -0,0 +1,79 @@
// Copyright © 2015 Abhishek Banthia
import XCTest
import CoreModelKit
@testable import Clocker
class StandardMenubarHandlerTests: XCTestCase {
private let mumbai = ["customLabel": "Ghar",
"formattedAddress": "Mumbai",
"place_id": "ChIJwe1EZjDG5zsRaYxkjY_tpF0",
"timezoneID": "Asia/Calcutta",
"nextUpdate": "",
"latitude": "19.0759837",
"longitude": "72.8776559"]
func testValidStandardMenubarHandler_returnMenubarTitle() {
// Wipe all timezones from UserDefaults
UserDefaults.standard.setValue(nil, forKey: CLDefaultPreferenceKey)
// Save a menubar selected timezone
let dataObject = TimezoneData(with: mumbai)
dataObject.isFavourite = 1
let operationsObject = TimezoneDataOperations(with: dataObject)
operationsObject.saveObject()
let menubarTimezones = DataStore.shared().menubarTimezones()
XCTAssertTrue(menubarTimezones?.count == 1)
// Set standard menubar in Prefs
UserDefaults.standard.set(1, forKey: CLMenubarCompactMode)
let menubarHandler = MenubarHandler()
let menubarString = menubarHandler.titleForMenubar() ?? ""
// Test menubar string is present
XCTAssertTrue(menubarString.count > 0)
XCTAssertTrue(menubarString.contains("Ghar"))
// Set default back to compact menubar
UserDefaults.standard.set(0, forKey: CLMenubarCompactMode)
}
func testUnfavouritedTimezone_returnEmptyMenubarTimezoneCount() {
// Wipe all timezones from UserDefaults
UserDefaults.standard.setValue(nil, forKey: CLDefaultPreferenceKey)
// Save a menubar selected timezone
let dataObject = TimezoneData(with: mumbai)
dataObject.isFavourite = 0
let operationsObject = TimezoneDataOperations(with: dataObject)
operationsObject.saveObject()
let menubarTimezones = DataStore.shared().menubarTimezones()
XCTAssertTrue(menubarTimezones?.count == 0)
}
func testUnfavouritedTimezone_returnNilMenubarString() {
// Wipe all timezones from UserDefaults
UserDefaults.standard.setValue(nil, forKey: CLDefaultPreferenceKey)
let menubarHandler = MenubarHandler()
let emptyMenubarString = menubarHandler.titleForMenubar()
// Returns early because DataStore.menubarTimezones is nil
XCTAssertNil(emptyMenubarString)
// Save a menubar selected timezone
let dataObject = TimezoneData(with: mumbai)
dataObject.isFavourite = 0
let operationsObject = TimezoneDataOperations(with: dataObject)
operationsObject.saveObject()
let menubarString = menubarHandler.titleForMenubar() ?? ""
// Test menubar string is absent
XCTAssertTrue(menubarString.count == 0)
}
}

72
Clocker/Onboarding/FinalOnboardingViewController.swift

@ -19,24 +19,6 @@ class FinalOnboardingViewController: NSViewController {
@IBOutlet var emailTextField: NSTextField!
@IBOutlet var localizationButton: UnderlinedButton!
private let emailValidator = EmailTextFieldValidator()
private var serialNumber: String? {
let platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"))
guard platformExpert > 0 else {
return nil
}
guard let serialNumber = (IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformSerialNumberKey as CFString, kCFAllocatorDefault, 0).takeUnretainedValue() as? String) else {
return nil
}
IOObjectRelease(platformExpert)
return serialNumber
}
override func viewDidLoad() {
super.viewDidLoad()
titleLabel.stringValue = "You're all set!".localized()
@ -87,58 +69,4 @@ class FinalOnboardingViewController: NSViewController {
super.viewWillAppear()
emailTextField.becomeFirstResponder()
}
private func todaysDate() -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .short
dateFormatter.timeZone = TimeZone(identifier: AppFeedbackConstants.CLCaliforniaTimezoneIdentifier)
return dateFormatter.string(from: Date())
}
private func extraData() -> [String: String]? {
guard let validEmail = emailValidator.validate(field: emailTextField) else {
Logger.info("Not sending up email because it was invalid")
return nil
}
guard let shortVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String,
let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String
else {
return nil
}
let operatingSystem = ProcessInfo.processInfo.operatingSystemVersion
let osVersion = "\(operatingSystem.majorVersion).\(operatingSystem.minorVersion).\(operatingSystem.patchVersion)"
let versionInfo = "Clocker \(shortVersion) (\(appVersion))"
return [
EmailSignupConstants.CLEmailSignupEmailProperty: validEmail,
EmailSignupConstants.CLOperatingSystemVersion: osVersion,
EmailSignupConstants.CLClockerVersion: versionInfo,
EmailSignupConstants.CLAppFeedbackDateProperty: todaysDate(),
EmailSignupConstants.CLAppLanguageKey: Locale.preferredLanguages.first ?? "en-US",
]
}
}
class EmailTextFieldValidator {
func validate(field: NSTextField) -> String? {
let trimmedText = field.stringValue.trimmingCharacters(in: .whitespacesAndNewlines)
guard let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) else {
return nil
}
let range = NSMakeRange(0, NSString(string: trimmedText).length)
let allMatches = dataDetector.matches(in: trimmedText,
options: [],
range: range)
if allMatches.count == 1,
allMatches.first?.url?.absoluteString.contains("mailto:") == true
{
return trimmedText
}
return nil
}
}

1
Clocker/Panel/UI/TimezoneDataSource.swift

@ -74,7 +74,6 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate {
cellView.noteLabel.stringValue = CLEmptyString
}
cellView.layout(with: currentModel)
cellView.setAccessibilityIdentifier(currentModel.formattedTimezoneLabel())
cellView.setAccessibilityLabel(currentModel.formattedTimezoneLabel())

4
Clocker/Panel/UI/Toasty.swift

@ -118,6 +118,7 @@ class ToastView: NSView {
let rect = CGRect(origin: .zero, size: size)
super.init(frame: rect)
wantsLayer = true
setAccessibility("ToastView")
}
@available(*, unavailable)
@ -127,6 +128,7 @@ class ToastView: NSView {
super.viewDidMoveToSuperview()
if superview != nil {
configure()
setAccessibility("ToastView")
}
}
@ -166,6 +168,8 @@ class ToastView: NSView {
public extension NSView {
func makeToast(_ message: String) {
let toast = ToastView(message: message)
toast.setAccessibilityEnabled(true)
toast.setAccessibilityRole(.sheet)
addSubview(toast)
hideAnimation(view: toast, style: DefaultStyle.shared)
}

Loading…
Cancel
Save