From 31965f2dd7f9b4e7141c508f039cb8b22e11a6b4 Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Sun, 8 Feb 2026 23:55:30 +0100 Subject: [PATCH] chore(ui): add integration tests for footer tmpl logic (#11197) Slightly related to https://codeberg.org/forgejo/forgejo/pulls/11196, but it has no tests related to the change in that PR. Added tests because I wanted those config options be tested, but haven't found any existing tests. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11197 Reviewed-by: Beowulf Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-committed-by: 0ko <0ko@noreply.codeberg.org> --- tests/integration/footer_test.go | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tests/integration/footer_test.go diff --git a/tests/integration/footer_test.go b/tests/integration/footer_test.go new file mode 100644 index 0000000000..45ff3ca426 --- /dev/null +++ b/tests/integration/footer_test.go @@ -0,0 +1,66 @@ +// Copyright 2026 The Forgejo Authors +// SPDX-License-Identifier: GPL-3.0-or-later + +package integration + +import ( + "net/http" + "strings" + "testing" + + "forgejo.org/modules/setting" + "forgejo.org/modules/test" + "forgejo.org/tests" + + "github.com/stretchr/testify/assert" +) + +/* TestFooterContent asserts go tmpl logic of footer */ +func TestFooterContent(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + // The footer can be tested on any page, but preferably a lightweight one + regularPage := "/explore/organizations" + adminPage := "/admin" + + adminUser := loginUser(t, "user1") + regularUser := loginUser(t, "user2") + + t.Run(`Default configuration`, func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + // For admins Version dubs as a link to /admin/config, for regular users + // it's just text + testFooterContent(t, regularUser, regularPage, true, true, false) + testFooterContent(t, adminUser, regularPage, true, true, true) + testFooterContent(t, adminUser, adminPage, true, true, true) + }) + + t.Run(`ShowFooterPoweredBy is disabled`, func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + defer test.MockVariableValue(&setting.Other.ShowFooterPoweredBy, false)() + + testFooterContent(t, regularUser, regularPage, false, true, false) + }) + + t.Run(`ShowFooterVersion is disabled`, func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + defer test.MockVariableValue(&setting.Other.ShowFooterVersion, false)() + + // ShowFooterVersion is on by default. Disabling it hides the version on + // all pages but not on /admin + testFooterContent(t, regularUser, regularPage, true, false, false) + testFooterContent(t, adminUser, regularPage, true, false, false) + testFooterContent(t, adminUser, adminPage, true, true, true) + }) +} + +// When visiting certain pages, the corresponding entry of user menu is highlighted +func testFooterContent(t *testing.T, session *TestSession, url string, expectPoweredBy, expectVersion, expectVersionLink bool) { + page := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", url), http.StatusOK).Body) + // AssertElement will only pass if there's just one such element + footerLeft := page.Find("footer .left-links").Text() + assert.Equal(t, expectPoweredBy, strings.Contains(footerLeft, "Powered by Forgejo")) + assert.Equal(t, expectVersion, strings.Contains(footerLeft, "Version")) + page.AssertElement(t, `footer .left-links a[href="/admin/config"]`, expectVersionLink) +}