mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-20 01:36:37 +00:00
Test coverage: |Modal|Test| |-|-| |admin: adopt unadopted|missing, not needed| |admin: delete unadopted|missing, not needed| |admin: delete user|e2e added: `Admin: delete a user`| |delete package|missing| |new project|?| |edit project col|?| |default project col|?| |delete project col|?| |commit cherry-pick|?| |commit delete note|?| |fork redirect|?| |lock/unlock issue|?| |dismiss PR review|?| |migration delete|?| |migration cancel|?| |lfs delete|?| |convert mirror|?| |convert fork|?| |transfer repo|?| |delete repo|?| |archive repo|integration present, selectors adjusted| |delete wiki|?| |rename wiki branch|?| |push mirror edit|?| |mde: new table|e2e present, selectors adjusted| |mde: new link|e2e present, selectors adjusted| |actions: add secret|?| |actions: edit variable|?| Co-authored-by: 0ko <0ko@noreply.codeberg.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10287 Reviewed-by: 0ko <0ko@noreply.codeberg.org>
77 lines
2.4 KiB
Go
77 lines
2.4 KiB
Go
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
"testing"
|
|
|
|
"forgejo.org/models/unittest"
|
|
user_model "forgejo.org/models/user"
|
|
"forgejo.org/modules/translation"
|
|
"forgejo.org/tests"
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestArchiveText(t *testing.T) {
|
|
onApplicationRun(t, func(t *testing.T, giteaURL *url.URL) {
|
|
testUser := "user2"
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: testUser})
|
|
session := loginUser(t, testUser)
|
|
testRepoName := "archived_repo"
|
|
tr := translation.NewLocale("en-US")
|
|
link := path.Join(testUser, testRepoName, "settings")
|
|
|
|
// Create test repo
|
|
_, _, f := tests.CreateDeclarativeRepo(t, user2, testRepoName, nil, nil, nil)
|
|
defer f()
|
|
|
|
// Test settings page
|
|
req := NewRequest(t, "GET", link)
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
archivation := NewHTMLParser(t, resp.Body)
|
|
testRepoArchiveElements(t, tr, archivation, "archive")
|
|
|
|
// Archive repo
|
|
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
|
"action": "archive",
|
|
})
|
|
_ = session.MakeRequest(t, req, http.StatusSeeOther)
|
|
|
|
// Test settings page again
|
|
req = NewRequest(t, "GET", link)
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
unarchivation := NewHTMLParser(t, resp.Body)
|
|
testRepoArchiveElements(t, tr, unarchivation, "unarchive")
|
|
})
|
|
}
|
|
|
|
func testRepoArchiveElements(t *testing.T, tr translation.Locale, doc *HTMLDoc, opType string) {
|
|
t.Helper()
|
|
|
|
// Test danger section
|
|
section := doc.Find(".danger.segment .flex-list .flex-item:has(.button[data-modal='#archive-repo-modal'])")
|
|
testRepoArchiveElement(t, tr, section, ".flex-item-title", opType+".header")
|
|
testRepoArchiveElement(t, tr, section, ".flex-item-body", opType+".text")
|
|
testRepoArchiveElement(t, tr, section, ".button", opType+".button")
|
|
|
|
// Test modal
|
|
modal := doc.Find("#archive-repo-modal")
|
|
testRepoArchiveElement(t, tr, modal, "header", opType+".header")
|
|
testRepoArchiveElement(t, tr, modal, ".message", opType+".text")
|
|
testRepoArchiveElement(t, tr, modal, ".button.red", opType+".button")
|
|
}
|
|
|
|
func testRepoArchiveElement(t *testing.T, tr translation.Locale, doc *goquery.Selection, selector, op string) {
|
|
t.Helper()
|
|
|
|
element := doc.Find(selector).Text()
|
|
element = strings.TrimSpace(element)
|
|
assert.Equal(t, tr.TrString("repo.settings."+op), element)
|
|
}
|