diff --git a/ui/tests/e2e/auth/authentication.spec.ts b/ui/tests/e2e/auth/authentication.spec.ts new file mode 100644 index 0000000000..a90f343dbf --- /dev/null +++ b/ui/tests/e2e/auth/authentication.spec.ts @@ -0,0 +1,53 @@ +import { test, expect, request } from '@playwright/test'; + +// Test credentials +const testEmail = 'test@gmail.com'; +const testPassword = 'Testt@123456'; + +test.beforeAll(async () => { + const apiContext = await request.newContext(); + + await apiContext.post(`${process.env.API_BASE_URL}users`, { + headers: { + 'Content-Type': 'application/vnd.api+json', + 'Accept': 'application/vnd.api+json', + }, + data: { + data: { + type: 'users', + attributes: { + name: 'testuser', + email: testEmail, + password: testPassword, + company_name: 'test', + }, + }, + }, + }); + + await apiContext.dispose(); +}); + +test('should show error for invalid credentials', async ({ page }) => { + await page.goto('/sign-in'); + + await page.fill('input[name="email"]', 'wrong@gmail.com'); + await page.fill('input[name="password"]', 'WrongPassword123'); + await page.getByRole('button', { name: /log in/i }).click(); + + await expect(page.getByText(/Invalid email or password/i)).toBeVisible(); +}); + +test('should sign in successfully', async ({ page }) => { + // Go to login page + await page.goto('/sign-in'); + + // Fill login form + await page.fill('input[name="email"]', testEmail); + await page.fill('input[name="password"]', testPassword); + + // Submit the form + await page.getByRole('button', { name: /log in/i }).click(); + await page.waitForURL('/', { timeout: 15000 }); + await expect(page).toHaveURL('/'); +});