-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
2,574 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,40 @@ | ||
name: Run Tests | ||
|
||
on: | ||
push: | ||
branches: [ci/cd] | ||
pull_request: | ||
branches: [ci/cd] | ||
|
||
env: | ||
MONGODB_URI: ${{ secrets.MONGODB_URI }} | ||
JWT_SECRET: ${{ secrets.JWT_SECRET }} | ||
DB_TYPE: ${{ secrets.DB_TYPE }} | ||
HOST_NAME: ${{ secrets.HOST_NAME }} | ||
DOCKER_DB_HOST_NAME: ${{ secrets.DOCKER_DB_HOST_NAME }} | ||
DB_NAME: ${{ secrets.DB_NAME }} | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Step 1: Checkout Code | ||
- name: Checkout Code | ||
uses: actions/checkout@v2 | ||
|
||
# Step 2: Install and Test Client | ||
- name: Install and Test Client | ||
working-directory: ./client | ||
run: | | ||
yarn install # Install dependencies using Yarn | ||
yarn install | ||
yarn test # Run unit tests with Yarn | ||
# Step 3: Install and Test Server | ||
- name: Install and Test Server | ||
working-directory: ./server | ||
run: | | ||
yarn install # Install dependencies using Yarn | ||
yarn install | ||
export MONGODB_URI=$MONGODB_URI | ||
export JWT_SECRET=$JWT_SECRET | ||
export DB_TYPE=$DB_TYPE | ||
export HOST_NAME=$HOST_NAME | ||
export DOCKER_DB_HOST_NAME=$DOCKER_DB_HOST_NAME | ||
export DB_NAME=$DB_NAME | ||
yarn test # Run unit tests with Yarn | ||
yarn test # Run unit tests with Yarn | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Builder, By, until } from 'selenium-webdriver'; | ||
import { Key } from 'selenium-webdriver'; | ||
|
||
describe('Login Page', () => { | ||
let driver: any; | ||
|
||
beforeAll(async () => { | ||
driver = await new Builder().forBrowser('chrome').build(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await driver.quit(); | ||
}); | ||
|
||
it('should login successfully with valid credentials', async () => { | ||
await driver.get('http://localhost:5173/login'); | ||
|
||
await driver.wait(until.elementLocated(By.id('email')), 5000); | ||
const emailInput = await driver.findElement(By.id('email')); | ||
await emailInput.sendKeys('testuser@example.com'); | ||
|
||
const passwordInput = await driver.findElement(By.id('password')); | ||
await passwordInput.sendKeys('password123'); | ||
|
||
const loginButton = await driver.findElement(By.css('button[type="submit"]')); | ||
await loginButton.click(); | ||
|
||
await driver.wait(until.elementLocated(By.css('h1')), 5000); | ||
const currentUrl = await driver.getCurrentUrl(); | ||
expect(currentUrl).toBe('http://localhost:5173/dashboard'); | ||
}); | ||
|
||
it('should display error message with invalid credentials', async () => { | ||
await driver.get('http://localhost:5173/login'); | ||
|
||
await driver.wait(until.elementLocated(By.id('email')), 5000); | ||
const emailInput = await driver.findElement(By.id('email')); | ||
await emailInput.sendKeys('invaliduser@example.com'); | ||
|
||
const passwordInput = await driver.findElement(By.id('password')); | ||
await passwordInput.sendKeys('wrongpassword'); | ||
|
||
const loginButton = await driver.findElement(By.css('button[type="submit"]')); | ||
await loginButton.click(); | ||
|
||
await driver.wait(until.elementLocated(By.css('.error-message')), 5000); // Update with your error element's class | ||
const errorMessage = await driver.findElement(By.css('.error-message')).getText(); | ||
expect(errorMessage).toBe('Invalid email or password'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Builder, By, until } from 'selenium-webdriver'; | ||
import Swal from 'sweetalert2'; | ||
|
||
describe('Logout Functionality', () => { | ||
let driver: any; | ||
|
||
beforeAll(async () => { | ||
driver = await new Builder().forBrowser('chrome').build(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await driver.quit(); | ||
}); | ||
|
||
it('should show a logout confirmation and logout the user', async () => { | ||
// Simulate logged-in state | ||
await driver.get('http://localhost:5173/'); | ||
const userProfileButton = await driver.findElement(By.css('.sidebar__logo')); | ||
await userProfileButton.click(); | ||
|
||
// Click on the logout button | ||
const logoutButton = await driver.findElement(By.css('button.logout')); | ||
await logoutButton.click(); | ||
|
||
// Simulate the confirmation dialog (you can customize this part based on your Swal implementation) | ||
const confirmButton = await driver.findElement(By.css('.swal2-confirm')); | ||
await confirmButton.click(); | ||
|
||
// Verify redirection to login page after logout | ||
await driver.wait(until.urlContains('/login'), 5000); | ||
const currentUrl = await driver.getCurrentUrl(); | ||
expect(currentUrl).toBe('http://localhost:5173/login'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Builder, By, until } from 'selenium-webdriver'; | ||
|
||
describe('Navbar Navigation', () => { | ||
let driver: any; | ||
|
||
beforeAll(async () => { | ||
driver = await new Builder().forBrowser('chrome').build(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await driver.quit(); | ||
}); | ||
|
||
it('should navigate to login page', async () => { | ||
await driver.get('http://localhost:5173/'); | ||
|
||
const loginLink = await driver.findElement(By.linkText('Connexion')); | ||
await loginLink.click(); | ||
|
||
await driver.wait(until.urlContains('/login'), 5000); | ||
const currentUrl = await driver.getCurrentUrl(); | ||
expect(currentUrl).toBe('http://localhost:5173/login'); | ||
}); | ||
|
||
it('should navigate to signup page', async () => { | ||
await driver.get('http://localhost:5173/'); | ||
|
||
const signupLink = await driver.findElement(By.linkText('S’inscrire')); | ||
await signupLink.click(); | ||
|
||
await driver.wait(until.urlContains('/signup'), 5000); | ||
const currentUrl = await driver.getCurrentUrl(); | ||
expect(currentUrl).toBe('http://localhost:5173/signup'); | ||
}); | ||
|
||
it('should navigate to evaluation page when user is not logged in', async () => { | ||
await driver.get('http://localhost:5173/'); | ||
|
||
const evaluationLink = await driver.findElement(By.linkText('Évaluation')); | ||
await evaluationLink.click(); | ||
|
||
await driver.wait(until.urlContains('/evaluation'), 5000); | ||
const currentUrl = await driver.getCurrentUrl(); | ||
expect(currentUrl).toBe('http://localhost:5173/evaluation'); | ||
}); | ||
|
||
it('should navigate to profile page when user is logged in', async () => { | ||
await driver.get('http://localhost:5173/'); | ||
|
||
const user = { role: 'ADMIN' }; // Simulate a logged-in user | ||
const userProfileLink = await driver.findElement(By.linkText(user.role.toLowerCase())); | ||
await userProfileLink.click(); | ||
|
||
await driver.wait(until.urlContains(`/${user.role.toLowerCase()}/profile`), 5000); | ||
const currentUrl = await driver.getCurrentUrl(); | ||
expect(currentUrl).toBe(`http://localhost:5173/${user.role.toLowerCase()}/profile`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Builder, By, until } from 'selenium-webdriver'; | ||
|
||
describe('Show Password Functionality', () => { | ||
let driver: any; | ||
|
||
beforeAll(async () => { | ||
driver = await new Builder().forBrowser('chrome').build(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await driver.quit(); | ||
}); | ||
|
||
it('should toggle password visibility when clicked', async () => { | ||
await driver.get('http://localhost:3000/login'); | ||
|
||
await driver.wait(until.elementLocated(By.id('password')), 5000); | ||
const passwordInput = await driver.findElement(By.id('password')); | ||
|
||
let inputType = await passwordInput.getAttribute('type'); | ||
expect(inputType).toBe('password'); | ||
|
||
const showPasswordButton = await driver.findElement(By.css('button[type="button"]')); | ||
await showPasswordButton.click(); | ||
|
||
inputType = await passwordInput.getAttribute('type'); | ||
expect(inputType).toBe('text'); // Password should be visible after clicking | ||
|
||
await showPasswordButton.click(); // Toggle back | ||
|
||
inputType = await passwordInput.getAttribute('type'); | ||
expect(inputType).toBe('password'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.