forgejo/tests/e2e/release.test.e2e.ts

92 lines
4.5 KiB
TypeScript
Raw Normal View History

// @watch start
// models/repo/attachment.go
// modules/structs/attachment.go
// routers/web/repo/**
// services/attachment/**
// services/release/**
// templates/repo/release/**
// web_src/js/features/repo-release.js
// @watch end
2024-08-14 15:34:36 -06:00
import {expect} from '@playwright/test';
import {save_visual, test} from './utils_e2e.ts';
2024-11-08 09:55:54 +01:00
import {validate_form} from './shared/forms.ts';
2023-09-15 18:20:16 +02:00
test.use({user: 'user2'});
2023-09-15 18:20:16 +02:00
test.describe.configure({
timeout: 30000,
});
test('External Release Attachments', async ({page, isMobile}) => {
2023-09-15 18:20:16 +02:00
test.skip(isMobile);
// Click "New Release"
await page.goto('/user2/repo2/releases');
await page.click('.button.small.primary');
// Fill out form and create new release
await expect(page).toHaveURL('/user2/repo2/releases/new');
await validate_form({page}, 'fieldset');
templates: release: Add JS to set default release title to tag name (#6645) Closes #6485 Adds a bit of javascript in the template responsible for the "create release" page When typing a name in the "tag name" field, the content will be automatically set in the "Title" field as a placeholder. This way, you can type a version number (ex: `v5.0.2`), and the title will default to it (`v5.0.2` in this case) ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [x] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [x] I do not want this change to show in the release notes. - [ ] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6645 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Litchi Pi <litchi.pi@proton.me> Co-committed-by: Litchi Pi <litchi.pi@proton.me>
2025-02-02 12:00:52 +00:00
const textarea = page.locator('input[name=tag_name]');
await textarea.pressSequentially('2.0');
await expect(page.locator('input[name=title]')).toHaveValue('2.0');
2023-09-15 18:20:16 +02:00
await page.click('#add-external-link');
await page.click('#add-external-link');
await page.fill('input[name=attachment-new-name-2]', 'Test');
await page.fill('input[name=attachment-new-exturl-2]', 'https://forgejo.org/');
await page.click('.remove-rel-attach');
await save_visual(page);
2023-09-15 18:20:16 +02:00
await page.click('.button.small.primary');
// Validate release page and click edit
await expect(page).toHaveURL('/user2/repo2/releases');
2023-09-15 18:20:16 +02:00
await expect(page.locator('.download[open] li')).toHaveCount(3);
feat(ui): add MIME types for generated archives (#6959) * add MIME types `application/zip` and `application/gzip` to anchors of automatically generated archives. * add testing for that, and also for https://codeberg.org/forgejo/forgejo/pulls/2899 ## Why Many instances are struggling with crawlers that are fetching these links, causing archives to be generated. The content is actually never downloaded. [MDN describes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#type) this attribute as a "hint". So this hint can help a client to decide against fetching the href contents. I don't believe this change will actually improve the situation, however, I think this attribute is nice to have. ## MIME types It was a bit difficult to determine which are the right ones for this use case. [IANA lists](https://www.iana.org/assignments/media-types/media-types.xhtml) both `application/zip` and `application/gzip`. `application/zip` refers to [RFC6713](https://datatracker.ietf.org/doc/html/rfc6713) and `application/gzip` doesn't refer to an RFC directly. It also has [detailed information](https://www.iana.org/assignments/media-types/application/zip) about zip. [gzip is less detailed](https://www.iana.org/assignments/media-types/application/gzip). * [`application/zip`](https://www.iana.org/assignments/media-types/application/zip): > ZIP files are binary data and thus should be encoded for MIME mail transmission. This was written in 1993, but probably applies to the more modern web as well. * [`application/gzip`](https://datatracker.ietf.org/doc/rfc6713): > The 'application/gzip' media type describes a block of data that is compressed using gzip [RFC1952] compression. The data is a stream of bytes as described in RFC 1952. [RFC1952](https://datatracker.ietf.org/doc/rfc1952/) is a "GZIP file format specification", but there's a warning: "This RFC is not endorsed by the IETF and has no formal standing in the IETF standards process.". Anyway, I consider it as the right way to mark .tar.gz files too. Additional stuff that I read while researching: * https://stackoverflow.com/questions/2110269/add-mime-type-to-html-link Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6959 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-committed-by: 0ko <0ko@noreply.codeberg.org>
2025-02-16 12:59:28 +00:00
await expect(page.locator('.download[open] li:nth-of-type(1)')).toContainText('Source code (ZIP)');
feat(ui): add MIME types for generated archives (#6959) * add MIME types `application/zip` and `application/gzip` to anchors of automatically generated archives. * add testing for that, and also for https://codeberg.org/forgejo/forgejo/pulls/2899 ## Why Many instances are struggling with crawlers that are fetching these links, causing archives to be generated. The content is actually never downloaded. [MDN describes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#type) this attribute as a "hint". So this hint can help a client to decide against fetching the href contents. I don't believe this change will actually improve the situation, however, I think this attribute is nice to have. ## MIME types It was a bit difficult to determine which are the right ones for this use case. [IANA lists](https://www.iana.org/assignments/media-types/media-types.xhtml) both `application/zip` and `application/gzip`. `application/zip` refers to [RFC6713](https://datatracker.ietf.org/doc/html/rfc6713) and `application/gzip` doesn't refer to an RFC directly. It also has [detailed information](https://www.iana.org/assignments/media-types/application/zip) about zip. [gzip is less detailed](https://www.iana.org/assignments/media-types/application/gzip). * [`application/zip`](https://www.iana.org/assignments/media-types/application/zip): > ZIP files are binary data and thus should be encoded for MIME mail transmission. This was written in 1993, but probably applies to the more modern web as well. * [`application/gzip`](https://datatracker.ietf.org/doc/rfc6713): > The 'application/gzip' media type describes a block of data that is compressed using gzip [RFC1952] compression. The data is a stream of bytes as described in RFC 1952. [RFC1952](https://datatracker.ietf.org/doc/rfc1952/) is a "GZIP file format specification", but there's a warning: "This RFC is not endorsed by the IETF and has no formal standing in the IETF standards process.". Anyway, I consider it as the right way to mark .tar.gz files too. Additional stuff that I read while researching: * https://stackoverflow.com/questions/2110269/add-mime-type-to-html-link Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6959 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-committed-by: 0ko <0ko@noreply.codeberg.org>
2025-02-16 12:59:28 +00:00
await expect(page.locator('.download[open] li:nth-of-type(1) span[data-tooltip-content]')).toHaveAttribute('data-tooltip-content', 'This attachment is automatically generated.');
await expect(page.locator('.download[open] li:nth-of-type(1) a')).toHaveAttribute('href', '/user2/repo2/archive/2.0.zip');
feat(ui): add MIME types for generated archives (#6959) * add MIME types `application/zip` and `application/gzip` to anchors of automatically generated archives. * add testing for that, and also for https://codeberg.org/forgejo/forgejo/pulls/2899 ## Why Many instances are struggling with crawlers that are fetching these links, causing archives to be generated. The content is actually never downloaded. [MDN describes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#type) this attribute as a "hint". So this hint can help a client to decide against fetching the href contents. I don't believe this change will actually improve the situation, however, I think this attribute is nice to have. ## MIME types It was a bit difficult to determine which are the right ones for this use case. [IANA lists](https://www.iana.org/assignments/media-types/media-types.xhtml) both `application/zip` and `application/gzip`. `application/zip` refers to [RFC6713](https://datatracker.ietf.org/doc/html/rfc6713) and `application/gzip` doesn't refer to an RFC directly. It also has [detailed information](https://www.iana.org/assignments/media-types/application/zip) about zip. [gzip is less detailed](https://www.iana.org/assignments/media-types/application/gzip). * [`application/zip`](https://www.iana.org/assignments/media-types/application/zip): > ZIP files are binary data and thus should be encoded for MIME mail transmission. This was written in 1993, but probably applies to the more modern web as well. * [`application/gzip`](https://datatracker.ietf.org/doc/rfc6713): > The 'application/gzip' media type describes a block of data that is compressed using gzip [RFC1952] compression. The data is a stream of bytes as described in RFC 1952. [RFC1952](https://datatracker.ietf.org/doc/rfc1952/) is a "GZIP file format specification", but there's a warning: "This RFC is not endorsed by the IETF and has no formal standing in the IETF standards process.". Anyway, I consider it as the right way to mark .tar.gz files too. Additional stuff that I read while researching: * https://stackoverflow.com/questions/2110269/add-mime-type-to-html-link Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6959 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-committed-by: 0ko <0ko@noreply.codeberg.org>
2025-02-16 12:59:28 +00:00
await expect(page.locator('.download[open] li:nth-of-type(1) a')).toHaveAttribute('type', 'application/zip');
await expect(page.locator('.download[open] li:nth-of-type(2)')).toContainText('Source code (TAR.GZ)');
feat(ui): add MIME types for generated archives (#6959) * add MIME types `application/zip` and `application/gzip` to anchors of automatically generated archives. * add testing for that, and also for https://codeberg.org/forgejo/forgejo/pulls/2899 ## Why Many instances are struggling with crawlers that are fetching these links, causing archives to be generated. The content is actually never downloaded. [MDN describes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#type) this attribute as a "hint". So this hint can help a client to decide against fetching the href contents. I don't believe this change will actually improve the situation, however, I think this attribute is nice to have. ## MIME types It was a bit difficult to determine which are the right ones for this use case. [IANA lists](https://www.iana.org/assignments/media-types/media-types.xhtml) both `application/zip` and `application/gzip`. `application/zip` refers to [RFC6713](https://datatracker.ietf.org/doc/html/rfc6713) and `application/gzip` doesn't refer to an RFC directly. It also has [detailed information](https://www.iana.org/assignments/media-types/application/zip) about zip. [gzip is less detailed](https://www.iana.org/assignments/media-types/application/gzip). * [`application/zip`](https://www.iana.org/assignments/media-types/application/zip): > ZIP files are binary data and thus should be encoded for MIME mail transmission. This was written in 1993, but probably applies to the more modern web as well. * [`application/gzip`](https://datatracker.ietf.org/doc/rfc6713): > The 'application/gzip' media type describes a block of data that is compressed using gzip [RFC1952] compression. The data is a stream of bytes as described in RFC 1952. [RFC1952](https://datatracker.ietf.org/doc/rfc1952/) is a "GZIP file format specification", but there's a warning: "This RFC is not endorsed by the IETF and has no formal standing in the IETF standards process.". Anyway, I consider it as the right way to mark .tar.gz files too. Additional stuff that I read while researching: * https://stackoverflow.com/questions/2110269/add-mime-type-to-html-link Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6959 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-committed-by: 0ko <0ko@noreply.codeberg.org>
2025-02-16 12:59:28 +00:00
await expect(page.locator('.download[open] li:nth-of-type(2) span[data-tooltip-content]')).toHaveAttribute('data-tooltip-content', 'This attachment is automatically generated.');
await expect(page.locator('.download[open] li:nth-of-type(2) a')).toHaveAttribute('href', '/user2/repo2/archive/2.0.tar.gz');
feat(ui): add MIME types for generated archives (#6959) * add MIME types `application/zip` and `application/gzip` to anchors of automatically generated archives. * add testing for that, and also for https://codeberg.org/forgejo/forgejo/pulls/2899 ## Why Many instances are struggling with crawlers that are fetching these links, causing archives to be generated. The content is actually never downloaded. [MDN describes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#type) this attribute as a "hint". So this hint can help a client to decide against fetching the href contents. I don't believe this change will actually improve the situation, however, I think this attribute is nice to have. ## MIME types It was a bit difficult to determine which are the right ones for this use case. [IANA lists](https://www.iana.org/assignments/media-types/media-types.xhtml) both `application/zip` and `application/gzip`. `application/zip` refers to [RFC6713](https://datatracker.ietf.org/doc/html/rfc6713) and `application/gzip` doesn't refer to an RFC directly. It also has [detailed information](https://www.iana.org/assignments/media-types/application/zip) about zip. [gzip is less detailed](https://www.iana.org/assignments/media-types/application/gzip). * [`application/zip`](https://www.iana.org/assignments/media-types/application/zip): > ZIP files are binary data and thus should be encoded for MIME mail transmission. This was written in 1993, but probably applies to the more modern web as well. * [`application/gzip`](https://datatracker.ietf.org/doc/rfc6713): > The 'application/gzip' media type describes a block of data that is compressed using gzip [RFC1952] compression. The data is a stream of bytes as described in RFC 1952. [RFC1952](https://datatracker.ietf.org/doc/rfc1952/) is a "GZIP file format specification", but there's a warning: "This RFC is not endorsed by the IETF and has no formal standing in the IETF standards process.". Anyway, I consider it as the right way to mark .tar.gz files too. Additional stuff that I read while researching: * https://stackoverflow.com/questions/2110269/add-mime-type-to-html-link Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6959 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-committed-by: 0ko <0ko@noreply.codeberg.org>
2025-02-16 12:59:28 +00:00
await expect(page.locator('.download[open] li:nth-of-type(2) a')).toHaveAttribute('type', 'application/gzip');
2023-09-15 18:20:16 +02:00
await expect(page.locator('.download[open] li:nth-of-type(3)')).toContainText('Test');
await expect(page.locator('.download[open] li:nth-of-type(3) a')).toHaveAttribute('href', 'https://forgejo.org/');
await save_visual(page);
2023-09-15 18:20:16 +02:00
await page.locator('.octicon-pencil').first().click();
// Validate edit page and edit the release
await expect(page).toHaveURL('/user2/repo2/releases/edit/2.0');
await validate_form({page}, 'fieldset');
2023-09-15 18:20:16 +02:00
await expect(page.locator('.attachment_edit:visible')).toHaveCount(2);
await expect(page.locator('.attachment_edit:visible').nth(0)).toHaveValue('Test');
await expect(page.locator('.attachment_edit:visible').nth(1)).toHaveValue('https://forgejo.org/');
await page.locator('.attachment_edit:visible').nth(0).fill('Test2');
await page.locator('.attachment_edit:visible').nth(1).fill('https://gitea.io/');
await page.click('#add-external-link');
await expect(page.locator('.attachment_edit:visible')).toHaveCount(4);
await page.locator('.attachment_edit:visible').nth(2).fill('Test3');
await page.locator('.attachment_edit:visible').nth(3).fill('https://gitea.com/');
await save_visual(page);
2023-09-15 18:20:16 +02:00
await page.click('.button.small.primary');
// Validate release page and click edit
await expect(page).toHaveURL('/user2/repo2/releases');
2023-09-15 18:20:16 +02:00
await expect(page.locator('.download[open] li')).toHaveCount(4);
await expect(page.locator('.download[open] li:nth-of-type(3)')).toContainText('Test2');
await expect(page.locator('.download[open] li:nth-of-type(3) a')).toHaveAttribute('href', 'https://gitea.io/');
await expect(page.locator('.download[open] li:nth-of-type(4)')).toContainText('Test3');
await expect(page.locator('.download[open] li:nth-of-type(4) a')).toHaveAttribute('href', 'https://gitea.com/');
await save_visual(page);
2023-09-15 18:20:16 +02:00
await page.locator('.octicon-pencil').first().click();
// Delete release
await expect(page).toHaveURL('/user2/repo2/releases/edit/2.0');
2023-09-15 18:20:16 +02:00
await page.click('.delete-button');
await page.click('.button.ok');
await expect(page).toHaveURL('/user2/repo2/releases');
2023-09-15 18:20:16 +02:00
});