summaryrefslogtreecommitdiffstats
path: root/tests/integration/markup_test.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-11 10:27:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-11 10:27:00 +0000
commit65aa53fc52ff15efe54df4147564828d535837f8 (patch)
tree31c51dad04fdcca80e6d3043c8bd49d2f1a51f83 /tests/integration/markup_test.go
parentInitial commit. (diff)
downloadforgejo-debian.tar.xz
forgejo-debian.zip
Adding upstream version 8.0.3.HEADupstream/8.0.3upstreamdebian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/integration/markup_test.go')
-rw-r--r--tests/integration/markup_test.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/integration/markup_test.go b/tests/integration/markup_test.go
new file mode 100644
index 00000000..d63190a8
--- /dev/null
+++ b/tests/integration/markup_test.go
@@ -0,0 +1,72 @@
+// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package integration
+
+import (
+ "fmt"
+ "net/http"
+ "strings"
+ "testing"
+
+ auth_model "code.gitea.io/gitea/models/auth"
+ api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/tests"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestRenderAlertBlocks(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ session := loginUser(t, "user1")
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteMisc)
+
+ assertAlertBlock := func(t *testing.T, input, alertType, alertIcon string) {
+ t.Helper()
+
+ blockquoteAttr := fmt.Sprintf(`<blockquote class="attention-header attention-%s"`, strings.ToLower(alertType))
+ classAttr := fmt.Sprintf(`class="attention-%s"`, strings.ToLower(alertType))
+ iconAttr := fmt.Sprintf(`svg octicon-%s`, alertIcon)
+
+ req := NewRequestWithJSON(t, "POST", "/api/v1/markdown", &api.MarkdownOption{
+ Text: input,
+ Mode: "markdown",
+ }).AddTokenAuth(token)
+ resp := MakeRequest(t, req, http.StatusOK)
+ body := resp.Body.String()
+ assert.Contains(t, body, blockquoteAttr)
+ assert.Contains(t, body, classAttr)
+ assert.Contains(t, body, iconAttr)
+ }
+
+ t.Run("legacy style", func(t *testing.T) {
+ for alertType, alertIcon := range map[string]string{"Note": "info", "Warning": "alert"} {
+ t.Run(alertType, func(t *testing.T) {
+ input := fmt.Sprintf(`> **%s**
+>
+> This is a %s.`, alertType, alertType)
+
+ assertAlertBlock(t, input, alertType, alertIcon)
+ })
+ }
+ })
+
+ t.Run("modern style", func(t *testing.T) {
+ for alertType, alertIcon := range map[string]string{
+ "NOTE": "info",
+ "TIP": "light-bulb",
+ "IMPORTANT": "report",
+ "WARNING": "alert",
+ "CAUTION": "stop",
+ } {
+ t.Run(alertType, func(t *testing.T) {
+ input := fmt.Sprintf(`> [!%s]
+>
+> This is a %s.`, alertType, alertType)
+
+ assertAlertBlock(t, input, alertType, alertIcon)
+ })
+ }
+ })
+}