You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wiki/search_test.go

102 lines
4.5 KiB

/*
* Wiki - A wiki with editor
* Copyright (c) 2021 Peter Stuifzand
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
const testData = `[{"id":"_a1zs4qeuxt5","indented":0,"text":"Metadata::","fold":"open","hidden":false},{"id":"_9kopnjwgx06","indented":1,"text":"Source:: https://www.youtube.com/watch?v=ljyo_WAJevQ","fold":"open","hidden":false},{"id":"_z83v65zsso","indented":1,"text":"Author:: [[Shu Omi]]","fold":"open","hidden":false},{"id":"_jkw3ff32hoa","indented":1,"text":"Keywords::","fold":"open","hidden":false},{"id":"_2t75yfhdwha","indented":2,"text":"#[[note-taking]]","fold":"open","hidden":false},{"id":"_k6pn5i4vk1h","indented":2,"text":"#[[zettelkasten]]","fold":"open","hidden":false},{"id":"_cefe8c1kr7","indented":1,"text":"Link:: [[Literature Notes How to Take Smart Notes]]","fold":"open","hidden":false},{"id":"_rrkre3jwhg","indented":1,"text":"Type:: article","fold":"open","hidden":false},{"id":"_7kzbptq7aif","indented":0,"text":"Relevant Notes::","fold":"open","hidden":false},{"id":"_8iexxkqnex6","indented":1,"text":"[[Active Reading]]","fold":"open","hidden":false},{"id":"_h3d1x02t1c8","indented":0,"text":"Notes #[[permanent notes]]","fold":"open","hidden":false},{"id":"_xljoaxcomno","indented":1,"text":"Slimme notities maak je in 4 stappen. Stap 1 is het verzamelen van notities op basis van de tekst. Deze selecteer je en schrijf je kort en bondig in je eigen woorden zonder te quoten. In stap 2 maak je een notitie van de referentie zelf. Bepaal de steekwoorden waarmee je deze notitie later terug zou willen vinden. Dit kan dus iets anders zijn dan de categorie van het onderwerp. In stap 3 maak je de notitie permanent. Je neemt het hiermee op in de structuur van je andere notities.","fold":"open","hidden":false}]`
func TestCreateStructuredFormat(t *testing.T) {
searchObject, err := createStructuredFormat(Page{
Name: "Test",
Title: "Test",
Content: testData,
})
if assert.NoError(t, err, "createStructuredFormat") {
assert.Equal(t, searchObject.Title, "Test")
assert.Equal(t, map[string]interface{}{
"metadata": map[string]interface{}{
"source": "https://www.youtube.com/watch?v=ljyo_WAJevQ",
"author": ParsedLink{
ID: "",
Name: "Shu Omi",
PageName: "Shu_Omi",
Line: "[[Shu Omi]]",
Href: "Shu_Omi",
},
"keywords": []interface{}{
ParsedLink{
ID: "",
Name: "note-taking",
PageName: "note-taking",
Line: "#[[note-taking]]",
Href: "note-taking",
},
ParsedLink{
ID: "",
Name: "zettelkasten",
PageName: "zettelkasten",
Line: "#[[zettelkasten]]",
Href: "zettelkasten",
},
},
"link": ParsedLink{
ID: "",
Name: "Literature Notes How to Take Smart Notes",
PageName: "Literature_Notes_How_to_Take_Smart_Notes",
Line: "[[Literature Notes How to Take Smart Notes]]",
Href: "Literature_Notes_How_to_Take_Smart_Notes",
},
"type": "article",
},
"relevant_notes": []interface{}{
ParsedLink{
ID: "",
Name: "Active Reading",
PageName: "Active_Reading",
Line: "[[Active Reading]]",
Href: "Active_Reading",
}},
},
searchObject.Meta,
)
}
}
const testData2 string = `[{"id": "_a1zs4qeuxt5", "indented": 0, "text": "Metadata::", "fold": "open", "hidden": false}, {"id": "_7kzbptq7aif", "indented": 0, "text": "Relevant Notes::", "fold": "open", "hidden": false}]`
func TestCreateStructuredFormat2(t *testing.T) {
searchObject, err := createStructuredFormat(Page{
Name: "Test2",
Title: "Test2",
Content: testData2,
})
if assert.NoError(t, err, "createStructuredFormat") {
assert.Equal(t, searchObject.Title, "Test2")
assert.Equal(t, map[string]interface{}{
"metadata": "",
"relevant_notes": "",
}, searchObject.Meta)
}
}