Merge pull request 'tests(e2e): Test nested file upload' (#2) from fnetx/playwright into upload_with_path_structure

Reviewed-on: https://codeberg.org/davrot/forgejo/pulls/2
This commit is contained in:
David Rotermund 2025-02-20 14:59:50 +00:00
commit 7f7b35b67a
3 changed files with 51 additions and 69 deletions

View file

@ -48,6 +48,10 @@ func DeclareGitRepos(t *testing.T) func() {
CommitMsg: "Another commit which mentions @user1 in the title\nand @user2 in the text",
},
}),
newRepo(t, 2, "file-uploads", []FileChanges{{
Filename: "README.md",
Versions: []string{"# File upload test\nUse this repo to test various file upload features in new branches."},
}}),
// add your repo declarations here
}
@ -68,7 +72,7 @@ func newRepo(t *testing.T, userID int64, repoName string, fileChanges []FileChan
for _, file := range fileChanges {
for i, version := range file.Versions {
operation := "update"
if i == 0 {
if i == 0 && file.Filename != "README.md" {
operation = "create"
}

View file

@ -1,68 +0,0 @@
// @watch start
// templates/user/auth/**
// web_src/js/features/user-**
// modules/{user,auth}/**
// @watch end
/// <reference lib="dom"/>
import { expect } from '@playwright/test';
import { test } from './utils_e2e.ts';
test('drap and drop upload test', async ({ page }, workerInfo) => {
page.setDefaultTimeout(0);
// Create user
const response = await page.goto('/user/sign_up');
expect(response?.status()).toBe(200); // Status OK
await page.fill('input[name=user_name]', `e2e-test-${workerInfo.workerIndex}`);
await page.fill('input[name=email]', `e2e-test-${workerInfo.workerIndex}@test.com`);
await page.fill('input[name=password]', 'test123test123');
await page.fill('input[name=retype]', 'test123test123');
await page.click('form button.ui.primary.button:visible');
// It looks like that I am automatically logged in if I create the account
// // Log-in into account
// const response2 = await page.goto('/user/login');
// expect(response2?.status()).toBe(200); // Status OK
// await page.fill('input[name=user_name]', `e2e-test-${workerInfo.workerIndex}`);
// await page.fill('input[name=password]', 'test123test123');
// await page.getByRole('button', { name: 'Sign in' }).click();
// Create a new repos
const response3 = await page.goto('/repo/create');
expect(response3?.status()).toBe(200); // Status OK
await page.fill('input[name=repo_name]', 'e2e-test');
await page.getByRole('button', { name: 'Create repository' }).click();
// Go into the repo
const response4 = await page.goto(`/e2e-test-${workerInfo.workerIndex}/e2e-test/_upload/master`);
expect(response4?.status()).toBe(200); // Status OK
// Find the drop zone
const dropzone = page.getByRole('button', { name: 'Drop files or click here to upload.' });
// Create file1.txt in the current directory
const buffer = Buffer.from('Test File 1', 'utf-8');
// Create the DataTransfer and File
const dataTransfer = await page.evaluateHandle((data) => {
const dt = new DataTransfer();
const file = new File([data], 'dir2/file_2.txt', { type: 'text/plain' });
dt.items.add(file);
return dt;
}, buffer);
// Drop the file
await dropzone.dispatchEvent('drop', { dataTransfer });
// Commit the file
await page.getByRole('button', { name: 'Commit changes' }).click();
// Go into the repo
const response6 = await page.goto(`/e2e-test-${workerInfo.workerIndex}/e2e-test/src/branch/master/dir2`);
expect(response6?.status()).toBe(200); // Status OK
await expect(page.getByRole('link', { name: 'file_2.txt' })).toBeVisible();
});

View file

@ -0,0 +1,46 @@
// @watch start
// templates/repo/editor/**
// web_src/js/features/common-global.js
// routers/web/web.go
// services/repository/files/upload.go
// @watch end
/// <reference lib="dom"/>
import { expect } from '@playwright/test';
import { test, dynamic_id, save_visual } from './utils_e2e.ts';
test.use({user: 'user2'});
test('drap and drop upload', async ({ page }, workerInfo) => {
const response = await page.goto(`/user2/file-uploads/_upload/main/`);
expect(response?.status()).toBe(200); // Status OK
const testID = dynamic_id();
const dropzone = page.getByRole('button', { name: 'Drop files or click here to upload.' });
// create the virtual files
const dataTransfer = await page.evaluateHandle(() => {
const dt = new DataTransfer();
// add items in different folders
dt.items.add(new File(["Filecontent"], 'dir1/file1.txt', { type: 'text/plain' }));
dt.items.add(new File(["Another file's content"], 'double/nested/file.txt', { type: 'text/plain' }));
dt.items.add(new File(["Root file"], 'root_file.txt', { type: 'text/plain' }));
return dt;
});
// and drop them to the upload area
await dropzone.dispatchEvent('drop', { dataTransfer });
await page.getByText('new branch').click();
await save_visual(page);
await page.getByRole('textbox', { name: 'Name the new branch for this' }).fill(testID);
await page.getByRole('button', { name: 'Propose file change' }).click();
// check that nested file structure is preserved
await expect(page.getByRole('link', { name: 'dir1/file1.txt' })).toBeVisible();
await expect(page.getByRole('link', { name: 'double/nested/file.txt' })).toBeVisible();
await expect(page.locator('#diff-file-boxes').getByRole('link', { name: 'root_file.txt', exact: true })).toBeVisible();
await save_visual(page);
});