@triptease/tt-navbar 0.0.2 → 0.0.5

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.2",
6
+ "version": "0.0.5",
7
7
  "type": "module",
8
8
  "main": "dist/src/index.js",
9
9
  "module": "dist/src/index.js",
package/src/TtNavbar.ts CHANGED
@@ -1,27 +1,112 @@
1
- import { html, css, LitElement } from 'lit';
1
+ import { html, LitElement } from 'lit';
2
2
  import { property } from 'lit/decorators.js';
3
+ import { styles } from './styles.js';
3
4
 
4
5
  export class TtNavbar extends LitElement {
5
- static styles = css`
6
- :host {
7
- display: block;
8
- padding: 25px;
9
- color: var(--tt-navbar-text-color, #000);
10
- }
11
- `;
6
+ static styles = styles;
12
7
 
13
- @property({ type: String }) header = 'Hey there';
8
+ @property({ type: Function })
9
+ navigate: ((e: MouseEvent) => void) | undefined;
14
10
 
15
- @property({ type: Number }) counter = 5;
11
+ @property({ type: String })
12
+ baseUrl?: string;
16
13
 
17
- __increment() {
18
- this.counter += 1;
19
- }
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
+ }
30
+ };
20
31
 
21
32
  render() {
22
33
  return html`
23
- <h2>${this.header} Nr. ${this.counter}!</h2>
24
- <button @click=${this.__increment}>increment</button>
34
+ <nav id=${this.id}>
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
+ </nav>
25
110
  `;
26
111
  }
27
112
  }
package/src/styles.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { css } from 'lit';
2
+
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,20 @@
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
+ </tt-navbar>
16
+ </div>
43
17
 
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
- };
18
+ `;
53
19
 
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
- };
20
+ export const Regular = Template.bind({});
@@ -1,32 +1,80 @@
1
- import { html } from 'lit';
2
- import { fixture, expect } from '@open-wc/testing';
3
- import { TtNavbar } from '../src/TtNavbar.js';
4
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';
5
17
 
6
18
  describe('TtNavbar', () => {
7
- it('has a default header "Hey there" and counter 5', async () => {
8
- const el = await fixture<TtNavbar>(html`<tt-navbar></tt-navbar>`);
9
19
 
10
- expect(el.header).to.equal('Hey there');
11
- expect(el.counter).to.equal(5);
12
- });
20
+ it("should throw an error if the clientKey is not provided", async () => {
21
+ try {
22
+ await fixture<TtNavbar>(`<tt-navbar></tt-navbar>`);
23
+ } catch(e) {
24
+ expect(e).to.match(/clientKey is required/);
25
+ }
26
+ })
27
+ it('should render with the default links', async () => {
28
+ const navbar = await fixture<TtNavbar>(`<tt-navbar clientKey=${CLIENT_KEY}></tt-navbar>`);
29
+ const links = navbar.shadowRoot?.querySelectorAll('a');
13
30
 
14
- it('increases the counter on button click', async () => {
15
- const el = await fixture<TtNavbar>(html`<tt-navbar></tt-navbar>`);
16
- el.shadowRoot!.querySelector('button')!.click();
31
+ expect(links?.length).to.equal(13);
32
+
33
+ if(links) {
34
+ expect(getLinkByHref(links, '/')).to.exist;
35
+ expect(getLinkByHref(links, 'https://app.campaign-manager.triptease.io')).to.exist;
36
+ expect(getLinkByHref(links, '/channels')).to.exist;
37
+ expect(getLinkByHref(links, `/parity/${CLIENT_KEY}`)).to.exist;
38
+ expect(getLinkByHref(links, `/guest-insights/${CLIENT_KEY}`)).to.exist;
39
+ expect(getLinkByHref(links, `/${CLIENT_KEY}/guest-behavioural-data`)).to.exist;
40
+ expect(getLinkByHref(links, `/${CLIENT_KEY}/crm-config`)).to.exist;
41
+ expect(getLinkByHref(links, `/settings/group`)).to.exist;
42
+ expect(getLinkByHref(links, `/settings/${CLIENT_KEY}/hotels/`)).to.exist;
43
+ expect(getLinkByHref(links, `/account`)).to.exist;
44
+ expect(getLinkByHref(links, `/account/team/${CLIENT_KEY}`)).to.exist;
45
+ expect(getLinkByHref(links, `/account/billing-management/${CLIENT_KEY}`)).to.exist;
46
+ expect(getLinkByHref(links, `/subscriptions/${CLIENT_KEY}`)).to.exist;
47
+ }
17
48
 
18
- expect(el.counter).to.equal(6);
19
49
  });
20
50
 
21
- it('can override the header via attribute', async () => {
22
- const el = await fixture<TtNavbar>(html`<tt-navbar header="attribute header"></tt-navbar>`);
51
+ it('should render platform URLs against the base URL when it is defined', async () => {
52
+ const baseUrl = 'https://app.triptease.io';
53
+ const navbar = await fixture<TtNavbar>(`<tt-navbar clientKey=${CLIENT_KEY} baseUrl="${baseUrl}"></tt-navbar>`);
54
+ const links = navbar.shadowRoot?.querySelectorAll('a');
23
55
 
24
- expect(el.header).to.equal('attribute header');
56
+ if(links) {
57
+ expect(getLinkByHref(links, `${baseUrl}/`)).to.exist;
58
+ expect(getLinkByHref(links, 'https://app.campaign-manager.triptease.io')).to.exist; // This shouldn't change
59
+ expect(getLinkByHref(links, `${baseUrl}/channels`)).to.exist;
60
+ }
25
61
  });
26
62
 
27
- it('passes the a11y audit', async () => {
28
- const el = await fixture<TtNavbar>(html`<tt-navbar></tt-navbar>`);
63
+ it('should allow navigation events to be handled externally', async () => {
64
+ let navigateEventCount = 0;
65
+
66
+ const onNavigate = (e: MouseEvent) => {
67
+ e.preventDefault();
68
+ navigateEventCount += 1;
69
+ }
70
+
71
+ const navbar = await fixture<TtNavbar>(`<tt-navbar clientKey=${CLIENT_KEY}></tt-navbar>`);
72
+ navbar.navigate = onNavigate;
73
+ await navbar.updateComplete;
74
+
75
+ const links = navbar.shadowRoot?.querySelectorAll('a');
76
+ links?.forEach(l => l.click());
29
77
 
30
- await expect(el).shadowDom.to.be.accessible();
78
+ await waitUntil(() => expect(navigateEventCount).to.equal(12), 'navigate event did not fire');
31
79
  });
32
80
  });