- Re-verifica a permissão de notificações quando o app volta ao primeiro plano (scenePhase), refletindo mudanças feitas nos Ajustes do iPhone - Toggle otimista: liga imediatamente ao toque e reverte apenas se a autorização for negada - Prompt inicial completa a ativação sozinho ao voltar dos Ajustes com a permissão concedida - Novo teste de UI: ativar o lembrete pelo toggle das configurações Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
124 lines
4.9 KiB
Swift
124 lines
4.9 KiB
Swift
//
|
|
// Bible_WeekUITests.swift
|
|
// Bible-WeekUITests
|
|
//
|
|
// Created by Matheus A Silveira on 04/09/26.
|
|
//
|
|
|
|
import XCTest
|
|
|
|
final class Bible_WeekUITests: XCTestCase {
|
|
|
|
override func setUpWithError() throws {
|
|
continueAfterFailure = false
|
|
}
|
|
|
|
/// Fluxo da aba Bíblia: lista de livros -> Gênesis -> leitura do capítulo 1.
|
|
@MainActor
|
|
func testNavigateToGenesisChapter1() throws {
|
|
let app = XCUIApplication()
|
|
app.launch()
|
|
|
|
// Espera a lista de livros carregar da API.
|
|
let genesis = app.staticTexts["Gênesis"]
|
|
XCTAssertTrue(genesis.waitForExistence(timeout: 15), "Lista de livros não carregou")
|
|
genesis.tap()
|
|
|
|
// Espera o texto do capítulo 1 aparecer (Gn 1:1).
|
|
let firstVerse = app.staticTexts.containing(
|
|
NSPredicate(format: "label CONTAINS[cd] 'princípio'")
|
|
).firstMatch
|
|
XCTAssertTrue(firstVerse.waitForExistence(timeout: 15), "Capítulo 1 de Gênesis não carregou")
|
|
|
|
// Pausa para inspeção visual/screenshot externo.
|
|
sleep(4)
|
|
}
|
|
|
|
/// Fluxo do plano: começar o Plano de 180 Dias, ativar o lembrete diário
|
|
/// (aceitando a permissão do iOS) e verificar o chip e a Leitura de Hoje.
|
|
@MainActor
|
|
func testStartPlanAndEnableDailyReminder() throws {
|
|
let app = XCUIApplication()
|
|
app.launchArguments += ["--reset-plan"]
|
|
app.launch()
|
|
|
|
// Vai para a aba Plano.
|
|
let planTab = app.tabBars.buttons["Plano"]
|
|
XCTAssertTrue(planTab.waitForExistence(timeout: 10), "Aba Plano não encontrada")
|
|
planTab.tap()
|
|
|
|
// Inicia o plano.
|
|
let startButton = app.buttons["Começar plano"]
|
|
XCTAssertTrue(startButton.waitForExistence(timeout: 10), "Botão de começar o plano não apareceu")
|
|
startButton.tap()
|
|
|
|
// Prompt contextual do lembrete.
|
|
let activateButton = app.buttons["Ativar lembrete"]
|
|
XCTAssertTrue(activateButton.waitForExistence(timeout: 5), "Prompt do lembrete não apareceu")
|
|
activateButton.tap()
|
|
|
|
// Alerta de permissão do iOS (só aparece na primeira autorização).
|
|
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
|
|
let allowButton = springboard.buttons["Allow"].exists
|
|
? springboard.buttons["Allow"]
|
|
: springboard.buttons["Permitir"]
|
|
if allowButton.waitForExistence(timeout: 5) {
|
|
allowButton.tap()
|
|
}
|
|
|
|
// De volta ao plano: chip do lembrete e Leitura de Hoje visíveis.
|
|
let chip = app.staticTexts["Lembrete às 20:00"]
|
|
XCTAssertTrue(chip.waitForExistence(timeout: 10), "Chip do lembrete não apareceu")
|
|
|
|
XCTAssertTrue(app.staticTexts["Dia 1 de 180"].exists, "Cabeçalho do dia não apareceu")
|
|
XCTAssertTrue(app.staticTexts["Novo Testamento"].waitForExistence(timeout: 5), "Trilhas da Leitura de Hoje não apareceram")
|
|
|
|
// Pausa para inspeção visual/screenshot externo.
|
|
sleep(4)
|
|
}
|
|
|
|
/// Caminho alternativo: recusar o prompt inicial ("Agora não") e ligar o
|
|
/// lembrete depois, pelo toggle nas configurações do plano.
|
|
@MainActor
|
|
func testEnableReminderLaterFromSettingsToggle() throws {
|
|
let app = XCUIApplication()
|
|
app.launchArguments += ["--reset-plan"]
|
|
app.launch()
|
|
|
|
app.tabBars.buttons["Plano"].tap()
|
|
let startButton = app.buttons["Começar plano"]
|
|
XCTAssertTrue(startButton.waitForExistence(timeout: 10), "Botão de começar o plano não apareceu")
|
|
startButton.tap()
|
|
|
|
let laterButton = app.buttons["Agora não"]
|
|
XCTAssertTrue(laterButton.waitForExistence(timeout: 5), "Prompt do lembrete não apareceu")
|
|
laterButton.tap()
|
|
|
|
// Abre as configurações pela engrenagem.
|
|
let settingsButton = app.buttons["Configurações do plano"]
|
|
XCTAssertTrue(settingsButton.waitForExistence(timeout: 5), "Engrenagem não apareceu")
|
|
settingsButton.tap()
|
|
|
|
let toggle = app.switches["Lembrete diário"]
|
|
XCTAssertTrue(toggle.waitForExistence(timeout: 5), "Toggle do lembrete não apareceu")
|
|
toggle.switches.firstMatch.tap()
|
|
|
|
// Alerta de permissão do iOS (aparece se ainda não determinada).
|
|
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
|
|
let allowButton = springboard.buttons["Allow"].exists
|
|
? springboard.buttons["Allow"]
|
|
: springboard.buttons["Permitir"]
|
|
if allowButton.waitForExistence(timeout: 5) {
|
|
allowButton.tap()
|
|
}
|
|
|
|
// O toggle precisa ficar ligado.
|
|
let turnedOn = NSPredicate(format: "value == '1'")
|
|
let onExpectation = expectation(for: turnedOn, evaluatedWith: toggle)
|
|
wait(for: [onExpectation], timeout: 10)
|
|
|
|
// E o horário padrão deve aparecer.
|
|
XCTAssertTrue(app.staticTexts["Horário"].waitForExistence(timeout: 5), "Campo de horário não apareceu")
|
|
}
|
|
}
|