ActionSheetStandardPresenterTests.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // ActionSheetStandardPresenterTests.swift
  3. // SheeeeeeeeetTests
  4. //
  5. // Created by Daniel Saidi on 2018-10-18.
  6. // Copyright © 2018 Daniel Saidi. All rights reserved.
  7. //
  8. import Quick
  9. import Nimble
  10. @testable import Sheeeeeeeeet
  11. class ActionSheetStandardPresenterTests: QuickSpec {
  12. override func spec() {
  13. var presenter: ActionSheetStandardPresenter!
  14. var sheet: MockActionSheet!
  15. var backgroundView: ActionSheetBackgroundView!
  16. var stackView: UIStackView!
  17. beforeEach {
  18. backgroundView = ActionSheetBackgroundView(frame: .zero)
  19. stackView = UIStackView(frame: CGRect(x: 0, y: 0, width: 0, height: 100))
  20. sheet = MockActionSheet(items: []) { _, _ in }
  21. sheet.backgroundView = backgroundView
  22. sheet.stackView = stackView
  23. presenter = ActionSheetStandardPresenter()
  24. presenter.animationDuration = 0
  25. presenter.actionSheet = sheet
  26. }
  27. describe("background tap dismissal") {
  28. it("is enabled by default") {
  29. expect(presenter.isDismissableWithTapOnBackground).to(beTrue())
  30. }
  31. }
  32. describe("dismissing action sheet") {
  33. var counter: Int!
  34. beforeEach {
  35. counter = 0
  36. presenter.dismiss { counter += 1 }
  37. }
  38. it("calls completion directly") {
  39. expect(counter).to(equal(1))
  40. }
  41. it("removes background view") {
  42. expect(backgroundView.alpha).to(equal(0))
  43. }
  44. it("removes action sheet") {
  45. expect(stackView.frame.origin.y).to(equal(200))
  46. expect(sheet.view.superview).to(beNil())
  47. expect(presenter.actionSheet).toEventually(beNil())
  48. }
  49. }
  50. describe("presenting action sheet") {
  51. var vc: MockViewController!
  52. var counter: Int!
  53. beforeEach {
  54. vc = MockViewController()
  55. vc.view.frame = CGRect(x: 1, y: 2, width: 3, height: 4)
  56. counter = 0
  57. presenter.present(sheet: sheet, in: vc) { counter += 1 }
  58. }
  59. it("sets action sheet") {
  60. expect(presenter.actionSheet).to(be(sheet))
  61. }
  62. it("adds actio sheet to vc view") {
  63. expect(sheet.view.frame).to(equal(vc.view.frame))
  64. expect(vc.view.subviews).to(contain(sheet.view))
  65. }
  66. it("adds tap gesture to background view") {
  67. expect(sheet.backgroundView?.isUserInteractionEnabled).to(beTrue())
  68. //expect(backgroundView.gestureRecognizers?.count).to(equal(1))
  69. }
  70. it("presents background view") {
  71. presenter.animationDuration = -1
  72. presenter.present(sheet: sheet, in: vc) {}
  73. expect(sheet.backgroundView?.alpha).to(equal(0))
  74. presenter.animationDuration = 0
  75. presenter.present(sheet: sheet, in: vc) {}
  76. expect(sheet.backgroundView?.alpha).to(equal(1))
  77. }
  78. it("presents stack view") {
  79. presenter.present(sheet: sheet, in: vc) {}
  80. expect(sheet.stackView?.frame.origin.y).to(equal(277))
  81. }
  82. }
  83. }
  84. }