Mercurial > code > home > repos > streamed-graph
comparison src/layout/suffixLabels.test.ts @ 106:2468f2227d22
make src/layout/ and src/render/ separation
author | drewp@bigasterisk.com |
---|---|
date | Sun, 13 Mar 2022 22:00:30 -0700 |
parents | src/suffixLabels.test.ts@45ed53428e74 |
children |
comparison
equal
deleted
inserted
replaced
105:4bb8c7775c83 | 106:2468f2227d22 |
---|---|
1 import { SuffixLabels } from './suffixLabels'; | |
2 | |
3 describe('_tailSegments', () => { | |
4 it("returns right amount", () => { | |
5 expect(SuffixLabels._tailSegments('http://foo/a/bb', 0)).toEqual(''); | |
6 expect(SuffixLabels._tailSegments('http://foo/a/bb', 1)).toEqual('bb'); | |
7 expect(SuffixLabels._tailSegments('http://foo/a/bb', 2)).toEqual('a/bb'); | |
8 expect(SuffixLabels._tailSegments('http://foo/a/bb', 3)).toEqual('foo/a/bb'); | |
9 expect(SuffixLabels._tailSegments('http://foo/a/bb', 4)).toEqual('/foo/a/bb'); | |
10 expect(SuffixLabels._tailSegments('http://foo/a/bb', 5)).toEqual('http://foo/a/bb'); | |
11 }); | |
12 it("_tailSegments ok with trailing slash", () => { | |
13 expect(SuffixLabels._tailSegments('http://foo/', 0)).toEqual(''); | |
14 expect(SuffixLabels._tailSegments('http://foo/', 1)).toEqual(''); | |
15 expect(SuffixLabels._tailSegments('http://foo/', 2)).toEqual('foo/'); | |
16 }); | |
17 }); | |
18 | |
19 describe("suffixLabels", () => { | |
20 const fakeNode = (uri: string) => { return { nominalValue: uri } }; | |
21 | |
22 it("returns whole url segments", () => { | |
23 const suf = new SuffixLabels(); | |
24 suf._planDisplayForUri('http://a/b/c/dd'); | |
25 suf._planDisplayForUri('http://a/b/c/ee'); | |
26 | |
27 expect(suf.getLabelForNode('http://a/b/c/dd')).toEqual('dd'); | |
28 expect(suf.getLabelForNode('http://a/b/c/ee')).toEqual('ee'); | |
29 }); | |
30 | |
31 it("doesn't treat a repeated uri as a name clash", () => { | |
32 const suf = new SuffixLabels(); | |
33 suf._planDisplayForUri('http://a/b/c'); | |
34 suf._planDisplayForUri('http://a/b/c'); | |
35 | |
36 expect(suf.getLabelForNode('http://a/b/c')).toEqual('c'); | |
37 }); | |
38 | |
39 it("moves to two segments when needed", () => { | |
40 const suf = new SuffixLabels(); | |
41 suf._planDisplayForUri('http://a/b/c/d'); | |
42 suf._planDisplayForUri('http://a/b/f/d'); | |
43 | |
44 expect(suf.getLabelForNode('http://a/b/c/d')).toEqual('c/d'); | |
45 expect(suf.getLabelForNode('http://a/b/f/d')).toEqual('f/d'); | |
46 }); | |
47 | |
48 it("is ok with clashes at different segment positions", () => { | |
49 const suf = new SuffixLabels(); | |
50 suf._planDisplayForUri('http://z/z/z/a/b/c'); | |
51 suf._planDisplayForUri('http://a/b/c'); | |
52 | |
53 expect(suf.getLabelForNode('http://z/z/z/a/b/c')).toEqual('z/a/b/c'); | |
54 expect(suf.getLabelForNode('http://a/b/c')).toEqual('/a/b/c'); | |
55 }); | |
56 | |
57 it("uses appropriately long suffixes per uri", () => { | |
58 const suf = new SuffixLabels(); | |
59 suf._planDisplayForUri('http://a/b/c/d/e'); | |
60 suf._planDisplayForUri('http://a/b/f/d/e'); | |
61 suf._planDisplayForUri('http://a/b/c/g'); | |
62 suf._planDisplayForUri('http://a/z'); | |
63 | |
64 expect(suf.getLabelForNode('http://a/b/c/d/e')).toEqual('c/d/e'); | |
65 expect(suf.getLabelForNode('http://a/b/f/d/e')).toEqual('f/d/e'); | |
66 expect(suf.getLabelForNode('http://a/b/c/g')).toEqual('g'); | |
67 expect(suf.getLabelForNode('http://a/z')).toEqual('z'); | |
68 }); | |
69 | |
70 }); |