From 7099e4221bf03e3122d234dfe67ca3ddd39ea35f Mon Sep 17 00:00:00 2001 From: Gemma Barlow Date: Sun, 16 Apr 2017 15:19:52 -0400 Subject: [PATCH 1/6] Test cleanup - Added `swipeUpUntilElementIsVisible` method, so as to prevent test failure on the iPhone 6S Simulator (previously was not swiping to reveal appropriate tappable elements) - Split giant test into four smaller tests, for better issue detection --- .../FSCalendarSwiftExampleUITests.swift | 67 +++++++++++-------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift b/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift index e0eea49d..a1046b73 100644 --- a/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift +++ b/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift @@ -9,33 +9,24 @@ import XCTest class FSCalendarSwiftExampleUITests: XCTestCase { - + + // MARK: - Setup / Tear Down + override func setUp() { super.setUp() - - // Put setup code here. This method is called before the invocation of each test method in the class. - - // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false - // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. XCUIApplication().launch() - - // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. } override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() } - - func testExample() { - self.doTestDIY() - self.doTestScope() - self.doTestDelegateAppearance() - self.doTestInterfaceBuilder() - } - - func doTestDIY() { + + + // MARK: - Tests + + func testDIY() { let application = XCUIApplication() application.tables.element(boundBy: 0).staticTexts["DIY"].tap() let calendar: XCUIElement = application.otherElements["calendar"] @@ -53,7 +44,7 @@ class FSCalendarSwiftExampleUITests: XCTestCase { application.buttons.element(boundBy: 0).tap() } - func doTestDelegateAppearance() { + func testDelegateAppearance() { let application = XCUIApplication() application.tables.element(boundBy: 0).staticTexts["Delegate Appearance"].tap() @@ -88,7 +79,7 @@ class FSCalendarSwiftExampleUITests: XCTestCase { application.buttons.element(boundBy: 0).tap() } - func doTestScope() { + func testScope() { let application = XCUIApplication() application.tables.element(boundBy: 0).staticTexts["FSCalendarScope"].tap() let tableView: XCUIElement = application.tables.element(boundBy: 0) @@ -114,8 +105,7 @@ class FSCalendarSwiftExampleUITests: XCTestCase { application.buttons.element(boundBy: 0).tap() } - func doTestInterfaceBuilder() { - + func testInterfaceBuilder() { let application = XCUIApplication() application.tables.element(boundBy: 0).staticTexts["Interface Builder"].tap() let calendar = application.otherElements["calendar"] @@ -177,22 +167,29 @@ class FSCalendarSwiftExampleUITests: XCTestCase { Thread.sleep(forTimeInterval: 0.5) configButton.tap() - application.tables.element(boundBy: 0).swipeUp() - application.tables.staticTexts["Monday"].tap() + let table = application.tables.element(boundBy: 0) + let monday = application.tables.staticTexts["Monday"] + swipeUpUntilElementIsVisible(table: table, element: monday) + monday.tap() + calendar.swipeUp() calendar.swipeDown() Thread.sleep(forTimeInterval: 0.5) configButton.tap() - application.tables.element(boundBy: 0).swipeUp() - application.tables.staticTexts["Tuesday"].tap() + let tuesday = application.tables.staticTexts["Tuesday"] + swipeUpUntilElementIsVisible(table: table, element: tuesday) + tuesday.tap() + calendar.swipeUp() calendar.swipeDown() Thread.sleep(forTimeInterval: 0.5) configButton.tap() - application.tables.element(boundBy: 0).swipeUp() - application.tables.staticTexts["Sunday"].tap() + let sunday = application.tables.staticTexts["Sunday"] + swipeUpUntilElementIsVisible(table: table, element: sunday) + sunday.tap() + calendar.swipeUp() calendar.swipeDown() Thread.sleep(forTimeInterval: 1.5) @@ -209,6 +206,18 @@ class FSCalendarSwiftExampleUITests: XCTestCase { // Exit Thread.sleep(forTimeInterval: 1.0) application.buttons.element(boundBy: 0).tap() - } + + + // MARK: - Helper Methods + + private let maxSwipes = 5 + + private func swipeUpUntilElementIsVisible(table: XCUIElement, element: XCUIElement) { + var swipes = 0 + while !element.exists && swipes < maxSwipes { + table.swipeUp() + swipes += 1 + } + } } From 2df76bce6ee0bd3ae3c8a693cbc6a01393bd215e Mon Sep 17 00:00:00 2001 From: Gemma Barlow Date: Sun, 16 Apr 2017 15:26:54 -0400 Subject: [PATCH 2/6] Adjust formatting, to match style of repository. --- .../FSCalendarSwiftExampleUITests.swift | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift b/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift index a1046b73..dc5ae7ee 100644 --- a/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift +++ b/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift @@ -9,12 +9,12 @@ import XCTest class FSCalendarSwiftExampleUITests: XCTestCase { - - // MARK: - Setup / Tear Down - + + // MARK: - Setup / Tear Down + override func setUp() { super.setUp() - + continueAfterFailure = false XCUIApplication().launch() } @@ -22,10 +22,10 @@ class FSCalendarSwiftExampleUITests: XCTestCase { override func tearDown() { super.tearDown() } - - - // MARK: - Tests - + + + // MARK: - Tests + func testDIY() { let application = XCUIApplication() application.tables.element(boundBy: 0).staticTexts["DIY"].tap() @@ -65,7 +65,7 @@ class FSCalendarSwiftExampleUITests: XCTestCase { CGVector(dx:4.5*columnWidth, dy:cellStart+rowHeight*3.5), CGVector(dx:0.5*columnWidth, dy:cellStart+rowHeight*4.5), CGVector(dx:5.5*columnWidth, dy:cellStart+rowHeight*5.5), - ] + ] vectors.forEach { (vector) in calendar.coordinate(withNormalizedOffset: vector).tap() } @@ -104,7 +104,7 @@ class FSCalendarSwiftExampleUITests: XCTestCase { Thread.sleep(forTimeInterval: 1.5) application.buttons.element(boundBy: 0).tap() } - + func testInterfaceBuilder() { let application = XCUIApplication() application.tables.element(boundBy: 0).staticTexts["Interface Builder"].tap() @@ -113,7 +113,7 @@ class FSCalendarSwiftExampleUITests: XCTestCase { let cellStart: CGFloat = (FSCalendarStandardHeaderHeight+FSCalendarStandardWeekdayHeight)/calendarHeight let rowHeight: CGFloat = (1.0-cellStart)/6.0 let columnWidth: CGFloat = 1.0/7 - + let nextVector = CGVector(dx: columnWidth.multiplied(by: 5.5), dy: cellStart+rowHeight.multiplied(by: 5.5)) let prevVector = CGVector(dx: columnWidth.multiplied(by: 1.5), dy: cellStart+rowHeight.multiplied(by: 0.5)) calendar.coordinate(withNormalizedOffset: nextVector).tap() @@ -167,29 +167,29 @@ class FSCalendarSwiftExampleUITests: XCTestCase { Thread.sleep(forTimeInterval: 0.5) configButton.tap() - let table = application.tables.element(boundBy: 0) - let monday = application.tables.staticTexts["Monday"] - swipeUpUntilElementIsVisible(table: table, element: monday) - monday.tap() - + let table = application.tables.element(boundBy: 0) + let monday = application.tables.staticTexts["Monday"] + swipeUpUntilElementIsVisible(table: table, element: monday) + monday.tap() + calendar.swipeUp() calendar.swipeDown() Thread.sleep(forTimeInterval: 0.5) configButton.tap() - let tuesday = application.tables.staticTexts["Tuesday"] + let tuesday = application.tables.staticTexts["Tuesday"] swipeUpUntilElementIsVisible(table: table, element: tuesday) tuesday.tap() - + calendar.swipeUp() calendar.swipeDown() Thread.sleep(forTimeInterval: 0.5) configButton.tap() - let sunday = application.tables.staticTexts["Sunday"] - swipeUpUntilElementIsVisible(table: table, element: sunday) - sunday.tap() - + let sunday = application.tables.staticTexts["Sunday"] + swipeUpUntilElementIsVisible(table: table, element: sunday) + sunday.tap() + calendar.swipeUp() calendar.swipeDown() Thread.sleep(forTimeInterval: 1.5) @@ -207,17 +207,17 @@ class FSCalendarSwiftExampleUITests: XCTestCase { Thread.sleep(forTimeInterval: 1.0) application.buttons.element(boundBy: 0).tap() } - - - // MARK: - Helper Methods - - private let maxSwipes = 5 - - private func swipeUpUntilElementIsVisible(table: XCUIElement, element: XCUIElement) { - var swipes = 0 - while !element.exists && swipes < maxSwipes { - table.swipeUp() - swipes += 1 - } - } + + + // MARK: - Helper Methods + + private let maxSwipes = 5 + + private func swipeUpUntilElementIsVisible(table: XCUIElement, element: XCUIElement) { + var swipes = 0 + while !element.exists && swipes < maxSwipes { + table.swipeUp() + swipes += 1 + } + } } From 9bb3ca1ff0fd1a4e837accccee597c79766874e7 Mon Sep 17 00:00:00 2001 From: Gemma Barlow Date: Mon, 17 Apr 2017 12:30:36 -0400 Subject: [PATCH 3/6] Correct analyzer warning --- FSCalendar/FSCalendarWeekdayView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FSCalendar/FSCalendarWeekdayView.m b/FSCalendar/FSCalendarWeekdayView.m index 388c6fb5..e475b30c 100644 --- a/FSCalendar/FSCalendarWeekdayView.m +++ b/FSCalendar/FSCalendarWeekdayView.m @@ -63,14 +63,14 @@ - (void)layoutSubviews self.contentView.frame = self.bounds; // Position Calculation - NSInteger count = self.weekdayPointers.count; + NSInteger count = self.weekdayPointers.allObjects.count; size_t size = sizeof(CGFloat)*count; CGFloat *widths = malloc(size); CGFloat contentWidth = self.contentView.fs_width; FSCalendarSliceCake(contentWidth, count, widths); __block CGFloat x = 0; - for (NSInteger i = 0; i < self.weekdayPointers.count; i++) { + for (NSInteger i = 0; i < count; i++) { CGFloat width = widths[i]; UILabel *label = [self.weekdayPointers pointerAtIndex:i]; label.frame = CGRectMake(x, 0, width, self.contentView.fs_height); From 6413e6d6a7d67f17cd89e5fe8242d404e0f28770 Mon Sep 17 00:00:00 2001 From: Gemma Barlow Date: Mon, 17 Apr 2017 19:56:10 -0400 Subject: [PATCH 4/6] Revert change that was not required --- FSCalendar/FSCalendarWeekdayView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FSCalendar/FSCalendarWeekdayView.m b/FSCalendar/FSCalendarWeekdayView.m index e475b30c..ef14e3ee 100644 --- a/FSCalendar/FSCalendarWeekdayView.m +++ b/FSCalendar/FSCalendarWeekdayView.m @@ -63,7 +63,7 @@ - (void)layoutSubviews self.contentView.frame = self.bounds; // Position Calculation - NSInteger count = self.weekdayPointers.allObjects.count; + NSInteger count = self.weekdayPointers.count; size_t size = sizeof(CGFloat)*count; CGFloat *widths = malloc(size); CGFloat contentWidth = self.contentView.fs_width; From f8c2997057274b710e12723386366f31e1e1baef Mon Sep 17 00:00:00 2001 From: WenchaoD Date: Tue, 18 Apr 2017 08:10:44 +0800 Subject: [PATCH 5/6] Remove unused block identifier --- FSCalendar/FSCalendarWeekdayView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FSCalendar/FSCalendarWeekdayView.m b/FSCalendar/FSCalendarWeekdayView.m index ef14e3ee..09293205 100644 --- a/FSCalendar/FSCalendarWeekdayView.m +++ b/FSCalendar/FSCalendarWeekdayView.m @@ -69,7 +69,7 @@ - (void)layoutSubviews CGFloat contentWidth = self.contentView.fs_width; FSCalendarSliceCake(contentWidth, count, widths); - __block CGFloat x = 0; + CGFloat x = 0; for (NSInteger i = 0; i < count; i++) { CGFloat width = widths[i]; UILabel *label = [self.weekdayPointers pointerAtIndex:i]; From d56ec5ba7e5c0222fbf8350202223abe37cc3440 Mon Sep 17 00:00:00 2001 From: ITACHI <2307735634@qq.com> Date: Tue, 18 Apr 2017 15:17:30 +0800 Subject: [PATCH 6/6] fix fix the bug that weekdayView not configure correctly when set calendar.firstWeekday --- FSCalendar/FSCalendarWeekdayView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FSCalendar/FSCalendarWeekdayView.m b/FSCalendar/FSCalendarWeekdayView.m index 09293205..518ea30a 100644 --- a/FSCalendar/FSCalendarWeekdayView.m +++ b/FSCalendar/FSCalendarWeekdayView.m @@ -100,7 +100,7 @@ - (void)configureAppearance for (NSInteger i = 0; i < self.weekdayPointers.count; i++) { NSInteger index = (i + self.calendar.firstWeekday-1) % 7; - UILabel *label = [self.weekdayPointers pointerAtIndex:index]; + UILabel *label = [self.weekdayPointers pointerAtIndex:i]; label.font = self.calendar.appearance.weekdayFont; label.textColor = self.calendar.appearance.weekdayTextColor; label.text = useDefaultWeekdayCase ? weekdaySymbols[index] : [weekdaySymbols[index] uppercaseString];