annotate web/resource-display_test.html @ 2440:d1f86109e3cc

more *value getter variants
author drewp@bigasterisk.com
date Thu, 30 May 2024 01:08:45 -0700
parents 4556eebe5d73
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1711
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
1 <!doctype html>
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
2 <html>
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
3 <head>
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
4 <title>resource-display test</title>
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
5 <meta charset="utf-8">
1714
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
6 <script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
1711
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
7 <script src="/node_modules/mocha/mocha.js"></script>
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
8 <script src="/node_modules/chai/chai.js"></script>
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
9
1714
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
10 <link rel="stylesheet" media="all" href="/node_modules/mocha/mocha.css">
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
11 <link rel="import" href="/lib/polymer/lib/elements/dom-bind.html">
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
12
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
13 <link rel="import" href="rdfdb-synced-graph.html">
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
14 <link rel="import" href="resource-display.html">
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
15 </head>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
16 <body>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
17 <div id="mocha"><p><a href=".">Index</a></p></div>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
18 <div id="messages"></div>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
19 <div id="fixtures">
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
20 <dom-bind>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
21 <template>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
22 <p>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
23 <rdfdb-synced-graph id="graph" test-graph="true" graph="{{graph}}"></rdfdb-synced-graph>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
24 </p>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
25 <p>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
26 resource: <resource-display
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
27 id="elem"
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
28 graph="{{graph}}"
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
29 uri="http://example.com/a"></resource-display>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
30 </p>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
31 </template>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
32 </dom-bind>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
33 </div>
1711
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
34
1714
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
35 <script>
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
36 mocha.setup('bdd')
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
37 const assert = chai.assert;
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
38
1711
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
39 describe("resource-display", () => {
1714
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
40 let elem;
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
41 let graph;
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
42 beforeEach((done) => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
43 elem = document.querySelector("#elem");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
44 window.elem = elem;
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
45 graph = document.querySelector("#graph");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
46 graph.graph.clearGraph();
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
47 graph.graph.loadTrig(`
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
48 @prefix : <http://example.com/> .
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
49 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
50 :a rdfs:label "label a" :ctx .
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
51 :b rdfs:label "label b" :ctx .
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
52 `, done);
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
53 });
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
54 const assertLabelTextEquals = (expected) => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
55 assert.equal(elem.shadowRoot.querySelector("#uri").innerText,
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
56 expected);
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
57
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
58 };
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
59 describe('link display', () => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
60 it("says no uri", () => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
61 elem.setAttribute('uri', '');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
62 assertLabelTextEquals("<no uri>");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
63 });
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
64 it("has no link when there's no uri", () => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
65 elem.setAttribute('uri', '');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
66 assert.equal(elem.shadowRoot.querySelector("#uri").href,
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
67 'javascript:;');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
68 });
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
69 it("shows uri's label if graph has one", () => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
70 elem.setAttribute('uri', 'http://example.com/a');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
71 assertLabelTextEquals("label a");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
72 });
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
73 it("links to uri", () => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
74 elem.setAttribute('uri', 'http://example.com/a');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
75 assert.equal(elem.shadowRoot.querySelector("#uri").href,
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
76 'http://example.com/a');
1711
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
77 });
1714
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
78 it("falls back to uri tail if there's no label", () => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
79 elem.setAttribute('uri', 'http://example.com/nolabel');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
80 assertLabelTextEquals("nolabel");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
81 });
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
82 it("falls back to full uri if the tail would be empty", () => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
83 elem.setAttribute('uri', 'http://example.com/');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
84 assertLabelTextEquals('http://example.com/');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
85
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
86 });
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
87 it("changes the label if the graph updates uri's label", () => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
88 const g = graph.graph;
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
89 elem.setAttribute('uri', 'http://example.com/a');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
90
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
91 g.patchObject(g.Uri('http://example.com/a'),
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
92 g.Uri('rdfs:label'),
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
93 g.Literal('new label'));
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
94 assertLabelTextEquals('new label');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
95
1711
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
96 });
1714
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
97 it("changes the label if the uri changes", (done) => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
98 elem.setAttribute('uri', 'http://example.com/a');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
99 setTimeout(() => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
100 elem.setAttribute('uri', 'http://example.com/b');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
101 assertLabelTextEquals('label b');
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
102 done();
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
103 }, 100);
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
104 });
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
105 });
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
106 describe('type icons', () => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
107 it("omits icon for unknown type");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
108 it("uses icon uri from graph and shows the icon");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
109 });
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
110 describe('rename ui', () => {
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
111 it("shows rename button if caller wants");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
112 it("opens dialog when you click rename");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
113 it("shows old label in dialog, ready to be replaced");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
114 it("does nothing if you cancel");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
115 it("patches the graph if you accept a new name");
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
116 });
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
117
1711
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
118 });
1714
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
119 mocha.run();
f2265601ead6 edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents: 1711
diff changeset
120 </script>
1711
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
121 </body>
d6ad5c249820 start resource-display web test
drewp@bigasterisk.com
parents:
diff changeset
122 </html>