Skip to content

Commit 1d169cb

Browse files
Copilotabraham
andcommitted
Refactor fork-me-block to use LitElement via ThemedElement
Co-authored-by: abraham <[email protected]>
1 parent 99cb827 commit 1d169cb

File tree

3 files changed

+71
-12
lines changed

3 files changed

+71
-12
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { beforeEach, 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 './fork-me-block';
6+
7+
describe('fork-me-block', () => {
8+
beforeEach(() => {
9+
// Clear any existing custom elements if needed
10+
});
11+
12+
it('defines a component', () => {
13+
expect(customElements.get('fork-me-block')).toBeDefined();
14+
});
15+
16+
it('renders the fork me content', async () => {
17+
const { shadowRootForWithin } = await fixture(
18+
html`<fork-me-block data-testid="fork-block"></fork-me-block>`,
19+
);
20+
const { getByText } = within(shadowRootForWithin);
21+
22+
expect(screen.getByTestId('fork-block')).toBeInTheDocument();
23+
expect(getByText('Fork me on GitHub')).toBeInTheDocument();
24+
expect(getByText('Fork this project')).toBeInTheDocument();
25+
expect(getByText(/Hoverboard is open source conference website template/)).toBeInTheDocument();
26+
});
27+
28+
it('renders the GitHub link correctly', async () => {
29+
const { shadowRootForWithin } = await fixture(html`<fork-me-block></fork-me-block>`);
30+
const { getByRole } = within(shadowRootForWithin);
31+
32+
const link = getByRole('link');
33+
expect(link).toHaveAttribute('href', 'https://github.com/gdg-x/hoverboard');
34+
});
35+
36+
it('has proper styling classes', async () => {
37+
const { shadowRootForWithin } = await fixture(html`<fork-me-block></fork-me-block>`);
38+
const { getByText } = within(shadowRootForWithin);
39+
40+
const container = getByText('Fork me on GitHub').closest('.container');
41+
expect(container).toHaveClass('container', 'container-narrow');
42+
43+
const button = getByText('Fork this project').closest('md-outlined-button');
44+
expect(button).toHaveClass('icon-right');
45+
});
46+
});
Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import { customElement } from '@polymer/decorators';
2-
import '@polymer/iron-icon';
1+
// TODO: enable imports
2+
// import '@polymer/iron-icon';
33
import '@material/web/button/outlined-button.js';
4-
import { html, PolymerElement } from '@polymer/polymer';
5-
import '../utils/icons';
6-
import './shared-styles';
4+
import { css, html } from 'lit';
5+
import { customElement } from 'lit/decorators.js';
6+
// TODO: enable imports
7+
// import '../utils/icons';
8+
import { ThemedElement } from './themed-element';
79

810
@customElement('fork-me-block')
9-
export class ForkMeBlock extends PolymerElement {
10-
static get template() {
11-
return html`
12-
<style include="shared-styles flex flex-alignment">
11+
export class ForkMeBlock extends ThemedElement {
12+
static override get styles() {
13+
return [
14+
...super.styles,
15+
css`
1316
:host {
1417
display: flex;
1518
width: 100%;
@@ -22,8 +25,12 @@ export class ForkMeBlock extends PolymerElement {
2225
--md-outlined-button-label-text-color: #000;
2326
--md-outlined-button-outline-color: #000;
2427
}
25-
</style>
28+
`,
29+
];
30+
}
2631

32+
override render() {
33+
return html`
2734
<div class="container container-narrow">
2835
<h1 class="container-title">Fork me on GitHub</h1>
2936
<p>
@@ -43,3 +50,9 @@ export class ForkMeBlock extends PolymerElement {
4350
`;
4451
}
4552
}
53+
54+
declare global {
55+
interface HTMLElementTagNameMap {
56+
'fork-me-block': ForkMeBlock;
57+
}
58+
}

src/pages/home-page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { HeroBlock } from '../components/hero/hero-block';
1010
import '../elements/about-organizer-block';
1111
import '../elements/featured-videos';
1212
import '../elements/footer-block';
13-
import '../elements/fork-me-block';
13+
import '../components/fork-me-block';
1414
import '../elements/gallery-block';
1515
import '../elements/latest-posts-block';
1616
import '../elements/map-block';
@@ -308,7 +308,7 @@ export class HomePage extends ReduxMixin(PolymerElement) {
308308
? showForkMeBlockForProjectIds.includes(firebaseApp.options.appId)
309309
: false;
310310
if (showForkMeBlock) {
311-
import('../elements/fork-me-block');
311+
import('../components/fork-me-block');
312312
}
313313
return showForkMeBlock;
314314
}

0 commit comments

Comments
 (0)