|
| 1 | +describe("Authenticated User Flows", () => { |
| 2 | + beforeEach(() => { |
| 3 | + // Use username/password from environment variables |
| 4 | + cy.login(Cypress.env("TEST_EMAIL"), Cypress.env("TEST_PASSWORD")); |
| 5 | + }); |
| 6 | + |
| 7 | + it("homepage shows authenticated state", () => { |
| 8 | + cy.visit("/"); |
| 9 | + |
| 10 | + // Should see welcome message for authenticated user |
| 11 | + cy.contains(/welcome back/i).should("be.visible"); |
| 12 | + |
| 13 | + // Should see account navigation |
| 14 | + cy.get("a") |
| 15 | + .contains(/view account/i) |
| 16 | + .should("be.visible"); |
| 17 | + |
| 18 | + // Should see sign out button |
| 19 | + // There are multiple sign out buttons, so we need to make sure we see at least one |
| 20 | + cy.get("button") |
| 21 | + .contains(/sign out/i) |
| 22 | + .first() |
| 23 | + .should("be.visible"); |
| 24 | + |
| 25 | + // Should NOT see sign in button |
| 26 | + cy.get("a") |
| 27 | + .contains(/sign in/i) |
| 28 | + .should("not.exist"); |
| 29 | + }); |
| 30 | + |
| 31 | + it("can navigate to account page", () => { |
| 32 | + cy.visit("/"); |
| 33 | + |
| 34 | + // Click on "View account" link |
| 35 | + cy.get("a") |
| 36 | + .contains(/view account/i) |
| 37 | + .click(); |
| 38 | + |
| 39 | + // Should navigate to account page |
| 40 | + cy.url().should("include", "/account"); |
| 41 | + |
| 42 | + // Should see account details heading |
| 43 | + cy.get("h1, h2, h3") |
| 44 | + .contains(/account details/i) |
| 45 | + .should("be.visible"); |
| 46 | + |
| 47 | + // Should see some user information fields |
| 48 | + cy.contains("Email").should("be.visible"); |
| 49 | + |
| 50 | + // Should see the email address in a readonly input |
| 51 | + cy.get("input[readonly]") |
| 52 | + .filter(`[value="${Cypress.env("TEST_EMAIL")}"]`) |
| 53 | + .should("exist"); |
| 54 | + |
| 55 | + // Should see user ID field |
| 56 | + cy.contains("Id", { matchCase: false }).should("be.visible"); |
| 57 | + }); |
| 58 | + |
| 59 | + it("account page is protected - direct access works when authenticated", () => { |
| 60 | + // Direct navigation to protected route should work when authenticated |
| 61 | + cy.visit("/account"); |
| 62 | + |
| 63 | + // Should see account details page |
| 64 | + cy.get("h1, h2, h3") |
| 65 | + .contains(/account details/i) |
| 66 | + .should("be.visible"); |
| 67 | + |
| 68 | + // Should see user information |
| 69 | + cy.contains("Email").should("be.visible"); |
| 70 | + }); |
| 71 | + |
| 72 | + it("can sign out successfully", () => { |
| 73 | + cy.visit("/"); |
| 74 | + |
| 75 | + // Verify we start authenticated |
| 76 | + cy.contains(/welcome back/i).should("be.visible"); |
| 77 | + |
| 78 | + // Click sign out button |
| 79 | + cy.get("button") |
| 80 | + .contains(/sign out/i) |
| 81 | + .first() |
| 82 | + .click(); |
| 83 | + |
| 84 | + // Wait for sign out to complete and page to update |
| 85 | + cy.url().should("eq", Cypress.config("baseUrl") + "/"); |
| 86 | + |
| 87 | + // Should see unauthenticated state |
| 88 | + cy.get("h1, h2, h3") |
| 89 | + .contains(/authkit authentication example/i) |
| 90 | + .should("be.visible"); |
| 91 | + cy.get("a") |
| 92 | + .contains(/sign in with authkit/i) |
| 93 | + .should("be.visible"); |
| 94 | + cy.contains(/sign in to view your account details/i).should("be.visible"); |
| 95 | + |
| 96 | + // Should NOT see authenticated elements |
| 97 | + cy.contains(/welcome back/i).should("not.exist"); |
| 98 | + cy.contains(/sign out/i).should("not.exist"); |
| 99 | + }); |
| 100 | + |
| 101 | + it("navigation between pages works correctly", () => { |
| 102 | + // Start at home |
| 103 | + cy.visit("/"); |
| 104 | + cy.contains(/welcome back/i).should("be.visible"); |
| 105 | + |
| 106 | + // Go to account |
| 107 | + cy.get("a") |
| 108 | + .contains(/view account/i) |
| 109 | + .click(); |
| 110 | + cy.url().should("include", "/account"); |
| 111 | + cy.get("h1, h2, h3") |
| 112 | + .contains(/account details/i) |
| 113 | + .should("be.visible"); |
| 114 | + |
| 115 | + // Go back to home via browser navigation |
| 116 | + cy.go("back"); |
| 117 | + cy.url().should("not.include", "/account"); |
| 118 | + cy.contains(/welcome back/i).should("be.visible"); |
| 119 | + |
| 120 | + // Go forward again |
| 121 | + cy.go("forward"); |
| 122 | + cy.url().should("include", "/account"); |
| 123 | + cy.get("h1, h2, h3") |
| 124 | + .contains(/account details/i) |
| 125 | + .should("be.visible"); |
| 126 | + }); |
| 127 | +}); |
0 commit comments