1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"net/http"
"net/url"
"strings"
"testing"
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
)
func TestArchivedLabelVisualProperties(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
session := loginUser(t, "user2")
// Create labels
session.MakeRequest(t, NewRequestWithValues(t, "POST", "user2/repo1/labels/new", map[string]string{
"_csrf": GetCSRF(t, session, "user2/repo1/labels"),
"title": "active_label",
"description": "",
"color": "#aa00aa",
}), http.StatusSeeOther)
session.MakeRequest(t, NewRequestWithValues(t, "POST", "user2/repo1/labels/new", map[string]string{
"_csrf": GetCSRF(t, session, "user2/repo1/labels"),
"title": "archived_label",
"description": "",
"color": "#00aa00",
}), http.StatusSeeOther)
// Get ID of label to archive it
var id string
doc := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", "user2/repo1/labels"), http.StatusOK).Body)
doc.Find(".issue-label-list .item").Each(func(i int, s *goquery.Selection) {
label := s.Find(".label-title .label")
if label.Text() == "archived_label" {
href, _ := s.Find(".label-issues a.open-issues").Attr("href")
hrefParts := strings.Split(href, "=")
id = hrefParts[len(hrefParts)-1]
}
})
// Make label archived
session.MakeRequest(t, NewRequestWithValues(t, "POST", "user2/repo1/labels/edit", map[string]string{
"_csrf": GetCSRF(t, session, "user2/repo1/labels"),
"id": id,
"title": "archived_label",
"is_archived": "on",
"description": "",
"color": "#00aa00",
}), http.StatusSeeOther)
// Test label properties
doc = NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", "user2/repo1/labels"), http.StatusOK).Body)
doc.Find(".issue-label-list .item").Each(func(i int, s *goquery.Selection) {
label := s.Find(".label-title .label")
style, _ := label.Attr("style")
if label.Text() == "active_label" {
assert.False(t, label.HasClass("archived-label"))
assert.Contains(t, style, "background-color: #aa00aaff")
} else if label.Text() == "archived_label" {
assert.True(t, label.HasClass("archived-label"))
assert.Contains(t, style, "background-color: #00aa007f")
}
})
})
}
|