@triptease/tt-navbar 0.0.4 → 0.0.6

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent tt-navbar following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "tt-navbar",
6
- "version": "0.0.4",
6
+ "version": "0.0.6",
7
7
  "type": "module",
8
8
  "main": "dist/src/index.js",
9
9
  "module": "dist/src/index.js",
package/src/TtNavbar.ts CHANGED
@@ -5,18 +5,108 @@ import { styles } from './styles.js';
5
5
  export class TtNavbar extends LitElement {
6
6
  static styles = styles;
7
7
 
8
- @property()
9
- onNavigate: (e: MouseEvent) => void = () => {
10
- // Do nothing by default
8
+ @property({ type: Function })
9
+ navigate: ((e: MouseEvent) => void) | undefined;
10
+
11
+ @property({ type: String })
12
+ baseUrl?: string;
13
+
14
+ @property({ type: String })
15
+ clientKey?: string;
16
+
17
+ private buildUrl = (path: string): string => {
18
+ if (!this.clientKey) throw new Error('clientKey is required');
19
+
20
+ const formattedPath = path.replace('$CLIENT_KEY', this.clientKey);
21
+ if (!this.baseUrl) return formattedPath;
22
+
23
+ return new URL(formattedPath, this.baseUrl).toString();
24
+ };
25
+
26
+ private onAnchorClick = (e: MouseEvent) => {
27
+ if (this.navigate) {
28
+ this.navigate(e);
29
+ }
11
30
  };
12
31
 
13
32
  render() {
14
33
  return html`
15
34
  <nav id=${this.id}>
16
- <a href="/">Dashboard</a>
17
- <a href="/campaigns">Campaigns</a>
18
- <a href="/channels">Channels</a>
19
- <a href="/guest-insights/zxd47KQGAP">Guest insights</a>
35
+ <a href=${this.buildUrl('/')} @click=${this.onAnchorClick}>Dashboard</a>
36
+ <a href="https://app.campaign-manager.triptease.io">Campaigns</a>
37
+ <a href=${this.buildUrl('/channels')} @click=${this.onAnchorClick}
38
+ >Channels</a
39
+ >
40
+ <details>
41
+ <summary>Market Insights</summary>
42
+ <div>
43
+ <a
44
+ href=${this.buildUrl('/parity/$CLIENT_KEY')}
45
+ @click=${this.onAnchorClick}
46
+ >Parity</a
47
+ >
48
+ <a
49
+ href=${this.buildUrl('/guest-insights/$CLIENT_KEY')}
50
+ @click=${this.onAnchorClick}
51
+ >Guest insights</a
52
+ >
53
+ </div>
54
+ </details>
55
+ <details>
56
+ <summary>Settings</summary>
57
+ <div>
58
+ <a
59
+ href=${this.buildUrl('/$CLIENT_KEY/guest-behavioural-data')}
60
+ @click=${this.onAnchorClick}
61
+ >Email setup</a
62
+ >
63
+ <a
64
+ href=${this.buildUrl('/$CLIENT_KEY/crm-config')}
65
+ @click=${this.onAnchorClick}
66
+ >CRM connectivity</a
67
+ >
68
+ <a
69
+ href=${this.buildUrl('/settings/group')}
70
+ @click=${this.onAnchorClick}
71
+ >Group settings</a
72
+ >
73
+ <a
74
+ href=${this.buildUrl('/settings/$CLIENT_KEY/hotels/')}
75
+ @click=${this.onAnchorClick}
76
+ >Property settings</a
77
+ >
78
+ </div>
79
+ </details>
80
+ <hr />
81
+ <details>
82
+ <summary>Account</summary>
83
+ <div>
84
+ <a href=${this.buildUrl('/account')} @click=${this.onAnchorClick}
85
+ >User settings</a
86
+ >
87
+ <a
88
+ href=${this.buildUrl('/account/team/$CLIENT_KEY')}
89
+ @click=${this.onAnchorClick}
90
+ >Team and permissions</a
91
+ >
92
+ </div>
93
+ </details>
94
+ <details>
95
+ <summary>Billing</summary>
96
+ <div>
97
+ <a
98
+ href=${this.buildUrl('/account/billing-management/$CLIENT_KEY')}
99
+ @click=${this.onAnchorClick}
100
+ >Booking reconciliation</a
101
+ >
102
+ <a
103
+ href=${this.buildUrl('/subscriptions/$CLIENT_KEY')}
104
+ @click=${this.onAnchorClick}
105
+ >Subscriptions</a
106
+ >
107
+ </div>
108
+ </details>
109
+ <slot name="clientSelector"></slot>
20
110
  </nav>
21
111
  `;
22
112
  }
package/src/styles.ts CHANGED
@@ -1,3 +1,21 @@
1
1
  import { css } from 'lit';
2
2
 
3
- export const styles = css``;
3
+ export const styles = css`
4
+ nav {
5
+ max-width: 260px;
6
+ display: flex;
7
+ flex-direction: column;
8
+ }
9
+
10
+ nav details div {
11
+ display: flex;
12
+ flex-direction: column;
13
+ }
14
+
15
+ hr {
16
+ background: black;
17
+ width: 100%;
18
+ height: 1px;
19
+ border: none;
20
+ }
21
+ `;
@@ -1,60 +1,23 @@
1
- import { html, TemplateResult } from 'lit';
1
+ import { html } from 'lit';
2
2
  import '../src/tt-navbar.js';
3
3
 
4
4
  export default {
5
5
  title: 'TtNavbar',
6
6
  component: 'tt-navbar',
7
- argTypes: {
8
- header: { control: 'text' },
9
- counter: { control: 'number' },
10
- textColor: { control: 'color' },
11
- },
12
7
  };
13
8
 
14
- interface Story<T> {
15
- (args: T): TemplateResult;
16
- args?: Partial<T>;
17
- argTypes?: Record<string, unknown>;
18
- }
19
9
 
20
- interface ArgTypes {
21
- header?: string;
22
- counter?: number;
23
- textColor?: string;
24
- slot?: TemplateResult;
25
- }
26
10
 
27
- const Template: Story<ArgTypes> = ({
28
- header = 'Hello world',
29
- counter = 5,
30
- textColor,
31
- slot,
32
- }: ArgTypes) => html`
33
- <tt-navbar
34
- style="--tt-navbar-text-color: ${textColor || 'black'}"
35
- .header=${header}
36
- .counter=${counter}
37
- >
38
- ${slot}
39
- </tt-navbar>
40
- `;
41
11
 
42
- export const Regular = Template.bind({});
12
+ const Template = () => html`
13
+ <div>
14
+ <tt-navbar clientKey="zxd47KQGAP">
15
+ <div slot="clientSelector">
16
+ <p>My Cool Client Selector</p>
17
+ </div>
18
+ </tt-navbar>
19
+ </div>
43
20
 
44
- export const CustomHeader = Template.bind({});
45
- CustomHeader.args = {
46
- header: 'My header',
47
- };
48
-
49
- export const CustomCounter = Template.bind({});
50
- CustomCounter.args = {
51
- counter: 123456,
52
- };
21
+ `;
53
22
 
54
- export const SlottedContent = Template.bind({});
55
- SlottedContent.args = {
56
- slot: html`<p>Slotted content</p>`,
57
- };
58
- SlottedContent.argTypes = {
59
- slot: { table: { disable: true } },
60
- };
23
+ export const Regular = Template.bind({});
@@ -1,5 +1,101 @@
1
1
  import '../src/tt-navbar.js';
2
+ import { expect, fixture, waitUntil } from '@open-wc/testing';
3
+ import { TtNavbar } from '../src/index.js';
4
+
5
+ // eslint-disable-next-line no-undef
6
+ const getLinkByHref = (links: NodeListOf<HTMLAnchorElement>, href: string) => {
7
+ for (const link of links) {
8
+ if (link.getAttribute('href') === href) {
9
+ return link;
10
+ }
11
+ }
12
+
13
+ return undefined;
14
+ };
15
+
16
+ const CLIENT_KEY = 'zxd47KQGAP';
2
17
 
3
18
  describe('TtNavbar', () => {
19
+ it('should throw an error if the clientKey is not provided', async () => {
20
+ try {
21
+ await fixture<TtNavbar>(`<tt-navbar></tt-navbar>`);
22
+ } catch (e) {
23
+ expect(e).to.match(/clientKey is required/);
24
+ }
25
+ });
26
+ it('should render with the default links', async () => {
27
+ const navbar = await fixture<TtNavbar>(
28
+ `<tt-navbar clientKey=${CLIENT_KEY}></tt-navbar>`,
29
+ );
30
+ const links = navbar.shadowRoot?.querySelectorAll('a');
31
+
32
+ expect(links?.length).to.equal(13);
33
+
34
+ if (links) {
35
+ expect(getLinkByHref(links, '/')).to.exist;
36
+ expect(getLinkByHref(links, 'https://app.campaign-manager.triptease.io'))
37
+ .to.exist;
38
+ expect(getLinkByHref(links, '/channels')).to.exist;
39
+ expect(getLinkByHref(links, `/parity/${CLIENT_KEY}`)).to.exist;
40
+ expect(getLinkByHref(links, `/guest-insights/${CLIENT_KEY}`)).to.exist;
41
+ expect(getLinkByHref(links, `/${CLIENT_KEY}/guest-behavioural-data`)).to
42
+ .exist;
43
+ expect(getLinkByHref(links, `/${CLIENT_KEY}/crm-config`)).to.exist;
44
+ expect(getLinkByHref(links, `/settings/group`)).to.exist;
45
+ expect(getLinkByHref(links, `/settings/${CLIENT_KEY}/hotels/`)).to.exist;
46
+ expect(getLinkByHref(links, `/account`)).to.exist;
47
+ expect(getLinkByHref(links, `/account/team/${CLIENT_KEY}`)).to.exist;
48
+ expect(getLinkByHref(links, `/account/billing-management/${CLIENT_KEY}`))
49
+ .to.exist;
50
+ expect(getLinkByHref(links, `/subscriptions/${CLIENT_KEY}`)).to.exist;
51
+ }
52
+ });
53
+
54
+ it('should render platform URLs against the base URL when it is defined', async () => {
55
+ const baseUrl = 'https://app.triptease.io';
56
+ const navbar = await fixture<TtNavbar>(
57
+ `<tt-navbar clientKey=${CLIENT_KEY} baseUrl="${baseUrl}"></tt-navbar>`,
58
+ );
59
+ const links = navbar.shadowRoot?.querySelectorAll('a');
60
+
61
+ if (links) {
62
+ expect(getLinkByHref(links, `${baseUrl}/`)).to.exist;
63
+ expect(getLinkByHref(links, 'https://app.campaign-manager.triptease.io'))
64
+ .to.exist; // This shouldn't change
65
+ expect(getLinkByHref(links, `${baseUrl}/channels`)).to.exist;
66
+ }
67
+ });
68
+
69
+ it('should allow navigation events to be handled externally', async () => {
70
+ let navigateEventCount = 0;
71
+
72
+ const onNavigate = (e: MouseEvent) => {
73
+ e.preventDefault();
74
+ navigateEventCount += 1;
75
+ };
76
+
77
+ const navbar = await fixture<TtNavbar>(
78
+ `<tt-navbar clientKey=${CLIENT_KEY}></tt-navbar>`,
79
+ );
80
+ navbar.navigate = onNavigate;
81
+ await navbar.updateComplete;
82
+
83
+ const links = navbar.shadowRoot?.querySelectorAll('a');
84
+ links?.forEach(l => l.click());
85
+
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 clientKey=${CLIENT_KEY}><div slot="clientSelector"><div id="myCoolClientSelector"></div></div></tt-navbar>`,
95
+ );
96
+
97
+ const clientSelector = navbar.querySelector('#myCoolClientSelector');
4
98
 
99
+ expect(clientSelector).to.exist;
100
+ });
5
101
  });