diff options
author | Daniel Baumann <daniel@debian.org> | 2024-10-18 20:33:49 +0200 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-12-12 23:57:56 +0100 |
commit | e68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch) | |
tree | 97775d6c13b0f416af55314eb6a89ef792474615 /tests/integration/org_nav_test.go | |
parent | Initial commit. (diff) | |
download | forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip |
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'tests/integration/org_nav_test.go')
-rw-r--r-- | tests/integration/org_nav_test.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/integration/org_nav_test.go b/tests/integration/org_nav_test.go new file mode 100644 index 0000000..37b6292 --- /dev/null +++ b/tests/integration/org_nav_test.go @@ -0,0 +1,62 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package integration + +import ( + "net/http" + "strings" + "testing" + + "code.gitea.io/gitea/modules/translation" + "code.gitea.io/gitea/tests" + + "github.com/stretchr/testify/assert" +) + +// This test makes sure that organization members are able to navigate between `/<orgname>` and `/org/<orgname>/<section>` freely. +// The `/org/<orgname>/<section>` page is only accessible to the members of the organization. It doesn't have +// a special logic to show the button or not. +// The `/<orgname>` page utilizes the `IsOrganizationMember` function to show the button for navigation to +// the organization dashboard. That function is covered by a test and is supposed to be true for the +// owners/admins/members of the organization. +func TestOrgNavigationDashboard(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + locale := translation.NewLocale("en-US") + + // Login as the future organization admin and create an organization + session1 := loginUser(t, "user2") + session1.MakeRequest(t, NewRequestWithValues(t, "POST", "/org/create", map[string]string{ + "_csrf": GetCSRF(t, session1, "/org/create"), + "org_name": "org_navigation_test", + "visibility": "0", + "repo_admin_change_team_access": "on", + }), http.StatusSeeOther) + + // Check if the "Open dashboard" button is available to the org admin (member) + resp := session1.MakeRequest(t, NewRequest(t, "GET", "/org_navigation_test"), http.StatusOK) + doc := NewHTMLParser(t, resp.Body) + doc.AssertElement(t, "#org-info a[href='/org/org_navigation_test/dashboard']", true) + + // Verify the "New repository" and "New migration" buttons + links := doc.Find(".organization.profile .grid .column .center") + assert.EqualValues(t, locale.TrString("new_repo.link"), strings.TrimSpace(links.Find("a[href^='/repo/create?org=']").Text())) + assert.EqualValues(t, locale.TrString("new_migrate.link"), strings.TrimSpace(links.Find("a[href^='/repo/migrate?org=']").Text())) + + // Check if the "View <orgname>" button is available on dashboard for the org admin (member) + resp = session1.MakeRequest(t, NewRequest(t, "GET", "/org/org_navigation_test/dashboard"), http.StatusOK) + doc = NewHTMLParser(t, resp.Body) + doc.AssertElement(t, ".dashboard .secondary-nav a[href='/org_navigation_test']", true) + + // Login a non-member user + session2 := loginUser(t, "user4") + + // Check if the "Open dashboard" button is available to non-member + resp = session2.MakeRequest(t, NewRequest(t, "GET", "/org_navigation_test"), http.StatusOK) + doc = NewHTMLParser(t, resp.Body) + doc.AssertElement(t, "#org-info a[href='/org/org_navigation_test/dashboard']", false) + + // There's no need to test "View <orgname>" button on dashboard as non-member + // because this page is not supposed to be visitable for this user +} |