@@ -262,39 +262,6 @@ func TestDocumentVersion_CreateDraft(t *testing.T) {
|
|||||||
assert.Equal(t, "DRAFT", result.CreateDraftDocumentVersion.DocumentVersionEdge.Node.Status)
|
assert.Equal(t, "DRAFT", result.CreateDraftDocumentVersion.DocumentVersionEdge.Node.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDocumentVersion_UpdateContent(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
owner := testutil.NewClient(t, testutil.RoleOwner)
|
|
||||||
|
|
||||||
_, draftVersionID := createTestDocument(t, owner)
|
|
||||||
|
|
||||||
query := `
|
|
||||||
mutation UpdateDocumentVersion($input: UpdateDocumentVersionContentInput!) {
|
|
||||||
updateDocumentVersionContent(input: $input) {
|
|
||||||
content
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
|
|
||||||
var result struct {
|
|
||||||
UpdateDocumentVersionContent struct {
|
|
||||||
Content string `json:"content"`
|
|
||||||
} `json:"updateDocumentVersionContent"`
|
|
||||||
}
|
|
||||||
|
|
||||||
wantContent := testutil.ProseMirrorTextDoc("Updated content for the document version")
|
|
||||||
|
|
||||||
err := owner.Execute(query, map[string]any{
|
|
||||||
"input": map[string]any{
|
|
||||||
"id": draftVersionID,
|
|
||||||
"content": wantContent,
|
|
||||||
},
|
|
||||||
}, &result)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
assert.JSONEq(t, wantContent, result.UpdateDocumentVersionContent.Content)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocumentVersion_RequestSignature(t *testing.T) {
|
func TestDocumentVersion_RequestSignature(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
owner := testutil.NewClient(t, testutil.RoleOwner)
|
owner := testutil.NewClient(t, testutil.RoleOwner)
|
||||||
|
|||||||
@@ -318,9 +318,9 @@ func (c *htmlBlockConverter) convertPre(n *html.Node) ([]Node, error) {
|
|||||||
|
|
||||||
func codeLanguageFromClass(class string) *string {
|
func codeLanguageFromClass(class string) *string {
|
||||||
const prefix = "language-"
|
const prefix = "language-"
|
||||||
for _, part := range strings.Fields(class) {
|
for part := range strings.FieldsSeq(class) {
|
||||||
if strings.HasPrefix(part, prefix) {
|
if after, ok := strings.CutPrefix(part, prefix); ok {
|
||||||
lang := strings.TrimPrefix(part, prefix)
|
lang := after
|
||||||
if lang != "" {
|
if lang != "" {
|
||||||
return &lang
|
return &lang
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -571,14 +571,14 @@ func TestParseMarkdown_InlineRawHTML(t *testing.T) {
|
|||||||
p := doc.Content[0]
|
p := doc.Content[0]
|
||||||
require.Equal(t, NodeParagraph, p.Type)
|
require.Equal(t, NodeParagraph, p.Type)
|
||||||
|
|
||||||
var joined string
|
var joined strings.Builder
|
||||||
for _, ch := range p.Content {
|
for _, ch := range p.Content {
|
||||||
require.Equal(t, NodeText, ch.Type)
|
require.Equal(t, NodeText, ch.Type)
|
||||||
require.NotNil(t, ch.Text)
|
require.NotNil(t, ch.Text)
|
||||||
joined += *ch.Text
|
joined.WriteString(*ch.Text)
|
||||||
}
|
}
|
||||||
// Sanitized HTML: span is unwrapped to plain text content.
|
// Sanitized HTML: span is unwrapped to plain text content.
|
||||||
assert.Equal(t, "before x after", joined)
|
assert.Equal(t, "before x after", joined.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMarkdown_InlineRawHTMLStrong(t *testing.T) {
|
func TestParseMarkdown_InlineRawHTMLStrong(t *testing.T) {
|
||||||
@@ -603,16 +603,16 @@ func TestParseMarkdown_InlineRawHTMLScriptStripped(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, doc.Content, 1)
|
require.Len(t, doc.Content, 1)
|
||||||
p := doc.Content[0]
|
p := doc.Content[0]
|
||||||
var joined string
|
var joined strings.Builder
|
||||||
for _, ch := range p.Content {
|
for _, ch := range p.Content {
|
||||||
if ch.Type == NodeText && ch.Text != nil {
|
if ch.Type == NodeText && ch.Text != nil {
|
||||||
joined += *ch.Text
|
joined.WriteString(*ch.Text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.NotContains(t, joined, "script")
|
assert.NotContains(t, joined.String(), "script")
|
||||||
assert.NotContains(t, joined, "evil")
|
assert.NotContains(t, joined.String(), "evil")
|
||||||
assert.Contains(t, joined, "hi")
|
assert.Contains(t, joined.String(), "hi")
|
||||||
assert.Contains(t, joined, "there")
|
assert.Contains(t, joined.String(), "there")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMarkdown_InlineRawHTMLWithOuterBold(t *testing.T) {
|
func TestParseMarkdown_InlineRawHTMLWithOuterBold(t *testing.T) {
|
||||||
@@ -624,13 +624,13 @@ func TestParseMarkdown_InlineRawHTMLWithOuterBold(t *testing.T) {
|
|||||||
p := doc.Content[0]
|
p := doc.Content[0]
|
||||||
require.GreaterOrEqual(t, len(p.Content), 3)
|
require.GreaterOrEqual(t, len(p.Content), 3)
|
||||||
|
|
||||||
var joined string
|
var joined strings.Builder
|
||||||
for _, ch := range p.Content {
|
for _, ch := range p.Content {
|
||||||
require.Equal(t, NodeText, ch.Type)
|
require.Equal(t, NodeText, ch.Type)
|
||||||
require.NotNil(t, ch.Text)
|
require.NotNil(t, ch.Text)
|
||||||
joined += *ch.Text
|
joined.WriteString(*ch.Text)
|
||||||
}
|
}
|
||||||
assert.Equal(t, "a b c", joined)
|
assert.Equal(t, "a b c", joined.String())
|
||||||
|
|
||||||
var mid *Node
|
var mid *Node
|
||||||
for i := range p.Content {
|
for i := range p.Content {
|
||||||
|
|||||||
Reference in New Issue
Block a user