|
| 1 | +// |
| 2 | +// Created by Eugene Kazaev on 05/09/2020. |
| 3 | +// Copyright (c) 2020 CocoaPods. All rights reserved. |
| 4 | +// |
| 5 | + |
| 6 | +@testable import ChatLayout |
| 7 | +import XCTest |
| 8 | + |
| 9 | +class StateControllerInternalTests: XCTestCase { |
| 10 | + |
| 11 | + func testUpdatePreferredSize() { |
| 12 | + let layout = MockCollectionLayout() |
| 13 | + layout.controller.set(layout.getPreparedSections(), at: .beforeUpdate) |
| 14 | + layout.controller.update(preferredSize: CGSize(width: 300, height: 100), for: IndexPath(item: 0, section: 0), kind: .footer, at: .beforeUpdate) |
| 15 | + layout.controller.update(preferredSize: CGSize(width: 300, height: 300), for: IndexPath(item: 0, section: 0), kind: .cell, at: .beforeUpdate) |
| 16 | + layout.controller.update(preferredSize: CGSize(width: 300, height: 100), for: IndexPath(item: 0, section: 0), kind: .header, at: .beforeUpdate) |
| 17 | + XCTAssertEqual(layout.controller.itemFrame(for: IndexPath(item: 0, section: 0), kind: .header, at: .beforeUpdate)?.size, CGSize(width: 300, height: 100)) |
| 18 | + XCTAssertEqual(layout.controller.itemFrame(for: IndexPath(item: 0, section: 0), kind: .footer, at: .beforeUpdate)?.size, CGSize(width: 300, height: 100)) |
| 19 | + XCTAssertEqual(layout.controller.itemFrame(for: IndexPath(item: 0, section: 0), kind: .cell, at: .beforeUpdate)?.size, CGSize(width: 300, height: 300)) |
| 20 | + XCTAssertEqual(layout.controller.itemFrame(for: IndexPath(item: 1, section: 0), kind: .cell, at: .beforeUpdate)?.size, CGSize(width: 300, height: 40)) |
| 21 | + } |
| 22 | + |
| 23 | + func testUpdatePreferredAlignment() { |
| 24 | + let layout = MockCollectionLayout() |
| 25 | + layout.settings.additionalInsets = UIEdgeInsets(top: 0, left: 13, bottom: 0, right: 7) |
| 26 | + layout.controller.set(layout.getPreparedSections(), at: .beforeUpdate) |
| 27 | + |
| 28 | + layout.controller.update(preferredSize: CGSize(width: 100, height: 100), for: IndexPath(item: 0, section: 0), kind: .footer, at: .beforeUpdate) |
| 29 | + layout.controller.update(preferredSize: CGSize(width: 100, height: 300), for: IndexPath(item: 0, section: 0), kind: .cell, at: .beforeUpdate) |
| 30 | + layout.controller.update(preferredSize: CGSize(width: 100, height: 100), for: IndexPath(item: 0, section: 0), kind: .header, at: .beforeUpdate) |
| 31 | + layout.controller.update(preferredSize: CGSize(width: 100, height: 100), for: IndexPath(item: 1, section: 0), kind: .cell, at: .beforeUpdate) |
| 32 | + |
| 33 | + layout.controller.update(alignment: .leading, for: IndexPath(item: 0, section: 0), kind: .footer, at: .beforeUpdate) |
| 34 | + layout.controller.update(alignment: .trailing, for: IndexPath(item: 0, section: 0), kind: .header, at: .beforeUpdate) |
| 35 | + layout.controller.update(alignment: .center, for: IndexPath(item: 0, section: 0), kind: .cell, at: .beforeUpdate) |
| 36 | + layout.controller.update(alignment: .full, for: IndexPath(item: 1, section: 0), kind: .cell, at: .beforeUpdate) |
| 37 | + |
| 38 | + XCTAssertEqual(layout.controller.itemAttributes(for: IndexPath(item: 0, section: 0), kind: .header, at: .beforeUpdate)?.alignment, .trailing) |
| 39 | + XCTAssertEqual(layout.controller.itemAttributes(for: IndexPath(item: 0, section: 0), kind: .footer, at: .beforeUpdate)?.alignment, .leading) |
| 40 | + XCTAssertEqual(layout.controller.itemAttributes(for: IndexPath(item: 0, section: 0), kind: .cell, at: .beforeUpdate)?.alignment, .center) |
| 41 | + XCTAssertEqual(layout.controller.itemAttributes(for: IndexPath(item: 1, section: 0), kind: .cell, at: .beforeUpdate)?.alignment, .full) |
| 42 | + XCTAssertEqual(layout.controller.itemAttributes(for: IndexPath(item: 2, section: 0), kind: .cell, at: .beforeUpdate)?.alignment, .full) |
| 43 | + |
| 44 | + XCTAssertEqual(layout.controller.itemAttributes(for: IndexPath(item: 0, section: 0), kind: .header, at: .beforeUpdate)?.frame.origin.x, 300 - 100 - layout.settings.additionalInsets.right) |
| 45 | + XCTAssertEqual(layout.controller.itemAttributes(for: IndexPath(item: 0, section: 0), kind: .footer, at: .beforeUpdate)?.frame.origin.x, layout.settings.additionalInsets.left) |
| 46 | + XCTAssertEqual(layout.controller.itemAttributes(for: IndexPath(item: 0, section: 0), kind: .cell, at: .beforeUpdate)?.frame.origin.x, layout.settings.additionalInsets.left + (300 - layout.settings.additionalInsets.right - layout.settings.additionalInsets.left) / 2 - 100 / 2) |
| 47 | + XCTAssertEqual(layout.controller.itemAttributes(for: IndexPath(item: 1, section: 0), kind: .cell, at: .beforeUpdate)?.frame.origin.x, layout.settings.additionalInsets.left) |
| 48 | + XCTAssertEqual(layout.controller.itemAttributes(for: IndexPath(item: 1, section: 0), kind: .cell, at: .beforeUpdate)?.frame.width, 300 - layout.settings.additionalInsets.left - layout.settings.additionalInsets.right) |
| 49 | + } |
| 50 | + |
| 51 | + func testItemIdentifierAtIndexPath() { |
| 52 | + let layout = MockCollectionLayout() |
| 53 | + layout.controller.set(layout.getPreparedSections(), at: .beforeUpdate) |
| 54 | + XCTAssertEqual(layout.controller.itemIdentifier(for: IndexPath(item: 0, section: 0), kind: .cell, at: .beforeUpdate), layout.controller.storage[.beforeUpdate]?.sections[0].items[0].id) |
| 55 | + XCTAssertEqual(layout.controller.itemIdentifier(for: IndexPath(item: 0, section: 0), kind: .header, at: .beforeUpdate), layout.controller.storage[.beforeUpdate]?.sections[0].header?.id) |
| 56 | + XCTAssertEqual(layout.controller.itemIdentifier(for: IndexPath(item: 0, section: 0), kind: .footer, at: .beforeUpdate), layout.controller.storage[.beforeUpdate]?.sections[0].footer?.id) |
| 57 | + } |
| 58 | + |
| 59 | + func testSectionIdentifierAtIndexPath() { |
| 60 | + let layout = MockCollectionLayout() |
| 61 | + layout.controller.set(layout.getPreparedSections(), at: .beforeUpdate) |
| 62 | + XCTAssertEqual(layout.controller.sectionIdentifier(for: 0, at: .beforeUpdate), layout.controller.storage[.beforeUpdate]?.sections[0].id) |
| 63 | + XCTAssertEqual(layout.controller.sectionIdentifier(for: 1, at: .beforeUpdate), layout.controller.storage[.beforeUpdate]?.sections[1].id) |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments