import XCTest @testable import CottonUI /// A swipe that comes to rest on a view card shows that view again on iPhone, /// as the owner's first fan did and Android's views arc does (`onRaise`). @MainActor final class FanRestChoosesViewTests: XCTestCase { /// RULE: a person's swipe that comes to rest on the views tier of the tool the fan stands on chooses the view rested on; a rest on any other tier (acts, choices, faces, a whole) chooses nothing, so acts never run by swiping; a tap's turn and a turn nobody asked for choose nothing. func testASwipesRestOnTheViewsTierChoosesAndNothingElseDoes() { let views = ViewTier.id(of: "books") let swipe = ArcChoice.chooses(.settled, byPerson: true, swiped: true) XCTAssertTrue(ViewTier.choosesOnRest(tier: views, viewsTool: "books", chose: swipe), "a swipe's rest shows the view") XCTAssertFalse(ViewTier.choosesOnRest(tier: "acts", viewsTool: "books", chose: swipe), "a rest on acts runs nothing") XCTAssertFalse(ViewTier.choosesOnRest(tier: "whole-books", viewsTool: "books", chose: swipe)) XCTAssertFalse(ViewTier.choosesOnRest(tier: ViewTier.id(of: "notes"), viewsTool: "books", chose: swipe), "another tool's views are not the ones standing") XCTAssertFalse(ViewTier.choosesOnRest(tier: views, viewsTool: nil, chose: swipe)) let tap = ArcChoice.chooses(.settled, byPerson: true, swiped: false) XCTAssertFalse(ViewTier.choosesOnRest(tier: views, viewsTool: "books", chose: tap), "a side tap only turns") let nobody = ArcChoice.chooses(.settled, byPerson: false, swiped: false) XCTAssertFalse(ViewTier.choosesOnRest(tier: views, viewsTool: "books", chose: nobody), "a programmatic turn chooses nothing") } #if os(iOS) /// RULE: the arc's motion is what the rest is judged by — a finger's swipe counts as a choice where it lands, a side tap's turn (`FanTiers.activate`) and the arc standing anew do not. func testTheArcsMotionTellsASwipeFromATurn() { let motion = FanMotion(geometry: FanGeometry(scale: Theme.paper.scale), spring: FanSpring(scale: Theme.paper.scale)) motion.recount(5) motion.beginDrag() motion.drag(-400) motion.release(pointsPerSecond: 0, flings: false) XCTAssertTrue(ArcChoice.chooses(.settled, byPerson: motion.byPerson, swiped: motion.swiped)) motion.turn(to: 0, animated: false) XCTAssertFalse(ArcChoice.chooses(.settled, byPerson: motion.byPerson, swiped: motion.swiped)) } #endif }