Skip to content

Commit

Permalink
feat: adding some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebrsk committed Sep 14, 2024
1 parent e1f9f9e commit 9e31053
Show file tree
Hide file tree
Showing 19 changed files with 1,893 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

__snapshots__
node_modules
dist
dist-ssr
Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
- [ ] Implement game recommendations based on user activity
- [ ] Create a personalized dashboard for logged-in users
- [ ] Testing & QA
- [ ] Write unit tests for all components
- [x] Write unit tests for all components
- [ ] Write unit tests for all pages
- [ ] Set up end-to-end testing with Cypress or Playwright
- [ ] Perform accessibility testing
- [ ] Deployment
Expand Down
27 changes: 27 additions & 0 deletions cypress.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { defineConfig } from 'cypress'

export default defineConfig({
projectId: 'j2456e',
e2e: {
baseUrl: 'http://localhost:5173',
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'cypress/support/e2e.ts',
viewportWidth: 1280,
viewportHeight: 720,
experimentalFetchPolyfill: true,
retries: {
runMode: 2,
openMode: 0,
},
},
env: {
API_URL: 'http://localhost:8000',
},
component: {
devServer: {
framework: 'react',
bundler: 'webpack',
},
},
nodeOptions: ['--loader', 'ts-node/esm'],
})
Binary file added cypress/downloads/downloads.htm
Binary file not shown.
24 changes: 24 additions & 0 deletions cypress/e2e/login.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// TODO: Change when implemented.

describe('Login Page', () => {
it('should load the login page and submit form', () => {
cy.visit('/login')

cy.get('input[placeholder="Type your nickname or email..."]').type(
'test@example.com',
)
cy.get('input[placeholder="Type your password..."]').type('password')

cy.get('button').contains('Login').click()

cy.log('Form submitted')
})

it('should trigger social logins', () => {
cy.visit('/login')

cy.get('button').contains('Google').click()
cy.get('button').contains('Facebook').click()
cy.get('button').contains('Twitter').click()
})
})
9 changes: 9 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const apiUrl = Cypress.env('API_URL')

Cypress.Commands.add('login', (email: string, password: string) => {
cy.request({
method: 'POST',
url: `${apiUrl}/auth/login`,
body: { email, password },
}).then((resp) => resp.body.data.message)
})
31 changes: 31 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ***********************************************************
// This example support/e2e.ts is processed and loaded automatically
// before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the 'supportFile'
// configuration option.
//
// More info: https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')

// Set global configurations or behaviors here

// Example: Ignore uncaught exceptions that aren't relevant to the test
Cypress.on('uncaught:exception', (err, runnable) => {
// Prevent Cypress from failing the test on uncaught exceptions
// Example: Ignore errors caused by third-party libraries or ads
console.log('Caught exception: ', err)

// return false to prevent the test from failing
return false
})
11 changes: 11 additions & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare namespace Cypress {
interface Chainable {
/**
* Custom command to log in a user.
*
* @param email - The email of the user
* @param password - The password of the user
*/
login(email: string, password: string): Chainable<void>
}
}
Loading

0 comments on commit 9e31053

Please sign in to comment.