Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1028 committed Jul 29, 2019
1 parent f02b82f commit 80dc5e3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 18 deletions.
71 changes: 53 additions & 18 deletions Tests/RendererTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ final class RendererTests: XCTestCase {
adapter: adapter,
updater: MockUpdater()
)
renderer.target = target

var completed = false
let data = [
Expand All @@ -78,9 +77,11 @@ final class RendererTests: XCTestCase {
Section(id: TestID.c)
]

renderer.render(data) {
renderer.target = target
renderer.completion = {
completed = true
}
renderer.render(data)

XCTAssertEqual(renderer.adapter.data.count, 3)
XCTAssertEqual(renderer.updater.targetCapturedOnUpdates, target)
Expand All @@ -95,7 +96,6 @@ final class RendererTests: XCTestCase {
adapter: adapter,
updater: MockUpdater()
)
renderer.target = target

var completed = false
let data = [
Expand All @@ -106,9 +106,11 @@ final class RendererTests: XCTestCase {
Section(id: TestID.c)
]

renderer.render(data) {
renderer.target = target
renderer.completion = {
completed = true
}
renderer.render(data)

XCTAssertEqual(renderer.adapter.data.count, 3)
XCTAssertEqual(renderer.updater.targetCapturedOnUpdates, target)
Expand All @@ -123,18 +125,20 @@ final class RendererTests: XCTestCase {
adapter: adapter,
updater: MockUpdater()
)
renderer.target = target

var completed = false

renderer.render(
let data = [
Section(id: TestID.a),
Section(id: TestID.b),
Section(id: TestID.c),
Section(id: TestID.d),
completion: {
completed = true
})
Section(id: TestID.d)
]

renderer.target = target
renderer.completion = {
completed = true
}
renderer.render(data)

XCTAssertEqual(renderer.adapter.data.count, 4)
XCTAssertEqual(renderer.updater.targetCapturedOnUpdates, target)
Expand All @@ -149,20 +153,51 @@ final class RendererTests: XCTestCase {
adapter: adapter,
updater: MockUpdater()
)
renderer.target = target

var completed = false

renderer.render(
let data = [
Section(id: TestID.a),
Section(id: TestID.b),
nil,
Section(id: TestID.c),
nil,
Section(id: TestID.d),
completion: {
completed = true
})
Section(id: TestID.d)
]

renderer.target = target
renderer.completion = {
completed = true
}
renderer.render(data)

XCTAssertEqual(renderer.adapter.data.count, 4)
XCTAssertEqual(renderer.updater.targetCapturedOnUpdates, target)
XCTAssertEqual(renderer.updater.adapterCapturedOnUpdates, adapter)
XCTAssertEqual(completed, true)
}

func testRenderWithBuilderClosure() {
let target = MockTarget()
let adapter = MockAdapter()
let renderer = Renderer(
adapter: adapter,
updater: MockUpdater()
)

var completed = false
let data = [
Section(id: TestID.a),
Section(id: TestID.b),
Section(id: TestID.c),
Section(id: TestID.d)
]

renderer.target = target
renderer.completion = {
completed = true
}
renderer.render(data)
renderer.render { $0 = data }

XCTAssertEqual(renderer.adapter.data.count, 4)
XCTAssertEqual(renderer.updater.targetCapturedOnUpdates, target)
Expand Down
17 changes: 17 additions & 0 deletions Tests/SectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ final class SectionTests: XCTestCase {
XCTAssertEqual(section.cells.count, 2)
}

func testInitWithBuilderClosure() {
let section = Section(id: TestID.a) { section in
section.header = ViewNode(A.Component())
section.cells = [
CellNode(MockIdentifiableComponent(id: TestID.a)),
CellNode(MockIdentifiableComponent(id: TestID.b)),
CellNode(MockIdentifiableComponent(id: TestID.c))
]
section.footer = ViewNode(A.Component())
}

XCTAssertEqual(section.id.base as? TestID, .a)
XCTAssertNotNil(section.header)
XCTAssertNotNil(section.footer)
XCTAssertEqual(section.cells.count, 3)
}

func testContentEquatableConformance() {
let section1 = Section(
id: TestID.a,
Expand Down

0 comments on commit 80dc5e3

Please sign in to comment.