|
| 1 | +import { enableI18n, event } from '../test-util'; |
| 2 | + |
| 3 | +import { readit, rdfs, skos } from '../common-rdf/ns'; |
| 4 | +import { FlatLdObject } from '../common-rdf/json'; |
| 5 | +import Node from '../common-rdf/node'; |
| 6 | +import FlatItem from '../common-adapters/flat-item-model'; |
| 7 | + |
| 8 | +import toTooltip from './tooltip-model'; |
| 9 | + |
| 10 | +function getDefaultAttributes(): FlatLdObject { |
| 11 | + return { |
| 12 | + '@id': readit('test'), |
| 13 | + "@type": [rdfs.Class], |
| 14 | + [skos.prefLabel]: [ |
| 15 | + { '@value': 'Content' }, |
| 16 | + ], |
| 17 | + [skos.altLabel]: [ |
| 18 | + { '@value': 'alternativeLabel' } |
| 19 | + ], |
| 20 | + [skos.definition]: [ |
| 21 | + { '@value': 'This is a test definition' } |
| 22 | + ], |
| 23 | + [rdfs.comment]: [ |
| 24 | + { '@value': 'Also, I have a comment' } |
| 25 | + ], |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +function getDefaultItem(): FlatItem { |
| 30 | + return new FlatItem(new Node(getDefaultAttributes())); |
| 31 | +} |
| 32 | + |
| 33 | +describe('Tooltip model adapter', function () { |
| 34 | + beforeAll(enableI18n); |
| 35 | + |
| 36 | + beforeEach(function() { |
| 37 | + this.item = getDefaultItem(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('uses skos:definition if available', async function () { |
| 41 | + const model = toTooltip(this.item); |
| 42 | + await event(this.item, 'complete'); |
| 43 | + expect(model.get('text')).toEqual('This is a test definition'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('uses rdfs:comment otherwise', async function() { |
| 47 | + this.item.underlying.unset(skos.definition); |
| 48 | + const model = toTooltip(this.item); |
| 49 | + await event(this.item, 'complete'); |
| 50 | + expect(model.get('text')).toEqual('Also, I have a comment'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('unsets the text when definition and comment are absent', async function() { |
| 54 | + this.item.underlying.unset(skos.definition); |
| 55 | + this.item.underlying.unset(rdfs.comment); |
| 56 | + const model = toTooltip(this.item); |
| 57 | + await event(this.item, 'complete'); |
| 58 | + expect(model.has('text')).toBe(false); |
| 59 | + }); |
| 60 | +}); |
0 commit comments