1
1
import { enableI18n , event } from '../test-util' ;
2
2
3
- import { readit , rdfs , skos } from './../common-rdf/ns' ;
3
+ import View from '../core/view' ;
4
+ import { readit , rdfs , skos } from '../common-rdf/ns' ;
4
5
import { FlatLdObject } from '../common-rdf/json' ;
5
6
import Node from '../common-rdf/node' ;
6
7
import FlatItem from '../common-adapters/flat-item-model' ;
7
8
8
- import { Tooltip } from './tooltip-view' ;
9
-
10
- function getDefaultItem ( ) : FlatItem {
11
- return new FlatItem ( new Node ( getDefaultAttributes ( ) ) ) ;
12
- }
9
+ import attachTooltip , { Tooltip } from './tooltip-view' ;
13
10
14
11
function getDefaultAttributes ( ) : FlatLdObject {
15
12
return {
@@ -19,25 +16,73 @@ function getDefaultAttributes(): FlatLdObject {
19
16
{ '@value' : 'Content' } ,
20
17
] ,
21
18
[ skos . altLabel ] : [
22
- { '@value' : 'alternativeLabel' }
19
+ { '@value' : 'alternativeLabel' }
23
20
] ,
24
21
[ skos . definition ] : [
25
- { '@value' : 'This is a test definition' }
26
- ]
22
+ { '@value' : 'This is a test definition' }
23
+ ] ,
24
+ [ rdfs . comment ] : [
25
+ { '@value' : 'Also, I have a comment' }
26
+ ] ,
27
27
}
28
28
}
29
29
30
+ function getDefaultItem ( ) : FlatItem {
31
+ return new FlatItem ( new Node ( getDefaultAttributes ( ) ) ) ;
32
+ }
33
+
30
34
describe ( 'Tooltip' , function ( ) {
31
35
beforeAll ( enableI18n ) ;
32
36
33
- beforeEach ( async function ( ) {
37
+ beforeEach ( function ( ) {
34
38
this . item = getDefaultItem ( ) ;
39
+ this . substrate = new View ( ) ;
40
+ this . substrate . $el
41
+ . html ( '<ul><li>A<li id=x>B<li>C</ul>' )
42
+ . appendTo ( document . body ) ;
43
+ } ) ;
35
44
45
+ afterEach ( function ( ) {
46
+ this . substrate . remove ( ) ;
36
47
} ) ;
37
48
38
49
it ( 'includes the definition if it exists' , async function ( ) {
39
- let view = new Tooltip ( { model : this . item } ) ;
50
+ const view = new Tooltip ( { model : this . item } ) ;
40
51
await event ( this . item , 'complete' ) ;
52
+ expect ( view . el ) . toHaveClass ( 'tooltip' ) ;
41
53
expect ( view . $el . data ( 'tooltip' ) ) . toEqual ( 'This is a test definition' ) ;
42
54
} ) ;
55
+
56
+ it ( 'uses rdfs:comment otherwise' , async function ( ) {
57
+ this . item . underlying . unset ( skos . definition ) ;
58
+ const view = new Tooltip ( { model : this . item } ) ;
59
+ await event ( this . item , 'complete' ) ;
60
+ expect ( view . el ) . toHaveClass ( 'tooltip' ) ;
61
+ expect ( view . $el . data ( 'tooltip' ) ) . toEqual ( 'Also, I have a comment' ) ;
62
+ } ) ;
63
+
64
+ it ( 'disables itself when definition and comment are absent' , async function ( ) {
65
+ this . item . underlying . unset ( skos . definition ) ;
66
+ this . item . underlying . unset ( rdfs . comment ) ;
67
+ const view = new Tooltip ( { model : this . item } ) ;
68
+ await event ( this . item , 'complete' ) ;
69
+ expect ( view . $el . data ( 'tooltip' ) ) . not . toBeDefined ( ) ;
70
+ expect ( view . el ) . not . toHaveClass ( 'tooltip' ) ;
71
+ } ) ;
72
+
73
+ it ( 'can be attached to another view' , function ( ) {
74
+ const view = attachTooltip ( this . substrate , { model : this . item } ) ;
75
+ spyOn ( view , 'remove' ) . and . callThrough ( ) ;
76
+ expect ( view . el ) . not . toHaveClass ( 'is-tooltip-active' ) ;
77
+ this . substrate . $el . trigger ( 'mouseenter' ) ;
78
+ expect ( view . el ) . toHaveClass ( 'is-tooltip-active' ) ;
79
+ expect ( view . $el . offset ( ) ) . toEqual ( this . substrate . $el . offset ( ) ) ;
80
+ expect ( view . $el . width ( ) ) . toEqual ( this . substrate . $el . width ( ) ) ;
81
+ expect ( view . $el . height ( ) ) . toEqual ( this . substrate . $el . height ( ) ) ;
82
+ this . substrate . $el . trigger ( 'mouseleave' ) ;
83
+ expect ( view . el ) . not . toHaveClass ( 'is-tooltip-active' ) ;
84
+ expect ( view . remove ) . not . toHaveBeenCalled ( ) ;
85
+ this . substrate . remove ( ) ;
86
+ expect ( view . remove ) . toHaveBeenCalled ( ) ;
87
+ } ) ;
43
88
} ) ;
0 commit comments