// HIDDEN CATEGORIES (CONTRACT-2 HIDDEN, NEXT-HIDDEN.md), walked by taps on Cinemas Dev's invented library: a category// hidden from its menu on Home (the Hide sheet's honest line, then Hide) leaves Home; You › Hidden, behind the lock// (`-cinemas-skip-lock` stands for Face ID passing on a simulator), holds it, and a search there finds its titles;// leaving the app locks Hidden again; Stop hiding brings the category back to Home. A phone with no lock opens Hidden// and says so (`-cinemas-no-lock`).import XCTestfinalclassCinemasHiddenTests: XCTestCase {overridefunc setUp() { continueAfterFailure = false } @MainActor privatefunc element(_ app: XCUIApplication, _ id: String) -> XCUIElement { app.descendants(matching: .any)[id].firstMatch } @MainActor privatefunc shot(_ app: XCUIApplication, _ name: String) {let attachment = XCTAttachment(screenshot: app.screenshot()) attachment.name = name attachment.lifetime = .keepAlways add(attachment) }/// Scrolls until `target` stands clear above the tab bar. @MainActor privatefunc reach(_ app: XCUIApplication, _ target: XCUIElement, up: Bool = true) {let bar = element(app, "cinemas-tab-home").frame.minY - 20var swipes = 0while (!target.exists || !target.isHittable || target.frame.maxY > bar) && swipes < 12 {if up { app.swipeUp(velocity: .slow) } else { app.swipeDown(velocity: .slow) } swipes += 1 } } @MainActor func testHideFindInHiddenAndStopHiding() throws {let app = XCUIApplication() app.launchArguments += ["-cinemas-invent", "-cinemas-skip-lock"] app.launch() XCTAssertTrue(element(app, "cinemas-tab-home").waitForExistence(timeout: 30))// Hide "With the children" from its menu on Home.let menu = element(app, "cinemas-row-menu-group:g-kids") reach(app, menu) XCTAssertTrue(menu.exists, "the category's menu on Home") menu.tap()let hide = app.buttons["Hide this category"].firstMatch XCTAssertTrue(hide.waitForExistence(timeout: 4)) hide.tap() XCTAssertTrue(element(app, "cinemas-hide-sheet").waitForExistence(timeout: 6), "the Hide sheet, with its honest line") XCTAssertTrue(app.staticTexts["Hide With the children?"].exists) XCTAssertTrue(app.staticTexts["Hidden categories do not show in Cinemas. Find them in You, Hidden."].exists, "the new words: no assistants") shot(app, "Hidden 1 the Hide sheet") element(app, "cinemas-hide-confirm").tap() XCTAssertTrue(app.staticTexts["With the children is hidden"].waitForExistence(timeout: 6), "the core's words, with Undo") XCTAssertTrue(element(app, "cinemas-row-group:g-kids").waitForNonExistence(timeout: 6), "gone from Home") XCTAssertFalse(element(app, "cinemas-poster-films-f-kite").exists, "its titles too") shot(app, "Hidden 2 Home without it")// You › Hidden, the last row of You. element(app, "cinemas-tab-you").tap()let row = element(app, "cinemas-you-hidden") reach(app, row) XCTAssertTrue(row.exists, "Hidden, the last row of You") row.tap() XCTAssertTrue(element(app, "cinemas-hidden").waitForExistence(timeout: 6)) XCTAssertTrue(element(app, "cinemas-row-group:g-kids").waitForExistence(timeout: 6), "the hidden category, inside") shot(app, "Hidden 3 inside")let search = element(app, "cinemas-hidden-search") search.tap() search.typeText("kite") XCTAssertTrue(element(app, "cinemas-hidden-found-f-kite").waitForExistence(timeout: 6), "search inside finds hidden titles") shot(app, "Hidden 4 search inside")// Leaving the app locks Hidden again: back, it is closed. XCUIDevice.shared.press(.home)Thread.sleep(forTimeInterval: 2) app.activate() XCTAssertTrue(element(app, "cinemas-hidden").waitForNonExistence(timeout: 6), "locked again on leaving the app")// In again, and Stop hiding from the category's menu. reach(app, row) row.tap()let inside = element(app, "cinemas-row-menu-group:g-kids") XCTAssertTrue(inside.waitForExistence(timeout: 6)) inside.tap()let stop = app.buttons["Show this category"].firstMatch XCTAssertTrue(stop.waitForExistence(timeout: 4)) stop.tap() XCTAssertTrue(app.staticTexts["With the children is back on Home"].waitForExistence(timeout: 6)) element(app, "cinemas-tab-home").tap()let back = element(app, "cinemas-row-group:g-kids") reach(app, back) XCTAssertTrue(back.exists, "back on Home") }/// A phone with no screen lock opens Hidden and says so, with Set a screen lock. @MainActor func testNoLockSaysSo() throws {let app = XCUIApplication() app.launchArguments += ["-cinemas-invent", "-cinemas-no-lock", "-cinemas-open", "hidden"] app.launch() XCTAssertTrue(element(app, "cinemas-hidden-no-lock").waitForExistence(timeout: 30)) XCTAssertTrue(element(app, "cinemas-hidden-set-lock").exists) XCTAssertTrue(element(app, "cinemas-hidden-empty").exists, "nothing hidden yet, and how to hide") shot(app, "Hidden 5 no lock") }}