fix: Update tests for new component

This commit is contained in:
April Hall 2025-03-05 09:36:49 -05:00
parent ae9ab3668d
commit 57c7f35c09
No known key found for this signature in database
GPG Key ID: A49AC35CB186266C

View File

@ -9,7 +9,6 @@ test.describe('Profile Photo Update', () => {
let page: Page; let page: Page;
let fileInput: Locator; let fileInput: Locator;
let profileImage: Locator; let profileImage: Locator;
let submitButton: Locator;
test.beforeEach(async ({ browser }) => { test.beforeEach(async ({ browser }) => {
page = await browser.newPage(); page = await browser.newPage();
@ -19,7 +18,6 @@ test.describe('Profile Photo Update', () => {
await page.goto('/account', { timeout: 30000, waitUntil: 'domcontentloaded' }); await page.goto('/account', { timeout: 30000, waitUntil: 'domcontentloaded' });
// Initialize locators // Initialize locators
submitButton = page.getByRole('button', { name: 'Update Profile Photo' });
profileImage = page.locator('img#userimage'); profileImage = page.locator('img#userimage');
fileInput = page.locator('input[type="file"]'); fileInput = page.locator('input[type="file"]');
}); });
@ -32,7 +30,8 @@ test.describe('Profile Photo Update', () => {
// Upload the new image // Upload the new image
await fileInput.setInputFiles(['./static/freakybear.jpg']); await fileInput.setInputFiles(['./static/freakybear.jpg']);
await submitButton.click(); await page.waitForTimeout(500);
await page.getByTestId('crop').click();
// Wait for upload to complete // Wait for upload to complete
const response = await page.waitForResponse((response) => response.request().method() === 'POST', { timeout: 30000 }); const response = await page.waitForResponse((response) => response.request().method() === 'POST', { timeout: 30000 });
@ -50,11 +49,11 @@ test.describe('Profile Photo Update', () => {
// Upload the new image // Upload the new image
await fileInput.setInputFiles(['./README.md']); await fileInput.setInputFiles(['./README.md']);
await submitButton.click(); await page.waitForTimeout(500);
// Wait for upload to complete // Check for error
const response = await page.waitForResponse((response) => response.request().method() === 'POST', { timeout: 30000 }); const errorMessageLocator = page.locator(`.text-sm.text-red-500:has-text("Please upload a valid image.")`);
expect(response.status()).toBe(500); await expect(errorMessageLocator).toBeVisible();
// Make sure the src is the same as the original // Make sure the src is the same as the original
expect(await getImgSrc(profileImage)).toEqual(initalSrc); expect(await getImgSrc(profileImage)).toEqual(initalSrc);