Skip to content

Commit

Permalink
Merge pull request #253 from PDOK/small-fixes
Browse files Browse the repository at this point in the history
fix: broken link on tiles metadata page (+ some extras)
  • Loading branch information
rkettelerij authored Nov 12, 2024
2 parents 3b33044 + 0e13c12 commit 074764d
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 31 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ type Resources struct {
// +optional
URL *URL `yaml:"url,omitempty" json:"url,omitempty" validate:"required_without=Directory,omitempty"`

// // Location where resources (e.g. thumbnails) specific to the given dataset are hosted. This is optional if URL is set
// Location where resources (e.g. thumbnails) specific to the given dataset are hosted. This is optional if URL is set
// +optional
Directory *string `yaml:"directory,omitempty" json:"directory,omitempty" validate:"required_without=URL,omitempty,dirpath|filepath"`
}
Expand Down
2 changes: 1 addition & 1 deletion examples/config_all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ datasetDetails:
- name: Metadata dataset
value: >-
[Dataset metadata in Example Register](https://example.com/my-dataset/metadata)
datasetCatalogUrl: https://www.pdok.nl/datasets
datasetCatalogUrl: https://example.com/datasets
baseUrl: http://localhost:8080
availableLanguages:
- nl
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/templates/layout.go.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<!-- canonical -->
<link rel="canonical" href="{{ .Config.BaseURL }}" />
{{ range $lang := .Config.AvailableLanguages }}
<link rel="alternate" hreflang="{{ $lang }}" href="{{ $.Config.BaseURL }}?lang={{ $lang }}" />
<link rel="alternate" hreflang="{{ $lang }}" href="{{ $.Config.BaseURL }}?f=html&lang={{ $lang }}" />
{{ end }}

<!-- css -->
Expand Down
12 changes: 3 additions & 9 deletions internal/engine/testdata/expected_dataset_landingpage.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@
"name": "Demo of all OGC specs in one API (OGC API)",
"description": "This is example combines features, 3D and vector tiles in one API. Usually this would encompass one dataset but this demo uses data from various sources. So don\u0027t pay too much attention to the actual data. It\u0027s just an example\/demo of GoKoala\u0027s capabilities.",
"url": "http:\/\/localhost:8080?f=html",
"keywords": ["keyword1, keyword2"],
"keywords": ["keyword1", "keyword2"],
"license": "https:\/\/creativecommons.org\/publicdomain\/zero\/1.0\/deed.nl",
"isAccessibleForFree": true,
"hasPart": [
{
"@type": "URL",
"url": "http:\/\/localhost:8080/collections/addresses"
},
{
"@type": "URL",
"url": "http:\/\/localhost:8080/collections/addresses2"
}
"http:\/\/localhost:8080/collections/addresses",
"http:\/\/localhost:8080/collections/addresses2"
]
}
16 changes: 8 additions & 8 deletions internal/ogc/common/core/templates/landing-page.go.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
"description": "{{ unmarkdown .Config.Abstract }}",
"url": "{{ .Config.BaseURL }}?f=html",
{{- if .Config.Keywords }}
"keywords": ["{{ .Config.Keywords | join ", " }}"],
"keywords": [
{{- range $i, $k := .Config.Keywords -}}
{{- if $i -}},{{- end -}}"{{ $k }}"
{{- end -}}
],
{{- end }}
"license": "{{ .Config.License.URL }}",
"isAccessibleForFree": true
,"hasPart": [
{{- range $index, $coll := .Config.AllCollections.Unique }}
{{- if $index }},{{ end }}
{
"@type": "URL",
"url": "{{ $.Config.BaseURL }}/collections/{{ $coll.ID }}"
}
{{- end }}
{{- range $i, $coll := .Config.AllCollections.Unique -}}
{{- if $i -}},{{- end -}}"{{ $.Config.BaseURL }}/collections/{{ $coll.ID }}"
{{- end -}}
]
}
</script>
Expand Down
15 changes: 7 additions & 8 deletions internal/ogc/tiles/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,18 @@ func renderTilesTemplates(e *engine.Engine, collection *config.GeoSpatialCollect
engine.NewTemplateKeyWithName(templatesDir+"tiles.go.json", collectionID),
engine.NewTemplateKeyWithName(templatesDir+"tiles.go.html", collectionID))

// Now render metadata bout tiles per projection/SRS.
// Now render metadata about tiles per projection/SRS.
for _, projection := range config.AllTileProjections {
path = tilesPath + "/" + projection

projectionBreadcrumbs := breadcrumbs
projectionBreadcrumbs = append(projectionBreadcrumbs, []engine.Breadcrumb{
{
Name: projection,
Path: collectionsCrumb + collectionID + path,
},
}...)

if collection != nil {
projectionBreadcrumbs = append(projectionBreadcrumbs, []engine.Breadcrumb{
{
Name: projection,
Path: collectionsCrumb + collectionID + path,
},
}...)
path = g.CollectionsPath + "/" + collectionID + tilesPath + "/" + projection
}
e.RenderTemplatesWithParams(path,
Expand Down
3 changes: 2 additions & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ yarn-error.log

# Cypress
cypress/videos
cypress/screenshots
cypress/screenshots
downloads/
31 changes: 31 additions & 0 deletions tests/cypress/e2e/common.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
describe('OGC API Common tests', () => {

// Fix for https://github.com/cypress-io/cypress/issues/1502#issuecomment-832403402
Cypress.on("window:before:load", () => {
cy.state("jQuery", Cypress.$);
});

it('landing page should have no a11y violations', () => {
cy.visit('/')
cy.injectAxe()
Expand All @@ -16,6 +21,11 @@ describe('OGC API Common tests', () => {
cy.get('.card-header.h5').should("have.length", 6)
})

it('landing page should have no broken links', () => {
cy.visit('/')
cy.checkForBrokenLinks()
})

// disabled since it has two violations in the 3rd party swagger-ui component (outside our control)
it.skip('openapi page should have no a11y violations', () => {
cy.visit('/api')
Expand All @@ -28,6 +38,11 @@ describe('OGC API Common tests', () => {
cy.htmlvalidate();
})

it('openapi page should have no broken links', () => {
cy.visit('/api')
cy.checkForBrokenLinks()
})

it('conformance page should have no a11y violations', () => {
cy.visit('/conformance')
cy.injectAxe()
Expand All @@ -39,6 +54,12 @@ describe('OGC API Common tests', () => {
cy.htmlvalidate();
})

// Here we also check ogc.org pages, so this test may fail if ogc webpage is down...
it('conformance page should have no broken links', () => {
cy.visit('/conformance')
cy.checkForBrokenLinks()
})

it('collections page should have no a11y violations', () => {
cy.visit('/collections')
cy.injectAxe()
Expand All @@ -50,6 +71,11 @@ describe('OGC API Common tests', () => {
cy.htmlvalidate();
})

it('collections page should have no broken links', () => {
cy.visit('/collections')
cy.checkForBrokenLinks()
})

it('collection page should have no a11y violations', () => {
cy.visit('/collections/addresses')
cy.injectAxe()
Expand All @@ -60,4 +86,9 @@ describe('OGC API Common tests', () => {
cy.visit("/collections/addresses");
cy.htmlvalidate();
})

it('collection page should have no broken links', () => {
cy.visit('/collections/addresses')
cy.checkForBrokenLinks()
})
})
14 changes: 14 additions & 0 deletions tests/cypress/e2e/features.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
describe('OGC API Features tests', () => {

// Fix for https://github.com/cypress-io/cypress/issues/1502#issuecomment-832403402
Cypress.on("window:before:load", () => {
cy.state("jQuery", Cypress.$);
});

it('features page should have no a11y violations', () => {
cy.visit('/collections/addresses/items')
cy.injectAxe()
Expand All @@ -13,6 +18,11 @@ describe('OGC API Features tests', () => {
})
})

it('collection page should have no broken links', () => {
cy.visit('/collections/addresses/items')
cy.checkForBrokenLinks()
})

it('feature page should have no a11y violations', () => {
cy.visit('/collections/addresses/items/1')
cy.injectAxe()
Expand All @@ -26,4 +36,8 @@ describe('OGC API Features tests', () => {
})
})

it('feature page should have no broken links', () => {
cy.visit('/collections/addresses/items/1')
cy.checkForBrokenLinks()
})
})
20 changes: 20 additions & 0 deletions tests/cypress/e2e/styles.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
describe('OGC API Styles tests', () => {

// Fix for https://github.com/cypress-io/cypress/issues/1502#issuecomment-832403402
Cypress.on("window:before:load", () => {
cy.state("jQuery", Cypress.$);
});

it('styles page should have no a11y violations', () => {
cy.visit('/styles')
cy.injectAxe()
Expand All @@ -11,6 +16,11 @@ describe('OGC API Styles tests', () => {
cy.htmlvalidate();
})

it('styles page should have no broken links', () => {
cy.visit('/styles')
cy.checkForBrokenLinks()
})

it('style page should have no a11y violations', () => {
cy.visit('/styles/dummy-style')
cy.injectAxe()
Expand All @@ -22,6 +32,11 @@ describe('OGC API Styles tests', () => {
cy.htmlvalidate();
})

it('style page should have no broken links', () => {
cy.visit('/styles/dummy-style')
cy.checkForBrokenLinks()
})

it('styles metadata page should have no a11y violations', () => {
cy.visit('/styles/dummy-style/metadata')
cy.injectAxe()
Expand All @@ -32,4 +47,9 @@ describe('OGC API Styles tests', () => {
cy.visit("/styles/dummy-style/metadata");
cy.htmlvalidate();
})

it('styles metadata page should have no broken links', () => {
cy.visit('/styles/dummy-style/metadata')
cy.checkForBrokenLinks()
})
})
37 changes: 36 additions & 1 deletion tests/cypress/e2e/tiles.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
describe('OGC API Tiles tests', () => {

// Fix for https://github.com/cypress-io/cypress/issues/1502#issuecomment-832403402
Cypress.on("window:before:load", () => {
cy.state("jQuery", Cypress.$);
});

it('dataset tiles page should have no a11y violations', () => {
cy.visit('/tiles')
cy.injectAxe()
Expand All @@ -11,6 +16,11 @@ describe('OGC API Tiles tests', () => {
cy.htmlvalidate();
})

it('dataset tiles page should have no broken links', () => {
cy.visit('/tiles')
cy.checkForBrokenLinks()
})

it('dataset tiles metadata page should have no a11y violations', () => {
cy.visit('/tiles/NetherlandsRDNewQuad')
cy.injectAxe()
Expand All @@ -22,6 +32,11 @@ describe('OGC API Tiles tests', () => {
cy.htmlvalidate();
})

it('dataset tiles metadata page should have no broken links', () => {
cy.visit('/tiles/NetherlandsRDNewQuad')
cy.checkForBrokenLinks()
})

it('geodata tiles page (collection-level) should have no a11y violations', () => {
cy.visit('/collections/addresses/tiles')
cy.injectAxe()
Expand All @@ -33,17 +48,27 @@ describe('OGC API Tiles tests', () => {
cy.htmlvalidate();
})

it('geodata tiles page should have no broken links', () => {
cy.visit('/collections/addresses/tiles')
cy.checkForBrokenLinks()
})

it('geodata tiles metadata page (collection-level) should have no a11y violations', () => {
cy.visit('/collections/addresses/tiles/NetherlandsRDNewQuad')
cy.injectAxe()
cy.checkA11y()
})

it("geodata tiles metadata page should have valid HTML", () => {
cy.visit("/collections/addresses/tiles/NetherlandsRDNewQuad");
cy.visit('/collections/addresses/tiles/NetherlandsRDNewQuad');
cy.htmlvalidate();
})

it('geodata tiles metadata page should have no broken links', () => {
cy.visit('/collections/addresses/tiles/NetherlandsRDNewQuad')
cy.checkForBrokenLinks()
})

it('tileMatrixSets page should have no a11y violations', () => {
cy.visit('/tileMatrixSets')
cy.injectAxe()
Expand All @@ -55,6 +80,11 @@ describe('OGC API Tiles tests', () => {
cy.htmlvalidate();
})

it('tileMatrixSets page should have no broken links', () => {
cy.visit('/tileMatrixSets')
cy.checkForBrokenLinks()
})

it('specific tileMatrixSet (NetherlandsRDNewQuad) page should have no a11y violations', () => {
cy.visit('/tileMatrixSets/NetherlandsRDNewQuad')
cy.injectAxe()
Expand All @@ -65,4 +95,9 @@ describe('OGC API Tiles tests', () => {
cy.visit("/tileMatrixSets/NetherlandsRDNewQuad");
cy.htmlvalidate();
})

it('specific tileMatrixSet (NetherlandsRDNewQuad) page should have no broken links', () => {
cy.visit('/tileMatrixSets/NetherlandsRDNewQuad')
cy.checkForBrokenLinks()
})
})
19 changes: 18 additions & 1 deletion tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,21 @@
// }
// }

import 'cypress-axe'
import 'cypress-axe'

declare global {
namespace Cypress {
interface Chainable {
checkForBrokenLinks(): Chainable<void>
}
}
}

Cypress.Commands.add('checkForBrokenLinks', () =>{
cy.get('a').each(link => {
const href = link.prop('href')
if (href && !href.includes('example.com') && !href.includes('europa.eu')) {
cy.request(href)
}
})
})

0 comments on commit 074764d

Please sign in to comment.