Skip to content

Commit

Permalink
Merge pull request #6 from AgataBialoskorska/cypress-tests-update
Browse files Browse the repository at this point in the history
Cypress tests update
  • Loading branch information
AgataBialoskorska authored Mar 16, 2024
2 parents ddcc275 + 0554349 commit c37f69d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
setupNodeEvents(on, config) {
console.log(config)
return {
target: 'http://localhost:5173'
target: 'http://localhost:5173/#/'
}
},
},
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/hangman.cy.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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'
)
})

Expand Down
18 changes: 9 additions & 9 deletions cypress/e2e/router.cy.js
Original file line number Diff line number Diff line change
@@ -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/#/')
})
})
})
2 changes: 1 addition & 1 deletion cypress/e2e/seo.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const router = createRouter({
},
{
path: '/:pathMatch(.*)*',
redirect: '/'
name: 'home',
component: ViewHome
}
]
})
Expand All @@ -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()
})

Expand Down

0 comments on commit c37f69d

Please sign in to comment.