Skip to content

Commit

Permalink
test: add tests for truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
kad-korpem committed Nov 27, 2024
1 parent 7e2282a commit 8b0d0c4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/engine/templatefuncs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ func TestUnmarkdown(t *testing.T) {
}
}

func TestTruncateText(t *testing.T) {
tests := []struct {
input string
limit int
expected string
}{
{"This text is not too long.", 50, "This text is not too long."},
{"", 50, ""},
{"This text is longer than the configured limit allows it to be.", 50, "This text is longer than the configured limit..."},
}

for _, tt := range tests {
t.Run("", func(t *testing.T) {
assert.Equal(t, tt.expected, *truncateText(&tt.input, tt.limit))
})
}
}

func TestHumanSize(t *testing.T) {
tests := []struct {
input any
Expand Down
14 changes: 14 additions & 0 deletions internal/ogc/features/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,20 @@ func TestFeatures(t *testing.T) {
statusCode: http.StatusOK,
},
},
{
name: "Request features of collection with a long description",
fields: fields{
configFile: "internal/ogc/features/testdata/config_features_bag_long_description.yaml",
url: "http://localhost:8080/collections/:collectionId/items?limit=1",
collectionID: "bar",
contentCrs: "<" + domain.WGS84CrsURI + ">",
format: "html",
},
want: want{
body: "internal/ogc/features/testdata/expected_bar_collection_snippet.html",
statusCode: http.StatusOK,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
version: 1.0.2
title: OGC API Features
abstract: Contains a slimmed-down/example version of the BAG-dataset
baseUrl: http://localhost:8080
serviceIdentifier: Feats
license:
name: CC0
url: https://www.tldrlegal.com/license/creative-commons-cc0-1-0-universal
ogcApi:
features:
datasources:
defaultWGS84:
geopackage:
local:
file: ./internal/ogc/features/datasources/geopackage/testdata/bag.gpkg
fid: feature_id
queryTimeout: 15m # pretty high to allow debugging
collections:
- id: foo
tableName: ligplaatsen
filters:
properties:
- name: straatnaam
- name: postcode
metadata:
title: Foooo
description: >-
This description of collection Foooo is short.
- id: bar
tableName: ligplaatsen
metadata:
title: Barrr
description: >-
This description of collection Barrr is quite long, and as such would distract the user from the rest of the content on overview pages.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec accumsan lectus id ipsum condimentum pretium. Aenean cursus et diam aliquam
vestibulum. Cras at est risus. Suspendisse venenatis dignissim aliquet. Maecenas rhoncus mi vulputate mi ullamcorper tincidunt.
Aliquam aliquet risus ut convallis finibus. Curabitur ut ultrices erat. Suspendisse et vehicula arcu, a lacinia ligula. Orci posuere.
tableName: ligplaatsen
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="card-body">

<p>This description of collection Barrr is quite long, and as such would distract the user from the rest of the content on overview pages. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec accumsan lectus id ipsum condimentum pretium. Aenean cursus et diam aliquam vestibulum. Cras at est risus. Suspendisse venenatis dignissim aliquet. Maecenas rhoncus mi vulputate mi ullamcorper&hellip;</p>


</div>

0 comments on commit 8b0d0c4

Please sign in to comment.