diff src/suffixLabels_test.html @ 3:a7ba8627a7b6

still trying to make imports work. add other files too
author drewp@bigasterisk.com
date Wed, 04 Dec 2019 00:09:15 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/suffixLabels_test.html	Wed Dec 04 00:09:15 2019 -0800
@@ -0,0 +1,91 @@
+<!doctype html>
+<html>
+  <head>
+    <title>suffixLabels_test</title>
+    <meta charset="utf-8" />
+    <link rel="shortcut icon" type="image/png" href="/lib/jasmine/3.4.0/jasmine_favicon.png">
+    <link rel="stylesheet" type="text/css" href="/lib/jasmine/3.4.0/jasmine.css">
+
+    <script type="text/javascript" src="/lib/jasmine/3.4.0/jasmine.js"></script>
+    <script type="text/javascript" src="/lib/jasmine/3.4.0/jasmine-html.js"></script>
+    <script type="text/javascript" src="/lib/jasmine/3.4.0/boot.js"></script>
+
+    <script type="module">
+
+     import { SuffixLabels } from './suffixLabels.js';
+
+     describe("_tailSegments", function() {
+       it("returns right amount", function() {
+         expect(SuffixLabels._tailSegments('http://foo/a/bb', 0)).toEqual('');
+         expect(SuffixLabels._tailSegments('http://foo/a/bb', 1)).toEqual('bb');
+         expect(SuffixLabels._tailSegments('http://foo/a/bb', 2)).toEqual('a/bb');
+         expect(SuffixLabels._tailSegments('http://foo/a/bb', 3)).toEqual('foo/a/bb');
+         expect(SuffixLabels._tailSegments('http://foo/a/bb', 4)).toEqual('/foo/a/bb');
+         expect(SuffixLabels._tailSegments('http://foo/a/bb', 5)).toEqual('http://foo/a/bb');
+       });
+       it("ok with trailing slash", function() {
+         expect(SuffixLabels._tailSegments('http://foo/', 0)).toEqual('');
+         expect(SuffixLabels._tailSegments('http://foo/', 1)).toEqual('');
+         expect(SuffixLabels._tailSegments('http://foo/', 2)).toEqual('foo/');
+       });
+     });
+
+     describe("suffixLabels", function() {
+       const fakeNode = (uri) => { return { nominalValue: uri } };
+
+       it("returns whole url segments", function() {
+         const suf = new SuffixLabels();
+         suf._planDisplayForUri('http://a/b/c/dd');
+         suf._planDisplayForUri('http://a/b/c/ee');
+
+         expect(suf.getLabelForNode(fakeNode('http://a/b/c/dd'))).toEqual('dd');
+         expect(suf.getLabelForNode(fakeNode('http://a/b/c/ee'))).toEqual('ee');
+       });
+
+       it("doesn't treat a repeated uri as a name clash", function() {
+         const suf = new SuffixLabels();
+         suf._planDisplayForUri('http://a/b/c');
+         suf._planDisplayForUri('http://a/b/c');
+
+         expect(suf.getLabelForNode(fakeNode('http://a/b/c'))).toEqual('c');
+       });
+
+       it("moves to two segments when needed", function() {
+         const suf = new SuffixLabels();
+         suf._planDisplayForUri('http://a/b/c/d');
+         suf._planDisplayForUri('http://a/b/f/d');
+
+         expect(suf.getLabelForNode(fakeNode('http://a/b/c/d'))).toEqual('c/d');
+         expect(suf.getLabelForNode(fakeNode('http://a/b/f/d'))).toEqual('f/d');
+       });
+
+       it("is ok with clashes at different segment positions", function() {
+         const suf = new SuffixLabels();
+         suf._planDisplayForUri('http://z/z/z/a/b/c');
+         suf._planDisplayForUri('http://a/b/c');
+
+         expect(suf.getLabelForNode(fakeNode('http://z/z/z/a/b/c'))).toEqual('z/a/b/c');
+         expect(suf.getLabelForNode(fakeNode('http://a/b/c'))).toEqual('/a/b/c');
+       });
+
+       it("uses appropriately long suffixes per uri", function() {
+         const suf = new SuffixLabels();
+         suf._planDisplayForUri('http://a/b/c/d/e');
+         suf._planDisplayForUri('http://a/b/f/d/e');
+         suf._planDisplayForUri('http://a/b/c/g');
+         suf._planDisplayForUri('http://a/z');
+
+         expect(suf.getLabelForNode(fakeNode('http://a/b/c/d/e'))).toEqual('c/d/e');
+         expect(suf.getLabelForNode(fakeNode('http://a/b/f/d/e'))).toEqual('f/d/e');
+         expect(suf.getLabelForNode(fakeNode('http://a/b/c/g'))).toEqual('g');
+         expect(suf.getLabelForNode(fakeNode('http://a/z'))).toEqual('z');
+       });
+
+     });
+    </script>
+
+  </head>
+  <body>
+
+  </body>
+</html>