From 1deabe7ca0740c97fd4612c22a76563ad2af1e09 Mon Sep 17 00:00:00 2001 From: AgataBialoskorska Date: Sat, 16 Mar 2024 01:00:50 +0100 Subject: [PATCH 1/4] adjust target for cypress --- cypress.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress.config.js b/cypress.config.js index 03f3b1a..97453b1 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -5,7 +5,7 @@ export default defineConfig({ setupNodeEvents(on, config) { console.log(config) return { - target: 'http://localhost:5173' + target: 'http://localhost:5173/#/' } }, }, From 4aeb0c4b12aa39d2744fe49a8d10e62fd9b4e98e Mon Sep 17 00:00:00 2001 From: AgataBialoskorska Date: Sat, 16 Mar 2024 01:01:59 +0100 Subject: [PATCH 2/4] redirect wrong path to home page --- src/router/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/router/index.js b/src/router/index.js index a4eb265..5fff082 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -25,7 +25,8 @@ const router = createRouter({ }, { path: '/:pathMatch(.*)*', - redirect: '/' + name: 'home', + component: ViewHome } ] }) @@ -36,6 +37,13 @@ router.beforeEach((to, from, next) => { } else { document.title = defaultTitle } + + const defaultUrl = '/' + if (to.path === '/' || to.path === '/more' || to.path === '/hangman') { + next() + } else { + next(defaultUrl) + } next() }) From ca86e0d4d47cfb94414ee30aaeba3d022557b0ac Mon Sep 17 00:00:00 2001 From: AgataBialoskorska Date: Sat, 16 Mar 2024 01:02:50 +0100 Subject: [PATCH 3/4] update e2e-prod script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 779ccbc..6be26ee 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "cypress": "cypress open", "e2e-open": "start-server-and-test dev http://localhost:5173 \"cypress open --e2e\"", "e2e-run": "start-server-and-test dev http://localhost:5173 \"cypress run --e2e\"", - "e2e-prod": "vite build && npm run e2e-run" + "e2e-prod": "vite build && start-server-and-test preview http://localhost:5173 \"cypress run --e2e\"" }, "dependencies": { "axios": "1.6.7", From 055434927169ae88091ab4768ee8151959960aa1 Mon Sep 17 00:00:00 2001 From: AgataBialoskorska Date: Sat, 16 Mar 2024 01:04:08 +0100 Subject: [PATCH 4/4] adjust tests to new router --- cypress/e2e/hangman.cy.js | 6 +++--- cypress/e2e/router.cy.js | 18 +++++++++--------- cypress/e2e/seo.cy.js | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cypress/e2e/hangman.cy.js b/cypress/e2e/hangman.cy.js index e10bff0..e0f13dd 100644 --- a/cypress/e2e/hangman.cy.js +++ b/cypress/e2e/hangman.cy.js @@ -1,7 +1,7 @@ /* eslint-disable cypress/unsafe-to-chain-command */ describe('GameHangman', () => { beforeEach(() => { - cy.visit('http://localhost:5173/hangman') + cy.visit('http://localhost:5173/#/hangman') }) it('Should display "Hangman Game" header', () => { @@ -34,14 +34,14 @@ describe('GameHangman', () => { it('Should navigate back when the back button is clicked', () => { cy.get('.goBack').click() - cy.url().should('eq', 'http://localhost:5173/more') + cy.url().should('eq', 'http://localhost:5173/#/more') }) it('Should navigate to the GitHub repository when the GitHub link is clicked', () => { cy.get('.gh').should( 'have.attr', 'href', - 'https://github.com/AgataBialoskorska/vuePortfolio/blob/master/src/components/GameHangman.vue' + 'https://github.com/AgataBialoskorska/vueProject/blob/master/src/components/GameHangman.vue' ) }) diff --git a/cypress/e2e/router.cy.js b/cypress/e2e/router.cy.js index 1379c05..29d0d9b 100644 --- a/cypress/e2e/router.cy.js +++ b/cypress/e2e/router.cy.js @@ -1,27 +1,27 @@ describe('Router', () => { beforeEach(() => { - cy.visit('http://localhost:5173/') + cy.visit('http://localhost:5173/#/') }) describe('Website Navigation', () => { it('Should load the main page correctly', () => { - cy.url().should('eq', 'http://localhost:5173/') + cy.url().should('eq', 'http://localhost:5173/#/') }) it('Should load the "More" page correctly', () => { - cy.get('a[href="/more"]').click() - cy.url().should('include', '/more') + cy.get('a[href="#/more"]').click() + cy.url().should('include', 'more') }) it('Should load the "Hangman" game correctly', () => { - cy.visit('http://localhost:5173/more') - cy.get('a[href="/hangman"]').click() - cy.url().should('include', '/hangman') + cy.visit('http://localhost:5173/#/more') + cy.get('a[href="#/hangman"]').click() + cy.url().should('include', 'hangman') }) it('Should redirect to the main page if an invalid URL is entered', () => { - cy.visit('http://localhost:5173/random') - cy.url().should('eq', 'http://localhost:5173/') + cy.visit('http://localhost:5173/#/random') + cy.url().should('eq', 'http://localhost:5173/#/') }) }) }) diff --git a/cypress/e2e/seo.cy.js b/cypress/e2e/seo.cy.js index f0df290..e0d33e9 100644 --- a/cypress/e2e/seo.cy.js +++ b/cypress/e2e/seo.cy.js @@ -4,7 +4,7 @@ describe('SEO Tests', () => { }) it('Should have a descriptive title', () => { - cy.title().should('eq', 'Agata B.') + cy.title().should('include', 'Agata Białoskórska') }) it('Should have meta description tag', () => {