|
1 | | -import XCTest |
| 1 | +// |
| 2 | +// AdvancedListTests.swift |
| 3 | +// AdvancedListTests |
| 4 | +// |
| 5 | +// Created by Christian Elies on 21.02.20. |
| 6 | +// |
| 7 | + |
2 | 8 | @testable import AdvancedList |
| 9 | +import SwiftUI |
| 10 | +import XCTest |
3 | 11 |
|
4 | 12 | final class AdvancedListTests: XCTestCase { |
5 | | - func testExample() { |
6 | | - // This is an example of a functional test case. |
7 | | - // Use XCTAssert and related functions to verify your tests produce the correct |
8 | | - // results. |
9 | | - XCTAssertEqual(AdvancedList().text, "Hello, World!") |
| 13 | + @State private var listState: ListState = .items |
| 14 | + |
| 15 | + private let emptyStateView = Text("Empty") |
| 16 | + private let errorStateView = Text("Error") |
| 17 | + private let loadingStateView = Text("Loading ...") |
| 18 | + |
| 19 | + override func setUp() { |
| 20 | + listState = .items |
| 21 | + } |
| 22 | + |
| 23 | + func testEmptyStateView() { |
| 24 | + let items: [String] = [] |
| 25 | + |
| 26 | + let view = AdvancedList(items, content: { item in Text(item) }, |
| 27 | + listState: $listState, |
| 28 | + emptyStateView: { self.emptyStateView }, |
| 29 | + errorStateView: { _ in self.errorStateView }, |
| 30 | + loadingStateView: { self.loadingStateView }, |
| 31 | + pagination: .noPagination) |
| 32 | + |
| 33 | + let body = view.body as? AnyView |
| 34 | + XCTAssertNotNil(body) |
| 35 | + } |
| 36 | + |
| 37 | + func testNotEmptyStateView() { |
| 38 | + let items: [String] = ["MockItem1", "MockItem2"] |
| 39 | + |
| 40 | + let view = AdvancedList(items, content: { item in Text(item) }, |
| 41 | + listState: $listState, |
| 42 | + emptyStateView: { self.emptyStateView }, |
| 43 | + errorStateView: { _ in self.errorStateView }, |
| 44 | + loadingStateView: { self.loadingStateView }, |
| 45 | + pagination: .noPagination) |
| 46 | + |
| 47 | + let body = view.body as? AnyView |
| 48 | + XCTAssertNotNil(body) |
| 49 | + } |
| 50 | + |
| 51 | + func testLoadingStateView() { |
| 52 | + listState = .loading |
| 53 | + |
| 54 | + let items: [String] = [] |
| 55 | + |
| 56 | + let view = AdvancedList(items, content: { item in Text(item) }, |
| 57 | + listState: $listState, |
| 58 | + emptyStateView: { self.emptyStateView }, |
| 59 | + errorStateView: { _ in self.errorStateView }, |
| 60 | + loadingStateView: { self.loadingStateView }, |
| 61 | + pagination: .noPagination) |
| 62 | + |
| 63 | + let body = view.body as? AnyView |
| 64 | + XCTAssertNotNil(body) |
| 65 | + } |
| 66 | + |
| 67 | + func testErrorStateView() { |
| 68 | + let error = NSError(domain: "MockDomain", code: 1, userInfo: nil) |
| 69 | + listState = .error(error) |
| 70 | + |
| 71 | + let items: [String] = [] |
| 72 | + |
| 73 | + let view = AdvancedList(items, content: { item in Text(item) }, |
| 74 | + listState: $listState, |
| 75 | + emptyStateView: { self.emptyStateView }, |
| 76 | + errorStateView: { _ in self.errorStateView }, |
| 77 | + loadingStateView: { self.loadingStateView }, |
| 78 | + pagination: .noPagination) |
| 79 | + |
| 80 | + let body = view.body as? AnyView |
| 81 | + XCTAssertNotNil(body) |
10 | 82 | } |
11 | 83 |
|
12 | 84 | static var allTests = [ |
13 | | - ("testExample", testExample), |
| 85 | + ("testEmptyStateView", testEmptyStateView), |
| 86 | + ("testNotEmptyStateView", testNotEmptyStateView), |
| 87 | + ("testLoadingStateView", testLoadingStateView), |
| 88 | + ("testErrorStateView", testErrorStateView) |
14 | 89 | ] |
15 | 90 | } |
0 commit comments