Skip to content

Commit

Permalink
tests(addTags): updating add tags test
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Apr 6, 2023
1 parent ccb1cdb commit 60594ca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 37 deletions.
56 changes: 20 additions & 36 deletions Tests iOS/AddTagsItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,8 @@ class AddTagsItemTests: XCTestCase {

server = Application()

server.routes.post("/graphql") { request, _ in
let apiRequest = ClientAPIRequest(request)

if apiRequest.isForSlateLineup {
return Response.slateLineup()
} else if apiRequest.isForSavesContent {
return Response.saves()
} else if apiRequest.isForArchivedContent {
return Response.archivedContent()
} else if apiRequest.isForRecommendationDetail(1) {
return Response.recommendationDetail(1)
} else if apiRequest.isForTags {
return Response.emptyTags()
} else {
return Response.fallbackResponses(apiRequest: apiRequest)
}
server.routes.post("/graphql") { request, _ -> Response in
return .fallbackResponses(apiRequest: ClientAPIRequest(request))
}

try server.start()
Expand All @@ -58,9 +44,6 @@ class AddTagsItemTests: XCTestCase {
let addTagsView = app.addTagsView.wait()
addTagsView.clearTagsTextfield()
let randomTagName = String(addTagsView.enterRandomTagName())
server.routes.post("/graphql") { request, _ in
Response.savedItemWithTag()
}
addTagsView.saveButton.tap()
selectTaggedFilterButton()
app.saves.tagsFilterView.wait()
Expand Down Expand Up @@ -89,14 +72,16 @@ class AddTagsItemTests: XCTestCase {
waitForDisappearance(of: addTagsView.allTagsRow(matching: "tag 1"))

await snowplowMicro.assertBaselineSnowplowExpectation()
let removeTagEvent = await snowplowMicro.getFirstEvent(with: "global-nav.addTags.removeInputTag")
removeTagEvent!.getUIContext()!.assertHas(type: "button")
removeTagEvent!.getContentContext()!.assertHas(url: "http://localhost:8080/hello")

await snowplowMicro.assertBaselineSnowplowExpectation()
let addTagEvent = await snowplowMicro.getFirstEvent(with: "global-nav.addTags.addTag")
addTagEvent!.getUIContext()!.assertHas(type: "button")
addTagEvent!.getContentContext()!.assertHas(url: "http://localhost:8080/hello")
let events = await [snowplowMicro.getFirstEvent(with: "global-nav.addTags.removeInputTag"), snowplowMicro.getFirstEvent(with: "global-nav.addTags.addTag")]

let removeTagEvent = events[0]!
removeTagEvent.getUIContext()!.assertHas(type: "button")
removeTagEvent.getContentContext()!.assertHas(url: "http://localhost:8080/hello")

let addTagEvent = events[1]!
addTagEvent.getUIContext()!.assertHas(type: "button")
addTagEvent.getContentContext()!.assertHas(url: "http://localhost:8080/hello")
}

@MainActor
Expand All @@ -121,24 +106,23 @@ class AddTagsItemTests: XCTestCase {

addTagsView.tag(matching: "tag 1").wait()

server.routes.post("/graphql") { request, _ in
Response.savedItemWithTag()
}

addTagsView.saveButton.tap()

itemCell.itemActionButton.wait().tap()
app.addTagsButton.wait().tap()
app.addTagsView.wait()

await snowplowMicro.assertBaselineSnowplowExpectation()
let tagEvent = await snowplowMicro.getFirstEvent(with: "global-nav.addTags.allTags")
tagEvent!.getUIContext()!.assertHas(type: "screen")
tagEvent!.getContentContext()!.assertHas(url: "https://example.com/items/archived-item-2")

let tagEvent2 = await snowplowMicro.getFirstEvent(with: "global-nav.addTags.userEntersText")
tagEvent2!.getUIContext()!.assertHas(type: "dialog")
tagEvent2!.getContentContext()!.assertHas(url: "https://example.com/items/archived-item-2")
let events = await [snowplowMicro.getFirstEvent(with: "global-nav.addTags.allTags"), snowplowMicro.getFirstEvent(with: "global-nav.addTags.userEntersText")]

let tagEvent = events[0]!
tagEvent.getUIContext()!.assertHas(type: "screen")
tagEvent.getContentContext()!.assertHas(url: "https://example.com/items/archived-item-2")

let tagEvent2 = events[1]!
tagEvent2.getUIContext()!.assertHas(type: "dialog")
tagEvent2.getContentContext()!.assertHas(url: "https://example.com/items/archived-item-2")
}

@MainActor
Expand Down
4 changes: 4 additions & 0 deletions Tests iOS/Support/Response+factories.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ extension Response {
return Response.archive()
} else if apiRequest.isToSaveAnItem {
return Response.saveItem()
} else if apiRequest.isForRecommendationDetail(1) {
return Response.recommendationDetail(1)
} else if apiRequest.isForReplacingSavedItemTags {
return Response.savedItemWithTag()
} else {
fatalError("Unexpected request")
}
Expand Down
2 changes: 1 addition & 1 deletion Tests iOS/Support/SnowplowMicro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class SnowplowMicro {
/**
Make a request to snowplow micro
*/
internal func snowplowRequest(path: String, method: String = "GET") async -> Data {
internal func snowplowRequest(path: String, method: String = "GET", shouldWait: Bool = true) async -> Data {
// For now we wait 5 seconds for snowplow data to be available because the iOS app flushes it to the server. In the future we could poll or find a way to make the make instant calls to snowplow.
_ = XCTWaiter.wait(for: [XCTestExpectation(description: "Wait 5 seconds for snowplow data to be available.")], timeout: 5.0)
let data = try! await self.client.httpData(from: URL(string: "http://localhost:9090\(path)")!, method: method)
Expand Down

0 comments on commit 60594ca

Please sign in to comment.