-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from hypermedia-app/label-blank-no-link
fix: not links to blank nodes
- Loading branch information
Showing
4 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hydrofoil/roadshow": patch | ||
--- | ||
|
||
`dash:LabelViewer` should not render link for blank nodes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hydrofoil/roadshow": patch | ||
--- | ||
|
||
`dash:LabelViewer`: correct precedence of predicates (`skos:xLabel`, then `schema:name`, `rdfs:label` last) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
import { dash, rdfs, schema, skos } from '@tpluscode/rdf-ns-builders' | ||
import { html } from 'lit' | ||
import { NamedNode } from '@rdfjs/types' | ||
import { Renderer } from '../index' | ||
|
||
export const Label: Renderer = { | ||
interface LabelRenderer extends Renderer { | ||
predicates: NamedNode[] | ||
} | ||
|
||
export const Label: LabelRenderer = { | ||
viewer: dash.LabelViewer, | ||
render(resource) { | ||
const [label] = resource.out([rdfs.label, skos.prefLabel, schema.name], { language: [this.params.language, '*'] }).values | ||
const [label] = resource.out(Label.predicates, { language: [this.params.language, '*'] }).values | ||
|
||
const labelResult = html`${label || resource.value}` | ||
|
||
if (resource.term?.termType === 'BlankNode') { | ||
return labelResult | ||
} | ||
|
||
return html`<a href="${resource.values[0]}">${label || resource.value}</a>` | ||
return html`<a href="${resource.values[0]}">${labelResult}</a>` | ||
}, | ||
predicates: [skos.prefLabel, skos.altLabel, schema.name, rdfs.label], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { expect, fixture, html } from '@open-wc/testing' | ||
import { rdfs, schema, skos } from '@tpluscode/rdf-ns-builders/strict' | ||
import { Label } from '../../renderers/Label' | ||
import { blankNode, namedNode } from '../_support/clownface' | ||
import { ViewContext } from '../../lib/ViewContext/index' | ||
|
||
describe('@hydrofoil/roadshow/renderers/Label', () => { | ||
let context: ViewContext<any> | ||
|
||
beforeEach(() => { | ||
context = { | ||
params: { | ||
language: 'en', | ||
}, | ||
} as any | ||
}) | ||
|
||
it('should not render anchor when value is a BlankNode', async () => { | ||
// given | ||
const pointer = blankNode() | ||
.addOut(rdfs.label, 'foo') | ||
|
||
// when | ||
const result = await fixture(html`<div>${Label.render.call(context, pointer)}</div>`) | ||
|
||
// then | ||
expect(result).dom.to.eq('<div>foo</div>') | ||
}) | ||
|
||
it('should use skos:prefLabel before skos:altLabel', async () => { | ||
// given | ||
const pointer = blankNode() | ||
.addOut(skos.prefLabel, 'foo') | ||
.addOut(skos.altLabel, 'bar') | ||
|
||
// when | ||
const result = await fixture(html`<div>${Label.render.call(context, pointer)}</div>`) | ||
|
||
// then | ||
expect(result).dom.to.eq('<div>foo</div>') | ||
}) | ||
|
||
it('should use skos:altLabel before rdfs:label', async () => { | ||
// given | ||
const pointer = blankNode() | ||
.addOut(rdfs.label, 'foo') | ||
.addOut(skos.altLabel, 'bar') | ||
|
||
// when | ||
const result = await fixture(html`<div>${Label.render.call(context, pointer)}</div>`) | ||
|
||
// then | ||
expect(result).dom.to.eq('<div>bar</div>') | ||
}) | ||
|
||
it('should use schema:name before rdfs:label', async () => { | ||
// given | ||
const pointer = blankNode() | ||
.addOut(rdfs.label, 'foo') | ||
.addOut(schema.name, 'bar') | ||
|
||
// when | ||
const result = await fixture(html`<div>${Label.render.call(context, pointer)}</div>`) | ||
|
||
// then | ||
expect(result).dom.to.eq('<div>bar</div>') | ||
}) | ||
|
||
it('should render anchor for named node', async () => { | ||
// given | ||
const pointer = namedNode('urn:foo:bar') | ||
.addOut(rdfs.label, 'baz') | ||
|
||
// when | ||
const result = await fixture(Label.render.call(context, pointer)) | ||
|
||
// then | ||
expect(result).dom.to.eq('<a href="urn:foo:bar">baz</a>') | ||
}) | ||
}) |