Skip to content

Commit e68a437

Browse files
committed
Refactor footer-rel to Lit
1 parent d376a84 commit e68a437

File tree

3 files changed

+83
-28
lines changed

3 files changed

+83
-28
lines changed

src/components/footer-rel.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { describe, expect, it } from '@jest/globals';
2+
import { screen, within } from '@testing-library/dom';
3+
import { html } from 'lit';
4+
import { fixture } from '../../__tests__/helpers/fixtures';
5+
import '../components/footer-rel';
6+
import { notifications, subscribeNote } from '../utils/data';
7+
8+
describe('footer-rel', () => {
9+
it('defines a component', () => {
10+
expect(customElements.get('footer-rel')).toBeDefined();
11+
});
12+
13+
it('renders subscription section', async () => {
14+
const { shadowRootForWithin } = await fixture(
15+
html`<footer-rel data-testid="footer-rel"></footer-rel>`,
16+
);
17+
const withinShadowRoot = within(shadowRootForWithin);
18+
19+
expect(screen.getByTestId('footer-rel')).toBeInTheDocument();
20+
21+
// Check subscription heading
22+
const subscriptionHeading = withinShadowRoot.getByText(notifications.subscribe);
23+
24+
expect(subscriptionHeading).toBeInTheDocument();
25+
expect(subscriptionHeading).toHaveClass('col-heading');
26+
27+
// Check subscription note
28+
const subscriptionNote = withinShadowRoot.getByText(subscribeNote);
29+
30+
expect(subscriptionNote).toBeInTheDocument();
31+
});
32+
33+
it('renders without errors', async () => {
34+
const { element } = await fixture(html`<footer-rel></footer-rel>`);
35+
36+
expect(element).toBeInTheDocument();
37+
expect(element.shadowRoot).toBeDefined();
38+
});
39+
});

src/elements/footer-rel.ts renamed to src/components/footer-rel.ts

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import { customElement, property } from '@polymer/decorators';
2-
import { html, PolymerElement } from '@polymer/polymer';
1+
import { css, html } from 'lit';
2+
import { customElement, property } from 'lit/decorators.js';
3+
import { repeat } from 'lit/directives/repeat.js';
34
import { footerRelBlock, notifications, subscribeNote } from '../utils/data';
4-
import './subscribe-form-footer';
5+
import { ThemedElement } from '../components/themed-element';
6+
import '../elements/subscribe-form-footer';
57

68
@customElement('footer-rel')
7-
export class FooterRel extends PolymerElement {
8-
static get template() {
9-
return html`
10-
<style include="shared-styles flex flex-alignment">
9+
export class FooterRel extends ThemedElement {
10+
static override get styles() {
11+
return [
12+
...super.styles,
13+
css`
1114
:host {
1215
border-top: 1px solid var(--border-light-color);
1316
border-bottom: 1px solid var(--border-light-color);
@@ -63,38 +66,51 @@ export class FooterRel extends PolymerElement {
6366
margin-top: 0;
6467
}
6568
}
66-
</style>
69+
`,
70+
];
71+
}
6772

68-
<template is="dom-repeat" items="[[footerRelBlock]]" as="footerRel">
69-
<div class="col" layout vertical wrap flex-auto>
70-
<div class="col-heading">[[footerRel.title]]</div>
71-
<ul class="nav">
72-
<template is="dom-repeat" items="[[footerRel.links]]" as="link">
73-
<li>
74-
<template is="dom-if" if="[[!link.newTab]]">
75-
<a href="[[link.url]]">[[link.name]]</a>
76-
</template>
77-
<template is="dom-if" if="[[link.newTab]]">
78-
<a href="[[link.url]]" target="_blank" rel="noopener noreferrer">[[link.name]]</a>
79-
</template>
80-
</li>
81-
</template>
82-
</ul>
83-
</div>
84-
</template>
73+
override render() {
74+
return html`
75+
${repeat(
76+
this.footerRelBlock,
77+
(footerRel) => footerRel.title,
78+
(footerRel) => html`
79+
<div class="col" layout vertical wrap flex-auto>
80+
<div class="col-heading">${footerRel.title}</div>
81+
<ul class="nav">
82+
${repeat(
83+
footerRel.links,
84+
(link) => link.url,
85+
(link) => html`
86+
<li>
87+
${link.newTab
88+
? html`<a href="${link.url}" target="_blank" rel="noopener noreferrer"
89+
>${link.name}</a
90+
>`
91+
: html`<a href="${link.url}">${link.name}</a>`}
92+
</li>
93+
`,
94+
)}
95+
</ul>
96+
</div>
97+
`,
98+
)}
8599
86100
<div class="col" layout vertical flex-auto wrap>
87-
<div class="col-heading">[[notifications.subscribe]]</div>
88-
<span>[[subscribeNote]]</span>
101+
<div class="col-heading">${this.notifications.subscribe}</div>
102+
<span>${this.subscribeNote}</span>
89103
<subscribe-form-footer></subscribe-form-footer>
90104
</div>
91105
`;
92106
}
93107

94108
@property({ type: Array })
95109
private footerRelBlock = footerRelBlock;
110+
96111
@property()
97112
private subscribeNote = subscribeNote;
113+
98114
@property({ type: Object })
99115
private notifications = notifications;
100116
}

src/elements/footer-block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { html, PolymerElement } from '@polymer/polymer';
44
import '../utils/icons';
55
import { scrollToTop } from '../utils/scrolling';
66
import '../components/footer-nav';
7-
import './footer-rel';
7+
import '../components/footer-rel';
88
import './footer-social';
99

1010
@customElement('footer-block')

0 commit comments

Comments
 (0)