mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 16:56:14 -04:00
feat(test): added e2e tests
This commit is contained in:
parent
ebfdb64fde
commit
ec7cb9351c
11 changed files with 245 additions and 5 deletions
|
@ -0,0 +1,48 @@
|
|||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('Tool - OTP code generator', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/otp-generator');
|
||||
});
|
||||
|
||||
test('Has title', async ({ page }) => {
|
||||
await expect(page).toHaveTitle('OTP code generator - IT Tools');
|
||||
});
|
||||
|
||||
test('Secret hexa value is computed from provided secret', async ({ page }) => {
|
||||
await page.getByPlaceholder('Paste your TOTP secret...').fill('ITTOOLS');
|
||||
|
||||
const secretInHex = await page.getByPlaceholder('Secret in hex will be displayed here').inputValue();
|
||||
|
||||
expect(secretInHex).toEqual('44e6e72e02');
|
||||
});
|
||||
|
||||
test('OTP a generated from the provided secret', async ({ page }) => {
|
||||
page.evaluate(() => {
|
||||
Date.now = () => 1609477200000; //Jan 1, 2021
|
||||
});
|
||||
|
||||
await page.getByPlaceholder('Paste your TOTP secret...').fill('ITTOOLS');
|
||||
|
||||
const previousOtp = await page.getByTestId('previous-otp').innerText();
|
||||
const currentOtp = await page.getByTestId('current-otp').innerText();
|
||||
const nextOtp = await page.getByTestId('next-otp').innerText();
|
||||
|
||||
expect(previousOtp.trim()).toEqual('028034');
|
||||
expect(currentOtp.trim()).toEqual('162195');
|
||||
expect(nextOtp.trim()).toEqual('452815');
|
||||
});
|
||||
|
||||
test('You can generate a new random secret', async ({ page }) => {
|
||||
const initialSecret = await page.getByPlaceholder('Paste your TOTP secret...').inputValue();
|
||||
await page
|
||||
.locator('div')
|
||||
.filter({ hasText: /^Secret$/ })
|
||||
.getByRole('button')
|
||||
.click();
|
||||
|
||||
const newSecret = await page.getByPlaceholder('Paste your TOTP secret...').inputValue();
|
||||
|
||||
expect(newSecret).not.toEqual(initialSecret);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue