@triptease/tt-navbar 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/TtNavbar.js +3 -2
- package/dist/src/TtNavbar.js.map +1 -1
- package/dist/src/styles.js +7 -1
- package/dist/src/styles.js.map +1 -1
- package/dist/stories/index.stories.js +4 -2
- package/dist/stories/index.stories.js.map +1 -1
- package/dist/test/tt-navbar.test.js +17 -8
- package/dist/test/tt-navbar.test.js.map +1 -1
- package/dist/web/TtNavbar.js +11 -4
- package/dist/web/TtNavbar.js.map +2 -2
- package/dist/web/index.js +11 -4
- package/dist/web/index.js.map +2 -2
- package/dist/web/styles.js +8 -2
- package/dist/web/styles.js.map +2 -2
- package/dist/web/tt-navbar.js +11 -4
- package/dist/web/tt-navbar.js.map +2 -2
- package/package.json +1 -1
- package/src/TtNavbar.ts +3 -2
- package/src/styles.ts +7 -1
- package/stories/index.stories.ts +4 -5
- package/test/tt-navbar.test.ts +42 -21
- package/demo/index.html +0 -30
package/package.json
CHANGED
package/src/TtNavbar.ts
CHANGED
|
@@ -8,10 +8,10 @@ export class TtNavbar extends LitElement {
|
|
|
8
8
|
@property({ type: Function })
|
|
9
9
|
navigate: ((e: MouseEvent) => void) | undefined;
|
|
10
10
|
|
|
11
|
-
@property({ type: String })
|
|
11
|
+
@property({ type: String, attribute: 'base-url' })
|
|
12
12
|
baseUrl?: string;
|
|
13
13
|
|
|
14
|
-
@property({ type: String })
|
|
14
|
+
@property({ type: String, attribute: 'client-key' })
|
|
15
15
|
clientKey?: string;
|
|
16
16
|
|
|
17
17
|
private buildUrl = (path: string): string => {
|
|
@@ -106,6 +106,7 @@ export class TtNavbar extends LitElement {
|
|
|
106
106
|
>
|
|
107
107
|
</div>
|
|
108
108
|
</details>
|
|
109
|
+
<slot name="clientSelector"></slot>
|
|
109
110
|
</nav>
|
|
110
111
|
`;
|
|
111
112
|
}
|
package/src/styles.ts
CHANGED
package/stories/index.stories.ts
CHANGED
|
@@ -6,15 +6,14 @@ export default {
|
|
|
6
6
|
component: 'tt-navbar',
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
9
|
const Template = () => html`
|
|
13
10
|
<div>
|
|
14
|
-
<tt-navbar
|
|
11
|
+
<tt-navbar client-key="zxd47KQGAP">
|
|
12
|
+
<div slot="clientSelector">
|
|
13
|
+
<p>My Cool Client Selector</p>
|
|
14
|
+
</div>
|
|
15
15
|
</tt-navbar>
|
|
16
16
|
</div>
|
|
17
|
-
|
|
18
17
|
`;
|
|
19
18
|
|
|
20
19
|
export const Regular = Template.bind({});
|
package/test/tt-navbar.test.ts
CHANGED
|
@@ -3,59 +3,65 @@ import { expect, fixture, waitUntil } from '@open-wc/testing';
|
|
|
3
3
|
import { TtNavbar } from '../src/index.js';
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line no-undef
|
|
6
|
-
const getLinkByHref = (links:
|
|
7
|
-
for(const link of links) {
|
|
8
|
-
if(link.getAttribute('href') === href) {
|
|
6
|
+
const getLinkByHref = (links: NodeListOf<HTMLAnchorElement>, href: string) => {
|
|
7
|
+
for (const link of links) {
|
|
8
|
+
if (link.getAttribute('href') === href) {
|
|
9
9
|
return link;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
return undefined
|
|
14
|
-
}
|
|
13
|
+
return undefined;
|
|
14
|
+
};
|
|
15
15
|
|
|
16
16
|
const CLIENT_KEY = 'zxd47KQGAP';
|
|
17
17
|
|
|
18
18
|
describe('TtNavbar', () => {
|
|
19
|
-
|
|
20
|
-
it("should throw an error if the clientKey is not provided", async () => {
|
|
19
|
+
it('should throw an error if the clientKey is not provided', async () => {
|
|
21
20
|
try {
|
|
22
21
|
await fixture<TtNavbar>(`<tt-navbar></tt-navbar>`);
|
|
23
|
-
} catch(e) {
|
|
22
|
+
} catch (e) {
|
|
24
23
|
expect(e).to.match(/clientKey is required/);
|
|
25
24
|
}
|
|
26
|
-
})
|
|
25
|
+
});
|
|
27
26
|
it('should render with the default links', async () => {
|
|
28
|
-
const navbar = await fixture<TtNavbar>(
|
|
27
|
+
const navbar = await fixture<TtNavbar>(
|
|
28
|
+
`<tt-navbar client-key=${CLIENT_KEY}></tt-navbar>`,
|
|
29
|
+
);
|
|
29
30
|
const links = navbar.shadowRoot?.querySelectorAll('a');
|
|
30
31
|
|
|
31
32
|
expect(links?.length).to.equal(13);
|
|
32
33
|
|
|
33
|
-
if(links) {
|
|
34
|
+
if (links) {
|
|
34
35
|
expect(getLinkByHref(links, '/')).to.exist;
|
|
35
|
-
expect(getLinkByHref(links, 'https://app.campaign-manager.triptease.io'))
|
|
36
|
+
expect(getLinkByHref(links, 'https://app.campaign-manager.triptease.io'))
|
|
37
|
+
.to.exist;
|
|
36
38
|
expect(getLinkByHref(links, '/channels')).to.exist;
|
|
37
39
|
expect(getLinkByHref(links, `/parity/${CLIENT_KEY}`)).to.exist;
|
|
38
40
|
expect(getLinkByHref(links, `/guest-insights/${CLIENT_KEY}`)).to.exist;
|
|
39
|
-
expect(getLinkByHref(links, `/${CLIENT_KEY}/guest-behavioural-data`)).to
|
|
41
|
+
expect(getLinkByHref(links, `/${CLIENT_KEY}/guest-behavioural-data`)).to
|
|
42
|
+
.exist;
|
|
40
43
|
expect(getLinkByHref(links, `/${CLIENT_KEY}/crm-config`)).to.exist;
|
|
41
44
|
expect(getLinkByHref(links, `/settings/group`)).to.exist;
|
|
42
45
|
expect(getLinkByHref(links, `/settings/${CLIENT_KEY}/hotels/`)).to.exist;
|
|
43
46
|
expect(getLinkByHref(links, `/account`)).to.exist;
|
|
44
47
|
expect(getLinkByHref(links, `/account/team/${CLIENT_KEY}`)).to.exist;
|
|
45
|
-
expect(getLinkByHref(links, `/account/billing-management/${CLIENT_KEY}`))
|
|
48
|
+
expect(getLinkByHref(links, `/account/billing-management/${CLIENT_KEY}`))
|
|
49
|
+
.to.exist;
|
|
46
50
|
expect(getLinkByHref(links, `/subscriptions/${CLIENT_KEY}`)).to.exist;
|
|
47
51
|
}
|
|
48
|
-
|
|
49
52
|
});
|
|
50
53
|
|
|
51
54
|
it('should render platform URLs against the base URL when it is defined', async () => {
|
|
52
55
|
const baseUrl = 'https://app.triptease.io';
|
|
53
|
-
const navbar = await fixture<TtNavbar>(
|
|
56
|
+
const navbar = await fixture<TtNavbar>(
|
|
57
|
+
`<tt-navbar client-key=${CLIENT_KEY} base-url="${baseUrl}"></tt-navbar>`,
|
|
58
|
+
);
|
|
54
59
|
const links = navbar.shadowRoot?.querySelectorAll('a');
|
|
55
60
|
|
|
56
|
-
if(links) {
|
|
61
|
+
if (links) {
|
|
57
62
|
expect(getLinkByHref(links, `${baseUrl}/`)).to.exist;
|
|
58
|
-
expect(getLinkByHref(links, 'https://app.campaign-manager.triptease.io'))
|
|
63
|
+
expect(getLinkByHref(links, 'https://app.campaign-manager.triptease.io'))
|
|
64
|
+
.to.exist; // This shouldn't change
|
|
59
65
|
expect(getLinkByHref(links, `${baseUrl}/channels`)).to.exist;
|
|
60
66
|
}
|
|
61
67
|
});
|
|
@@ -66,15 +72,30 @@ describe('TtNavbar', () => {
|
|
|
66
72
|
const onNavigate = (e: MouseEvent) => {
|
|
67
73
|
e.preventDefault();
|
|
68
74
|
navigateEventCount += 1;
|
|
69
|
-
}
|
|
75
|
+
};
|
|
70
76
|
|
|
71
|
-
const navbar = await fixture<TtNavbar>(
|
|
77
|
+
const navbar = await fixture<TtNavbar>(
|
|
78
|
+
`<tt-navbar client-key=${CLIENT_KEY}></tt-navbar>`,
|
|
79
|
+
);
|
|
72
80
|
navbar.navigate = onNavigate;
|
|
73
81
|
await navbar.updateComplete;
|
|
74
82
|
|
|
75
83
|
const links = navbar.shadowRoot?.querySelectorAll('a');
|
|
76
84
|
links?.forEach(l => l.click());
|
|
77
85
|
|
|
78
|
-
await waitUntil(
|
|
86
|
+
await waitUntil(
|
|
87
|
+
() => expect(navigateEventCount).to.equal(12),
|
|
88
|
+
'navigate event did not fire',
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should render the given client selector', async () => {
|
|
93
|
+
const navbar = await fixture<TtNavbar>(
|
|
94
|
+
`<tt-navbar client-key=${CLIENT_KEY}><div slot="clientSelector"><div id="myCoolClientSelector"></div></div></tt-navbar>`,
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const clientSelector = navbar.querySelector('#myCoolClientSelector');
|
|
98
|
+
|
|
99
|
+
expect(clientSelector).to.exist;
|
|
79
100
|
});
|
|
80
101
|
});
|
package/demo/index.html
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en-GB">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
|
6
|
-
<style>
|
|
7
|
-
body {
|
|
8
|
-
background: #fafafa;
|
|
9
|
-
}
|
|
10
|
-
</style>
|
|
11
|
-
</head>
|
|
12
|
-
<body>
|
|
13
|
-
<div id="demo"></div>
|
|
14
|
-
|
|
15
|
-
<script type="module">
|
|
16
|
-
import { html, render } from 'lit';
|
|
17
|
-
import '../dist/src/tt-navbar.js';
|
|
18
|
-
|
|
19
|
-
const header = 'Hello owc World!';
|
|
20
|
-
render(
|
|
21
|
-
html`
|
|
22
|
-
<tt-navbar .header=${header}>
|
|
23
|
-
some light-dom
|
|
24
|
-
</tt-navbar>
|
|
25
|
-
`,
|
|
26
|
-
document.querySelector('#demo')
|
|
27
|
-
);
|
|
28
|
-
</script>
|
|
29
|
-
</body>
|
|
30
|
-
</html>
|