import XCTest @testable import Wikipedia @testable import WMF class TalkPageNetworkDataTests: XCTestCase { let session = MWKDataStore.temporary().session func testLocalJsonDecodesToTalkPage() { guard let json = wmf_bundle().wmf_data(fromContentsOfFile: TalkPageTestHelpers.TalkPageJSONType.original.fileName, ofType: "json") else { XCTFail("Failure pulling local talk page json") return } do { let result: NetworkBase = try session.jsonDecodeData(data: json) let topics = result.topics XCTAssertEqual(topics.count, 6, "Unexpected topic count") XCTAssertEqual(topics[1].html, "Let’s talk about talk pages", "Unexpected topic title") XCTAssertEqual(topics[1].replies.count, 3, "Unexpected replies count") let firstItem = topics[1].replies[0] XCTAssertEqual(firstItem.html, "Hello, I am testing a new topic from the iOS app. It is fun. 47.184.10.84 20:50, 21 June 2019 (UTC)", "Unexpected reply text") XCTAssertEqual(firstItem.depth, 0, "Unexpected reply depth") let secondItem = topics[1].replies[1] XCTAssertEqual(secondItem.html, "Hello back! This is a nested reply. TSevener (WMF) (talk) 20:51, 21 June 2019 (UTC)", "Unexpected reply text") XCTAssertEqual(secondItem.depth, 1, "Unexpected reply depth") let thirdItem = topics[1].replies[2] XCTAssertEqual(thirdItem.html, "Yes I see, I am nested as well. 47.184.10.84 20:52, 21 June 2019 (UTC)", "Unexpected reply text") XCTAssertEqual(thirdItem.depth, 2, "Unexpected reply depth") } catch let error { XCTFail("Talk Page json failed to decode \(error)") } } }