From b2d3ae4dc0d5ab07b3a5e83a98aca468b74f5a36 Mon Sep 17 00:00:00 2001
From: Gusted <postmaster@gusted.xyz>
Date: Sun, 14 Jul 2024 05:38:45 +0200
Subject: [PATCH 1/2] [UI] Remove unnecessary vertical space in empty labels
 list

- Don't show the labels-list element, if no labels are selected.
- The labels-list was taking up vertical space, even if no labels were
selected which caused an inconsistency in how the sidebar looked.
- Adds integration test

(cherry picked from commit 013b89eb13f4a87e521381072853d253137c1da5)
---
 .../repo/issue/labels/labels_sidebar.tmpl     | 18 +++++++-----
 tests/integration/issue_test.go               | 29 +++++++++++++++++++
 2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/templates/repo/issue/labels/labels_sidebar.tmpl b/templates/repo/issue/labels/labels_sidebar.tmpl
index be30baba92..d39c2133a7 100644
--- a/templates/repo/issue/labels/labels_sidebar.tmpl
+++ b/templates/repo/issue/labels/labels_sidebar.tmpl
@@ -1,11 +1,13 @@
 <div class="ui labels list">
 	<span class="no-select item {{if .root.HasSelectedLabel}}tw-hidden{{end}}">{{ctx.Locale.Tr "repo.issues.new.no_label"}}</span>
-	<span class="labels-list">
-		{{range .root.Labels}}
-			{{template "repo/issue/labels/label" dict "root" $.root "label" .}}
-		{{end}}
-		{{range .root.OrgLabels}}
-			{{template "repo/issue/labels/label" dict "root" $.root "label" .}}
-		{{end}}
-	</span>
+	{{if .root.HasSelectedLabel}}
+		<span class="labels-list">
+			{{range .root.Labels}}
+				{{template "repo/issue/labels/label" dict "root" $.root "label" .}}
+			{{end}}
+			{{range .root.OrgLabels}}
+				{{template "repo/issue/labels/label" dict "root" $.root "label" .}}
+			{{end}}
+		</span>
+	{{end}}
 </div>
diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go
index 3f61dafbf0..6a0a9c2934 100644
--- a/tests/integration/issue_test.go
+++ b/tests/integration/issue_test.go
@@ -939,3 +939,32 @@ func TestIssueUnsubscription(t *testing.T) {
 		session.MakeRequest(t, req, http.StatusOK)
 	})
 }
+
+func TestIssueLabelList(t *testing.T) {
+	defer tests.PrepareTestEnv(t)()
+	labelListSelector := ".labels.list .labels-list"
+	hiddenClass := "tw-hidden"
+
+	t.Run("Show label list", func(t *testing.T) {
+		defer tests.PrintCurrentTest(t)()
+
+		req := NewRequest(t, "GET", "/user2/repo1/issues/1")
+		resp := MakeRequest(t, req, http.StatusOK)
+		htmlDoc := NewHTMLParser(t, resp.Body)
+
+		htmlDoc.AssertElement(t, labelListSelector, true)
+		htmlDoc.AssertElement(t, ".labels.list .no-select.item."+hiddenClass, true)
+	})
+
+	t.Run("Show no label list", func(t *testing.T) {
+		defer tests.PrintCurrentTest(t)()
+		session := loginUser(t, "user2")
+
+		req := NewRequest(t, "GET", "/user2/repo2/issues/1")
+		resp := session.MakeRequest(t, req, http.StatusOK)
+		htmlDoc := NewHTMLParser(t, resp.Body)
+
+		htmlDoc.AssertElement(t, labelListSelector, false)
+		htmlDoc.AssertElement(t, ".labels.list .no-select.item:not([class*='"+hiddenClass+"'])", true)
+	})
+}

From a56bc83bb28752aef6ad118fdf5b04c2cf1ef2f7 Mon Sep 17 00:00:00 2001
From: fnetX <otto@codeberg.org>
Date: Sun, 14 Jul 2024 17:46:40 +0000
Subject: [PATCH 2/2] revert [v7.0/forgejo] test: issue sidebar testing using
 playwright' (#4335)

revert Merge pull request '[v7.0/forgejo] test: issue sidebar testing using playwright' (#4335) from bp-v7.0/forgejo-fafc4f6 into v7.0/forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4335
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
---
 tests/e2e/README.md                 | 26 ---------
 tests/e2e/issue-sidebar.test.e2e.js | 86 -----------------------------
 2 files changed, 112 deletions(-)
 delete mode 100644 tests/e2e/issue-sidebar.test.e2e.js

diff --git a/tests/e2e/README.md b/tests/e2e/README.md
index 0f1ef4b40e..e5fd1ca6c0 100644
--- a/tests/e2e/README.md
+++ b/tests/e2e/README.md
@@ -20,32 +20,6 @@ make clean frontend
 npx playwright install-deps
 ```
 
-## Interactive testing
-
-You can make use of Playwright's integrated UI mode to run individual tests,
-get feedback and visually trace what your browser is doing.
-
-To do so, launch the debugserver using:
-
-```
-make test-e2e-debugserver
-```
-
-Then launch the Playwright UI:
-
-```
-npx playwright test --ui
-```
-
-You can also run individual tests while the debugserver using:
-
-```
-npx playwright test actions.test.e2e.js:9
-```
-
-First, specify the complete test filename,
-and after the colon you can put the linenumber where the test is defined.
-
 
 ## Run all tests via local act_runner
 ```
diff --git a/tests/e2e/issue-sidebar.test.e2e.js b/tests/e2e/issue-sidebar.test.e2e.js
deleted file mode 100644
index 41b1b2064a..0000000000
--- a/tests/e2e/issue-sidebar.test.e2e.js
+++ /dev/null
@@ -1,86 +0,0 @@
-// @ts-check
-import {test, expect} from '@playwright/test';
-import {login_user, load_logged_in_context} from './utils_e2e.js';
-
-test.beforeAll(async ({browser}, workerInfo) => {
-  await login_user(browser, workerInfo, 'user2');
-});
-
-async function login({browser}, workerInfo) {
-  const context = await load_logged_in_context(browser, workerInfo, 'user2');
-  return await context.newPage();
-}
-
-// belongs to test: Pull: Toggle WIP
-const prTitle = 'pull5';
-
-async function click_toggle_wip({page}) {
-  await page.locator('.toggle-wip>a').click();
-  await page.waitForLoadState('networkidle');
-}
-
-async function check_wip({page}, is) {
-  const elemTitle = '#issue-title-display';
-  const stateLabel = '.issue-state-label';
-  await expect(page.locator(elemTitle)).toContainText(prTitle);
-  await expect(page.locator(elemTitle)).toContainText('#5');
-  if (is) {
-    await expect(page.locator(elemTitle)).toContainText('WIP');
-    await expect(page.locator(stateLabel)).toContainText('Draft');
-  } else {
-    await expect(page.locator(elemTitle)).not.toContainText('WIP');
-    await expect(page.locator(stateLabel)).toContainText('Open');
-  }
-}
-
-test('Pull: Toggle WIP', async ({browser}, workerInfo) => {
-  test.skip(workerInfo.project.name === 'Mobile Safari', 'Unable to get tests working on Safari Mobile, see https://codeberg.org/forgejo/forgejo/pulls/3445#issuecomment-1789636');
-  const page = await login({browser}, workerInfo);
-  const response = await page.goto('/user2/repo1/pulls/5');
-  await expect(response?.status()).toBe(200); // Status OK
-  // initial state
-  await check_wip({page}, false);
-  // toggle to WIP
-  await click_toggle_wip({page});
-  await check_wip({page}, true);
-  // remove WIP
-  await click_toggle_wip({page});
-  await check_wip({page}, false);
-
-  // manually edit title to another prefix
-  await page.locator('#issue-title-edit-show').click();
-  await page.locator('#issue-title-editor input').fill(`[WIP] ${prTitle}`);
-  await page.getByText('Save').click();
-  await page.waitForLoadState('networkidle');
-  await check_wip({page}, true);
-  // remove again
-  await click_toggle_wip({page});
-  await check_wip({page}, false);
-});
-
-test('Issue: Labels', async ({browser}, workerInfo) => {
-  test.skip(workerInfo.project.name === 'Mobile Safari', 'Unable to get tests working on Safari Mobile, see https://codeberg.org/forgejo/forgejo/pulls/3445#issuecomment-1789636');
-  const page = await login({browser}, workerInfo);
-  // select label list in sidebar only
-  const labelList = page.locator('.issue-content-right .labels-list a');
-  const response = await page.goto('/user2/repo1/issues/1');
-  await expect(response?.status()).toBe(200);
-  // preconditions
-  await expect(labelList.filter({hasText: 'label1'})).toBeVisible();
-  await expect(labelList.filter({hasText: 'label2'})).not.toBeVisible();
-  // add label2
-  await page.locator('.select-label').click();
-  // label search could be tested this way:
-  // await page.locator('.select-label input').fill('label2');
-  await page.locator('.select-label .item').filter({hasText: 'label2'}).click();
-  await page.locator('.select-label').click();
-  await page.waitForLoadState('networkidle');
-  await expect(labelList.filter({hasText: 'label2'})).toBeVisible();
-  // test removing label again
-  await page.locator('.select-label').click();
-  await page.locator('.select-label .item').filter({hasText: 'label2'}).click();
-  await page.locator('.select-label').click();
-  await page.waitForLoadState('networkidle');
-  await expect(labelList.filter({hasText: 'label2'})).not.toBeVisible();
-  await expect(labelList.filter({hasText: 'label1'})).toBeVisible();
-});