Skip to content

Commit

Permalink
[XCUITests] Table View Cell tests (#1508)
Browse files Browse the repository at this point in the history
* add table view cell tests

* move single line asserts to function

* add comment
  • Loading branch information
joannaquu committed Jan 24, 2023
1 parent 8872ab6 commit 1339ed0
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
85 changes: 85 additions & 0 deletions ios/FluentUI.Demo/FluentUIDemoTests/TableViewCellTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,93 @@ import XCTest
class TableViewCellTest: BaseTest {
override var controlName: String { "TableViewCell" }

let title: String = "\"Contoso Survey\""
let subtitle: String = "\"Research Notes\""
let footer: String = "\"22 views\""
let customTitle: String = "\"Format\""
let longTitle: String = "\"This is a cell with a long text1 as an example of how this label will render\""
let longSubtitle: String = "\"This is a cell with a long text2 as an example of how this label will render\""
let longFooter: String = "\"This is a cell with a long text3 as an example of how this label will render\""

func assertSingleLine() throws {
XCTAssertEqual(app.cells.element(boundBy: 0).identifier, "Table View Cell with title \(title), with a leading image")
XCTAssertEqual(app.cells.element(boundBy: 1).identifier, "Table View Cell with title \(title), with a leading image and a chevron")
XCTAssertEqual(app.cells.element(boundBy: 2).identifier, "Table View Cell with title \(title), with a leading image and a details button")
XCTAssertEqual(app.cells.element(boundBy: 3).identifier, "Table View Cell with title \(title), with a leading image and a checkmark")
XCTAssertEqual(app.cells.element(boundBy: 4).identifier, "Table View Cell with title \(title), with a leading image and a title leading image")
}

// launch test that ensures the demo app does not crash and is on the correct control page
func testLaunch() throws {
XCTAssertTrue(app.navigationBars[controlName].exists)
}

func testSingleLine() throws {
try assertSingleLine()
}

func testDoubleLine() throws {
XCTAssertEqual(app.cells.element(boundBy: 5).identifier, "Table View Cell with title \(title) and subtitle \(subtitle), with a leading unread dot and a leading image")
XCTAssertEqual(app.cells.element(boundBy: 6).identifier, "Table View Cell with title \(title) and subtitle \(subtitle), with a leading unread dot, a leading image, and a chevron")
XCTAssertEqual(app.cells.element(boundBy: 7).identifier, "Table View Cell with title \(title) and subtitle \(subtitle), with a leading unread dot, a leading image, and a details button")
XCTAssertEqual(app.cells.element(boundBy: 8).identifier, "Table View Cell with title \(title) and subtitle \(subtitle), with a leading unread dot, a leading image, and a checkmark")
XCTAssertEqual(app.cells.element(boundBy: 9).identifier, "Table View Cell with title \(title) and subtitle \(subtitle), with a leading unread dot, a leading image, and a subtitle leading image")
}

func testInvertedDoubleLine() throws {
XCTAssertEqual(app.cells.element(boundBy: 10).identifier, "Table View Cell with title \(title) and subtitle \(subtitle)")
XCTAssertEqual(app.cells.element(boundBy: 11).identifier, "Table View Cell with title \(title) and subtitle \(subtitle), with a chevron")
XCTAssertEqual(app.cells.element(boundBy: 12).identifier, "Table View Cell with title \(title) and subtitle \(subtitle), with a details button")
XCTAssertEqual(app.cells.element(boundBy: 13).identifier, "Table View Cell with title \(title) and subtitle \(subtitle), with a checkmark")
XCTAssertEqual(app.cells.element(boundBy: 14).identifier, "Table View Cell with title \(title) and subtitle \(subtitle), with a subtitle leading image")
}

func testTripleLine() throws {
XCTAssertEqual(app.cells.element(boundBy: 15).identifier, "Table View Cell with title \(title), subtitle \(subtitle), and footer \(footer), with a leading image")
XCTAssertEqual(app.cells.element(boundBy: 16).identifier, "Table View Cell with title \(title), subtitle \(subtitle), and footer \(footer), with a leading image and a chevron")
XCTAssertEqual(app.cells.element(boundBy: 17).identifier, "Table View Cell with title \(title), subtitle \(subtitle), and footer \(footer), with a leading image and a details button")
XCTAssertEqual(app.cells.element(boundBy: 18).identifier, "Table View Cell with title \(title), subtitle \(subtitle), and footer \(footer), with a leading image and a checkmark")
XCTAssertEqual(app.cells.element(boundBy: 19).identifier, "Table View Cell with title \(title), subtitle \(subtitle), and footer, with a leading image, a subtitle trailing image, and a footer trailing image")
}

func testCustomView() throws {
XCTAssertEqual(app.cells.element(boundBy: 25).identifier, "Table View Cell with title \(customTitle)")
XCTAssertEqual(app.cells.element(boundBy: 26).identifier, "Table View Cell with title \(customTitle), with a chevron")
XCTAssertEqual(app.cells.element(boundBy: 27).identifier, "Table View Cell with title \(customTitle), with a details button")
XCTAssertEqual(app.cells.element(boundBy: 28).identifier, "Table View Cell with title \(customTitle), with a checkmark")
XCTAssertEqual(app.cells.element(boundBy: 29).identifier, "Table View Cell with title \(customTitle)")
}

func testLongLabels() throws {
XCTAssertEqual(app.cells.element(boundBy: 30).identifier, "Table View Cell with title \(longTitle), subtitle \(longSubtitle), and footer \(longFooter), with a leading image")
XCTAssertEqual(app.cells.element(boundBy: 31).identifier, "Table View Cell with title \(longTitle), subtitle \(longSubtitle), and footer \(longFooter), with a leading image and a chevron")
XCTAssertEqual(app.cells.element(boundBy: 32).identifier, "Table View Cell with title \(longTitle), subtitle \(longSubtitle), and footer \(longFooter), with a leading image and a details button")
XCTAssertEqual(app.cells.element(boundBy: 33).identifier, "Table View Cell with title \(longTitle), subtitle \(longSubtitle), and footer \(longFooter), with a leading image and a checkmark")
XCTAssertEqual(app.cells.element(boundBy: 34).identifier, "Table View Cell with title \(longTitle), subtitle \(longSubtitle), and footer \(longFooter), with a leading image, a title trailing image, a subtitle trailing image, and a footer trailing image")
}

// ensures that selection/deselection adds/removes unread dot
func testSelection() throws {
try assertSingleLine()

app.buttons["Select"].tap()
for i in 0...4 {
app.images.element(boundBy: i).tap()
}
app.buttons["Done"].tap()

XCTAssertEqual(app.cells.element(boundBy: 0).identifier, "Table View Cell with title \(title), with a leading unread dot and a leading image")
XCTAssertEqual(app.cells.element(boundBy: 1).identifier, "Table View Cell with title \(title), with a leading unread dot, a leading image, and a chevron")
XCTAssertEqual(app.cells.element(boundBy: 2).identifier, "Table View Cell with title \(title), with a leading unread dot, a leading image, and a details button")
XCTAssertEqual(app.cells.element(boundBy: 3).identifier, "Table View Cell with title \(title), with a leading unread dot, a leading image, and a checkmark")
XCTAssertEqual(app.cells.element(boundBy: 4).identifier, "Table View Cell with title \(title), with a leading unread dot, a leading image, and a title leading image")

app.buttons["Select"].tap()
for i in 0...4 {
app.images.element(boundBy: i).tap()
}
app.buttons["Done"].tap()

try assertSingleLine()
}
}
81 changes: 81 additions & 0 deletions ios/FluentUI/Table View/TableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,87 @@ open class TableViewCell: UITableViewCell, TokenizedControlInternal {
set { super.accessibilityValue = newValue }
}

#if DEBUG
open override var accessibilityIdentifier: String? {
get {
var identifier: String = "Table View Cell with"

switch layoutType {
case .oneLine:
identifier += " title \"\(title)\""
case .twoLines:
identifier += " title \"\(title)\" and subtitle \"\(subtitle)\""
case .threeLines:
identifier += " title \"\(title)\", subtitle \"\(subtitle)\", and footer"
if footer != "" {
identifier += " \"\(footer)\""
}
}

var accessoryViews: [String] = []

if isUnreadDotVisible {
accessoryViews.append("leading unread dot")
}

if customView != nil {
accessoryViews.append("leading image")
}

if titleLeadingAccessoryView != nil {
accessoryViews.append("title leading image")
}

if subtitleLeadingAccessoryView != nil {
accessoryViews.append("subtitle leading image")
}

if footerLeadingAccessoryView != nil {
accessoryViews.append("footer leading image")
}

switch _accessoryType {
case .none:
break
case .disclosureIndicator:
accessoryViews.append("chevron")
case .detailButton:
accessoryViews.append("details button")
case .checkmark:
accessoryViews.append("checkmark")
}

if titleTrailingAccessoryView != nil {
accessoryViews.append("title trailing image")
}

if subtitleTrailingAccessoryView != nil {
accessoryViews.append("subtitle trailing image")
}

if footerTrailingAccessoryView != nil {
accessoryViews.append("footer trailing image")
}

if accessoryViews.count > 0 {
identifier += ", with a \(accessoryViews[0])"
}

if accessoryViews.count == 2 {
identifier += " and a \(accessoryViews[1])"
} else if accessoryViews.count > 2 {
for i in 1...accessoryViews.count - 2 {
identifier += ", a \(accessoryViews[i])"
}
identifier += ", and a \(accessoryViews[accessoryViews.count - 1])"
}

return identifier
}
set { }
}
#endif

open override var accessibilityActivationPoint: CGPoint {
get {
if let customAccessoryView = customAccessoryView as? UISwitch {
Expand Down

0 comments on commit 1339ed0

Please sign in to comment.