Skip to content

Commit

Permalink
Compare excluding whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullah-original committed Jul 15, 2024
1 parent d9ca758 commit 0fa3fb8
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions Tests/ExtendedDatePickerFormatterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ final class ExtendedDatePickerFormatterTests: XCTestCase {

private var sut: ExtendedDatePickerFormatter!
private var calendar: Calendar = .current

func testHourMode_shouldOnlyDisplayHour() {
// Arrange
// Arrange
self.calendar.locale = .init(identifier: "en-GB")
self.sut = .init(calendar: calendar)

let hour = calendar.date(
from: .init(
year: 2024,
Expand All @@ -20,18 +20,18 @@ final class ExtendedDatePickerFormatterTests: XCTestCase {
)
)!

// Act
// Act
let result = sut.format(from: hour, mode: .hour)

// Assert
// Assert
XCTAssertEqual(result, "17:00")
}

func testDateMode_shouldOnlyDisplayDate() {
// Arrange
self.calendar.locale = .init(identifier: "en-US")
self.sut = .init(calendar: calendar)

let hour = calendar.date(
from: .init(
year: 2024,
Expand All @@ -48,12 +48,12 @@ final class ExtendedDatePickerFormatterTests: XCTestCase {
// Assert
XCTAssertEqual(result, "July 15, 2024")
}

func testDateTimeMode_shouldDisplayBothDateAndTime() {
// Arrange
self.calendar.locale = .init(identifier: "en-US")
self.sut = .init(calendar: calendar)

let hour = calendar.date(
from: .init(
year: 2024,
Expand All @@ -65,12 +65,15 @@ final class ExtendedDatePickerFormatterTests: XCTestCase {
)!

// Act
let result = sut.format(from: hour, mode: .dateTime)
let result = sut.format(from: hour, mode: .dateTime).filter { $0.isWhitespace }

// Assert
XCTAssertEqual(result, "July 15, 2024 at 5:37 PM")
XCTAssertEqual(
result,
"July 15, 2024 at 5:37 PM".filter { $0.isWhitespace }
)
}

func testDateTimeMode_givenENGBLocale_shouldDisplayBothDateAndTime() {
// Arrange
self.calendar.locale = .init(identifier: "en-GB")
Expand Down Expand Up @@ -109,14 +112,15 @@ final class ExtendedDatePickerFormatterTests: XCTestCase {
)!

// Act
let result = sut.format(from: hour, mode: .week)
let result = sut.format(from: hour, mode: .week).filter { $0.isWhitespace }

// Assert
XCTAssertEqual(result, "15 – 21 Jul 2024")
XCTAssertEqual(
result,
"15 – 21 Jul 2024".filter { $0.isWhitespace }
)
}



func testMonthYearMode_shouldNotDisplayDay() {
// Arrange
self.calendar.locale = .init(identifier: "en-US")
Expand All @@ -138,7 +142,7 @@ final class ExtendedDatePickerFormatterTests: XCTestCase {
// Assert
XCTAssertEqual(result, "July 2024")
}

func testYearMode_shouldNotDisplayMonth() {
// Arrange
self.calendar.locale = .init(identifier: "en-US")
Expand All @@ -160,6 +164,5 @@ final class ExtendedDatePickerFormatterTests: XCTestCase {
// Assert
XCTAssertEqual(result, "2024")
}


}

0 comments on commit 0fa3fb8

Please sign in to comment.