Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-24 10:46:10 +01:00
forgejo/tests/integration/issue_subscribe_test.go
0ko 367317af6c Disable issue subscribe button for guest users (#4095)
* disabled the button itself, but added the tooltip to the form, because it didn't work for the button and likely has something to do with JS
* added an integration test to verify the new logic

## Preview

|Signed in|Guest|
|-|-|
|![](/attachments/b1441565-6aec-4a72-a28f-6383914c8918)|![](/attachments/839cc58e-18cf-4a5d-a9d7-f0e3e2556c98)|

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4095
Reviewed-by: Mai-Lapyst <mai-lapyst@noreply.codeberg.org>
2024-06-11 05:54:35 +00:00

45 lines
1.2 KiB
Go

// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"net/http"
"net/url"
"path"
"testing"
"github.com/stretchr/testify/assert"
)
func TestIssueSubscribe(t *testing.T) {
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
session := emptyTestSession(t)
testIssueSubscribe(t, *session, true)
})
}
func testIssueSubscribe(t *testing.T, session TestSession, unavailable bool) {
t.Helper()
testIssue := "/user2/repo1/issues/1"
testPull := "/user2/repo1/pulls/2"
selector := ".issue-content-right .watching form"
resp := session.MakeRequest(t, NewRequest(t, "GET", path.Join(testIssue)), http.StatusOK)
area := NewHTMLParser(t, resp.Body).Find(selector)
tooltip, exists := area.Attr("data-tooltip-content")
assert.EqualValues(t, unavailable, exists)
if unavailable {
assert.EqualValues(t, "Sign in to subscribe to this issue.", tooltip)
}
resp = session.MakeRequest(t, NewRequest(t, "GET", path.Join(testPull)), http.StatusOK)
area = NewHTMLParser(t, resp.Body).Find(selector)
tooltip, exists = area.Attr("data-tooltip-content")
assert.EqualValues(t, unavailable, exists)
if unavailable {
assert.EqualValues(t, "Sign in to subscribe to this pull request.", tooltip)
}
}