From 298ddbef094ba43245bdaa2fdcb2c4e72cefeb22 Mon Sep 17 00:00:00 2001
From: heikkkk <henrik.teksle.sandok@hotmail.no>
Date: Wed, 1 May 2024 11:06:22 +0200
Subject: [PATCH] test: add e2e tests for not found views

---
 cypress/e2e/NotFoundView.cy.ts | 17 +++++++++++++++++
 src/views/NotFoundView.vue     |  4 ++--
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 cypress/e2e/NotFoundView.cy.ts

diff --git a/cypress/e2e/NotFoundView.cy.ts b/cypress/e2e/NotFoundView.cy.ts
new file mode 100644
index 0000000..9f8515e
--- /dev/null
+++ b/cypress/e2e/NotFoundView.cy.ts
@@ -0,0 +1,17 @@
+describe('NotFound Test', () => {
+  beforeEach(() => {
+    cy.visit('/login');
+    cy.get('#emailInput input').type('user@example.com');
+    cy.get('#passwordInput input').type('John1');
+    cy.get('form').submit();
+    cy.wait(1000);
+    cy.visit('/')
+  })
+  it('redirects user when page is not found, then go home', () => {
+    cy.visit('/non-existent-page')
+    cy.get('[data-cy="404-error"]').should('exist')
+    cy.get('[data-cy="to-home"]').click()
+    cy.url().should('include', '/')
+  })
+
+})
\ No newline at end of file
diff --git a/src/views/NotFoundView.vue b/src/views/NotFoundView.vue
index 7637014..4e9d5ee 100644
--- a/src/views/NotFoundView.vue
+++ b/src/views/NotFoundView.vue
@@ -5,13 +5,13 @@
                 <div class="error-template text-center"> <!-- 'text-center' for centering text content -->
                     <h1>
                         Oops!</h1>
-                    <h2>
+                    <h2 data-cy="404-error">
                         404 Not Found</h2>
                     <div class="error-details">
                         Sorry, an error has occurred, Requested page not found!
                     </div>
                     <div class="error-actions">
-                        <Button1 button-text="Take Me Home" @click="home" />
+                        <Button1 data-cy="to-home" button-text="Take Me Home" @click="home" />
                     </div>
                 </div>
             </div>
-- 
GitLab