Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/upup/e2e/fixtures/baseTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test as baseTest, expect } from '@playwright/test';
import { UploaderPage } from '../pages/UploaderPage';

type UpupPageObjects = {
uploaderPage: UploaderPage;
};

export const test = baseTest.extend<UpupPageObjects>({
uploaderPage: async ({ page }, use) => {
const uploaderPage = new UploaderPage(page);
await use(uploaderPage);
},
});

export { expect };
12 changes: 12 additions & 0 deletions packages/upup/e2e/locators/UploaderLocators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const UploaderLocators = {
fileInput: 'input[type="file"]',
myDeviceBtn: 'My Device',
addMoreBtn: 'Add More',
removeAllFilesBtn: 'Remove all files',
removeFileBtn: 'Remove file',
uploaderRegion: 'Add your documents here, you',

messages: {
dropInstructions: 'Add your documents here, you can upload up to 10 files max',
},
} as const;
48 changes: 48 additions & 0 deletions packages/upup/e2e/pages/UploaderPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Locator, Page } from '@playwright/test';
import { UploaderLocators as locators } from '../locators/UploaderLocators';

export class UploaderPage {
readonly page: Page;
readonly fileInput: Locator;
readonly myDeviceBtn: Locator;
readonly addMoreBtn: Locator;
readonly removeAllFilesBtn: Locator;
readonly uploaderRegion: Locator;

constructor(page: Page) {
this.page = page;
this.fileInput = page.locator(locators.fileInput);
this.myDeviceBtn = page.getByRole('button', { name: locators.myDeviceBtn });
this.addMoreBtn = page.getByRole('button', { name: locators.addMoreBtn });
this.removeAllFilesBtn = page.getByRole('button', { name: locators.removeAllFilesBtn });
this.uploaderRegion = page.getByLabel(locators.uploaderRegion);
}

async goTo(): Promise<void> {
await this.page.goto(
'http://localhost:6007/iframe.html?id=upupuploader--uploader-with-button&viewMode=story'
);
await this.page.waitForLoadState('domcontentloaded');
await this.uploaderRegion.waitFor({ state: 'visible' });
}

async uploadFiles(files: string[]): Promise<void> {
await this.fileInput.setInputFiles(files);
}

async clickUpload(fileCount: number): Promise<void> {
const uploadBtn = this.page.getByRole('button', {
name: `Upload ${fileCount} file${fileCount > 1 ? 's' : ''}`,
});
await uploadBtn.click();
}

async addMoreFiles(files: string[]): Promise<void> {
await this.addMoreBtn.click();
await this.fileInput.setInputFiles(files);
}

async removeAllFiles(): Promise<void> {
await this.removeAllFilesBtn.click();
}
}
38 changes: 38 additions & 0 deletions packages/upup/e2e/specs/upload.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { test, expect } from '../fixtures/baseTest';
import { UploaderLocators as locators } from '../locators/UploaderLocators';

test.describe('Upup Uploader Component - Full Validation', () => {
test.beforeEach(async ({ uploaderPage }) => {
await uploaderPage.goTo();
});

test('should display initial upload instructions', async ({ uploaderPage }) => {
await expect(uploaderPage.uploaderRegion).toContainText(locators.messages.dropInstructions);
});

test('should handle selection of 10 files', async ({ uploaderPage }) => {
const files = Array.from({ length: 10 }, (_, i) => `test-files/image${i + 1}.jpg`);

await uploaderPage.uploadFiles(files);

await expect(uploaderPage.uploaderRegion).toContainText('10 files selected');
});

test('should allow removing all files to reset state', async ({ uploaderPage }) => {
await uploaderPage.uploadFiles(['test-files/image1.jpg', 'test-files/image2.jpg']);
await uploaderPage.removeAllFiles();

await expect(uploaderPage.uploaderRegion).toContainText(locators.messages.dropInstructions);
});

test('BUG: upload button should disable after clicking', async ({ uploaderPage, page }) => {
test.fail(true, 'Known issue: Upload button remains visible and active after click');

await uploaderPage.uploadFiles(['test-files/image1.jpg']);
const uploadBtn = page.getByRole('button', { name: 'Upload 1 file' });

await uploadBtn.click();

await expect(uploadBtn).not.toBeVisible({ timeout: 5000 });
});
});
5 changes: 3 additions & 2 deletions packages/upup/src/frontend/components/FileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export default memo(function FileList() {
classNames.fileListFooter,
)}
>
<ShouldRender if={uploadStatus !== UploadStatus.SUCCESSFUL}>
{/* FIX: Hide upload button when status is SUCCESSFUL or FAILED */}
<ShouldRender if={uploadStatus !== UploadStatus.SUCCESSFUL && uploadStatus !== UploadStatus.FAILED}>
<button
className={cn(
'upup-disabled:animate-pulse upup-ml-auto upup-rounded-full upup-bg-blue-600 upup-px-4 upup-py-2 upup-text-sm upup-font-medium upup-text-white',
Expand Down Expand Up @@ -133,4 +134,4 @@ export default memo(function FileList() {
</div>
</div>
)
})
})
Binary file added packages/upup/test-files/image1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/upup/test-files/image10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/upup/test-files/image2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/upup/test-files/image3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/upup/test-files/image4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/upup/test-files/image5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/upup/test-files/image6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/upup/test-files/image7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/upup/test-files/image8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/upup/test-files/image9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.