settings.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // ---------------------------------------------------------------------------
  2. // Page-object helpers for the /settings view.
  3. // ---------------------------------------------------------------------------
  4. import type { Terminal } from "@microsoft/tui-test/lib/terminal/term"
  5. import { expectVisible } from "../terminal.js"
  6. const TAB_ORDER = ["API", "Auto-approve", "Features", "Account", "Other"] as const
  7. export type SettingsTab = (typeof TAB_ORDER)[number]
  8. /**
  9. * Navigate to a specific settings tab by pressing Right from the API tab (index 0).
  10. * Waits for each tab's content to appear before pressing the next key, making
  11. * navigation deterministic regardless of machine speed.
  12. */
  13. export async function goToSettingsTab(terminal: Terminal, tab: SettingsTab): Promise<void> {
  14. const targetIndex = TAB_ORDER.indexOf(tab)
  15. for (let i = 0; i < targetIndex; i++) {
  16. terminal.keyRight()
  17. // Wait for the next tab's content to appear before pressing again
  18. await assertTabContent(terminal, TAB_ORDER[i + 1])
  19. }
  20. }
  21. /** Assert the API tab content is visible */
  22. export async function assertApiTab(terminal: Terminal): Promise<void> {
  23. await expectVisible(terminal, ["Provider:", "Model ID:"])
  24. }
  25. /** Assert the Auto-approve tab content is visible */
  26. export async function assertAutoApproveTab(terminal: Terminal): Promise<void> {
  27. await expectVisible(terminal, ["Read project files", "Execute safe commands", "Edit project files"])
  28. }
  29. /** Assert the Features tab content is visible */
  30. export async function assertFeaturesTab(terminal: Terminal): Promise<void> {
  31. await expectVisible(terminal, ["Subagents", "Web tools", "Double-check completion"])
  32. }
  33. /** Assert the Account tab content is visible */
  34. export async function assertAccountTab(terminal: Terminal): Promise<void> {
  35. // The account tab shows sign-in options when not authenticated to Cline
  36. await expectVisible(terminal, /sign in|sign out/i)
  37. }
  38. /** Assert the Other tab content is visible */
  39. export async function assertOtherTab(terminal: Terminal): Promise<void> {
  40. await expectVisible(terminal, ["Preferred language:", "Cline v"])
  41. }
  42. /**
  43. * Assert the content for a given tab is visible.
  44. * Used internally by goToSettingsTab to confirm navigation landed correctly.
  45. */
  46. export async function assertTabContent(terminal: Terminal, tab: SettingsTab): Promise<void> {
  47. switch (tab) {
  48. case "API":
  49. return assertApiTab(terminal)
  50. case "Auto-approve":
  51. return assertAutoApproveTab(terminal)
  52. case "Features":
  53. return assertFeaturesTab(terminal)
  54. case "Account":
  55. return assertAccountTab(terminal)
  56. case "Other":
  57. return assertOtherTab(terminal)
  58. }
  59. }