Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Setup SSR fixtures for package components #1377

Draft
wants to merge 57 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
3de5ea2
test: Setup SSR fixtures for package components
rkaraivanov Sep 9, 2024
a81e3b8
refactor: Exposed self-registering entry points for SSR tests
rkaraivanov Sep 9, 2024
686e99b
fix(form-mixin): Do not add invalid handler in server env
rkaraivanov Sep 9, 2024
7a25b0e
test(accordion, avatar): Added SSR fixtures
rkaraivanov Sep 9, 2024
d4c7b1b
test(badge): Added SSR fixtures
rkaraivanov Sep 9, 2024
a5f7441
test(banner): Added SSR fixtures
rkaraivanov Sep 9, 2024
9ada067
test(button, icon-button): Added SSR fixtures
rkaraivanov Sep 9, 2024
2727b87
test(button-group): Added SSR fixtures
rkaraivanov Sep 9, 2024
6a32dd9
test(calendar): Added SSR fixtures
rkaraivanov Sep 9, 2024
fef5ab0
test(card): Added SSR fixtures
rkaraivanov Sep 9, 2024
bf50258
test(checkbox, switch): Added SSR fixtures
rkaraivanov Sep 9, 2024
69e7a27
test(chip): Added SSR fixtures
rkaraivanov Sep 9, 2024
9b19604
test(combo): Added SSR fixtures
rkaraivanov Sep 9, 2024
391da0a
test(date-picker,date-time-input): Added SSR fixtures
rkaraivanov Sep 9, 2024
912dd5a
test(dialog): Added SSR fixtures
rkaraivanov Sep 9, 2024
c882362
test(divider): Added SSR fixtures
rkaraivanov Sep 9, 2024
bdd366f
test(dropdown): Added SSR fixtures
rkaraivanov Sep 9, 2024
fa98822
test(expansion-panel): Added SSR fixtures
rkaraivanov Sep 9, 2024
7bf5a39
test(icon): Added SSR fixtures
rkaraivanov Sep 9, 2024
4368d69
test(list): Added SSR fixtures
rkaraivanov Sep 9, 2024
f0e060e
test(mask-input): Added SSR fixtures
rkaraivanov Sep 9, 2024
bb3f564
test(nav-drawer): Added SSR fixtures
rkaraivanov Sep 9, 2024
8b93713
test(navbar): Added SSR fixture
rkaraivanov Sep 9, 2024
841ab69
test(icon): Fix SSR module import
rkaraivanov Sep 9, 2024
0f4ff1e
test(progress): Added SSR fixtures
rkaraivanov Sep 9, 2024
f7b2690
test(radio, radio-group): Add SSR fixtures
rkaraivanov Sep 9, 2024
0f3d105
test(rating): Added SSR fixtures
rkaraivanov Sep 9, 2024
9337c10
test(ripple): Added SSR fixtures
rkaraivanov Sep 9, 2024
030146e
test(select): Added SSR fixtures
rkaraivanov Sep 9, 2024
5ee49ae
test(slider): Added SSR fixtures
rkaraivanov Sep 9, 2024
c7e45fd
test(ripple): Fix button import
rkaraivanov Sep 9, 2024
4e441c5
test(snackbar, toast): Added SSR fixtures
rkaraivanov Sep 9, 2024
7e7c108
fix(icon): Safely create DOM parser
rkaraivanov Sep 9, 2024
a2d0294
fix(accordion): Added safe addEventListener
rkaraivanov Sep 9, 2024
97ce58e
fix: MutationObserver controller safe initialization
rkaraivanov Sep 9, 2024
8cdcede
fix(calendar): Added safe addEventListener
rkaraivanov Sep 9, 2024
2bd1a11
fix(combo): Added safe addEventListener
rkaraivanov Sep 9, 2024
e4831b1
fix: Root click controller safe addEventListener
rkaraivanov Sep 9, 2024
a61373c
Merge remote-tracking branch 'origin/master' into rkaraivanov/ssr-sup…
rkaraivanov Sep 10, 2024
0bfe618
test(stepper): Added SSR fixtures
rkaraivanov Sep 10, 2024
ade58d7
test(tabs): Added SSR fixtures
rkaraivanov Sep 10, 2024
8ce6378
test(textarea): Added SSR fixtures
rkaraivanov Sep 10, 2024
e63529d
fix(date-picker): Added safe addEventListener
rkaraivanov Sep 10, 2024
548038d
fix: Made LTR helper server aware
rkaraivanov Sep 10, 2024
8351b83
fix(ripple): Added safe addEventListener
rkaraivanov Sep 10, 2024
8e2cde8
fix(select): Added safe addEventListener
rkaraivanov Sep 10, 2024
55bcc9e
fix(slider): Added safe addEventListener
rkaraivanov Sep 10, 2024
9f87f66
fix(textarea): Added safe addEventListener and check for observer
rkaraivanov Sep 10, 2024
5e6d1da
test: Ignore SSR entry points from coverage
rkaraivanov Sep 10, 2024
ea96b9a
fix: Made getElementFromRoot server aware
rkaraivanov Sep 10, 2024
4aa7840
fix(icon): Changed life-cycle icon refs resolution
rkaraivanov Sep 10, 2024
9857297
test(tree): Added SSR fixtures
rkaraivanov Sep 10, 2024
cfd14ba
Merge remote-tracking branch 'origin/master' into rkaraivanov/ssr-sup…
rkaraivanov Sep 12, 2024
54f0556
refactor: Better typing for the safe addEventListener
rkaraivanov Sep 12, 2024
c0c29ea
Merge remote-tracking branch 'origin/master' into rkaraivanov/ssr-sup…
rkaraivanov Sep 13, 2024
43e172f
Merge remote-tracking branch 'origin/master' into rkaraivanov/ssr-sup…
rkaraivanov Sep 16, 2024
1962021
chore: Fix package-lock.json
rkaraivanov Sep 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,168 changes: 2,372 additions & 796 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@biomejs/biome": "1.9.1",
"@custom-elements-manifest/analyzer": "^0.10.3",
"@igniteui/material-icons-extended": "^3.0.2",
"@lit-labs/testing": "^0.2.4",
"@open-wc/testing": "^4.0.0",
"@storybook/addon-a11y": "^8.3.0",
"@storybook/addon-actions": "^8.3.0",
Expand Down
5 changes: 2 additions & 3 deletions scripts/tsconfig.prod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../tsconfig.json",
"exclude": [
"../**/*-auto-register.ts",
"../vite.config.ts",
"../**/*.spec.ts",
"../stories"
Expand All @@ -12,7 +13,5 @@
"declarationMap": false,
"removeComments": true
},
"include": [
"../**/*.ts"
]
"include": ["../**/*.ts"]
}
5 changes: 5 additions & 0 deletions src/components/accordion/accordion-auto-register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// NOTE: Self-registering import for SSR fixtures.
import Component from './accordion.js';
Component.register();

export default Component;
40 changes: 40 additions & 0 deletions src/components/accordion/accordion.ssr.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
cleanupFixtures,
csrFixture,
ssrHydratedFixture,
ssrNonHydratedFixture,
} from '@lit-labs/testing/fixtures.js';

import { html } from 'lit';
import { isSsrRendered, isSsrStyled } from '../common/utils.spec.js';
import type IgcAccordionComponent from './accordion.js';

afterEach(() => cleanupFixtures());

const template = html`
<igc-accordion>
<igc-expansion-panel open>
<h1 slot="title">Expansion panel 1 title</h1>
<h2 slot="subtitle">Expansion panel 1 subtitle</h2>
<p>Sample content</p>
</igc-expansion-panel>
<igc-expansion-panel open>
<h1 slot="title">Expansion panel 2 title</h1>
<h2 slot="subtitle">Expansion panel 2 subtitle</h2>
<p>Sample content</p>
</igc-expansion-panel>
</igc-accordion>
`;

for (const fixture of [csrFixture, ssrHydratedFixture, ssrNonHydratedFixture]) {
describe(`[${fixture.name}] - igc-accordion`, () => {
it('renders as expected', async () => {
const element = await fixture<IgcAccordionComponent>(template, {
modules: ['./accordion-auto-register.js'],
});

isSsrRendered(element);
isSsrStyled(element);
});
});
}
18 changes: 12 additions & 6 deletions src/components/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
shiftKey,
} from '../common/controllers/key-bindings.js';
import { registerComponent } from '../common/definitions/register.js';
import { ssrAddEventListener } from '../common/util.js';
import { first, last } from '../common/util.js';
import IgcExpansionPanelComponent from '../expansion-panel/expansion-panel.js';
import type { IgcExpansionPanelComponentEventMap } from '../expansion-panel/expansion-panel.js';
import { styles } from './themes/accordion.base.css.js';

/**
Expand Down Expand Up @@ -52,7 +54,11 @@ export default class IgcAccordionComponent extends LitElement {
constructor() {
super();

this.addEventListener('igcOpening', this.handlePanelOpening);
ssrAddEventListener<IgcExpansionPanelComponentEventMap>(
this,
'igcOpening',
this.handlePanelOpening
);

addKeybindings(this, {
skip: this.skipKeybinding,
Expand Down Expand Up @@ -111,15 +117,15 @@ export default class IgcAccordionComponent extends LitElement {
}
}

private handlePanelOpening(event: Event) {
const current = event.target as IgcExpansionPanelComponent;

if (!(this.singleExpand && this.panels.includes(current))) {
private handlePanelOpening({
detail,
}: CustomEvent<IgcExpansionPanelComponent>) {
if (!(this.singleExpand && this.panels.includes(detail))) {
return;
}

for (const panel of this.enabledPanels) {
if (panel.open && panel !== current) {
if (panel.open && panel !== detail) {
this.closePanel(panel);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/avatar/avatar-auto-register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// NOTE: Self-registering import for SSR fixtures.
import Component from './avatar.js';
Component.register();

export default Component;
27 changes: 27 additions & 0 deletions src/components/avatar/avatar.ssr.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
cleanupFixtures,
csrFixture,
ssrHydratedFixture,
ssrNonHydratedFixture,
} from '@lit-labs/testing/fixtures.js';

import { html } from 'lit';
import { isSsrRendered, isSsrStyled } from '../common/utils.spec.js';
import type IgcAvatarComponent from './avatar.js';

afterEach(() => cleanupFixtures());

const template = html`<igc-avatar initials="IG"></igc-avatar>`;

for (const fixture of [csrFixture, ssrHydratedFixture, ssrNonHydratedFixture]) {
describe(`[${fixture.name}] - igc-avatar`, () => {
it('renders as expected', async () => {
const element = await fixture<IgcAvatarComponent>(template, {
modules: ['./avatar-auto-register.js'],
});

isSsrRendered(element);
isSsrStyled(element);
});
});
}
5 changes: 5 additions & 0 deletions src/components/badge/badge-auto-register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// NOTE: Self-registering import for SSR fixtures.
import Component from './badge.js';
Component.register();

export default Component;
27 changes: 27 additions & 0 deletions src/components/badge/badge.ssr.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
cleanupFixtures,
csrFixture,
ssrHydratedFixture,
ssrNonHydratedFixture,
} from '@lit-labs/testing/fixtures.js';

import { html } from 'lit';
import { isSsrRendered, isSsrStyled } from '../common/utils.spec.js';
import type IgcBadgeComponent from './badge.js';

afterEach(() => cleanupFixtures());

const template = html`<igc-badge shape="square"></igc-badge>`;

for (const fixture of [csrFixture, ssrHydratedFixture, ssrNonHydratedFixture]) {
describe(`[${fixture.name}] - igc-badge`, () => {
it('renders as expected', async () => {
const element = await fixture<IgcBadgeComponent>(template, {
modules: ['./badge-auto-register.js'],
});

isSsrRendered(element);
isSsrStyled(element);
});
});
}
5 changes: 5 additions & 0 deletions src/components/banner/banner-auto-register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// NOTE: Self-registering import for SSR fixtures.
import Component from './banner.js';
Component.register();

export default Component;
27 changes: 27 additions & 0 deletions src/components/banner/banner.ssr.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
cleanupFixtures,
csrFixture,
ssrHydratedFixture,
ssrNonHydratedFixture,
} from '@lit-labs/testing/fixtures.js';

import { html } from 'lit';
import { isSsrRendered, isSsrStyled } from '../common/utils.spec.js';
import type IgcBannerComponent from './banner.js';

afterEach(() => cleanupFixtures());

const template = html`<igc-banner>You are currently offline!</igc-banner>`;

for (const fixture of [csrFixture, ssrHydratedFixture, ssrNonHydratedFixture]) {
describe(`[${fixture.name}] - igc-banner`, () => {
it('renders as expected', async () => {
const element = await fixture<IgcBannerComponent>(template, {
modules: ['./banner-auto-register.js'],
});

isSsrRendered(element);
isSsrStyled(element);
});
});
}
5 changes: 5 additions & 0 deletions src/components/button-group/button-group-auto-register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// NOTE: Self-registering import for SSR fixtures.
import Component from './button-group.js';
Component.register();

export default Component;
33 changes: 33 additions & 0 deletions src/components/button-group/button-group.ssr.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
cleanupFixtures,
csrFixture,
ssrHydratedFixture,
ssrNonHydratedFixture,
} from '@lit-labs/testing/fixtures.js';

import { html } from 'lit';
import { isSsrRendered, isSsrStyled } from '../common/utils.spec.js';
import type IgcButtonGroupComponent from './button-group.js';

afterEach(() => cleanupFixtures());

const template = html`
<igc-button-group>
<igc-toggle-button value="left">Left</igc-toggle-button>
<igc-toggle-button value="center">Center</igc-toggle-button>
<igc-toggle-button value="right">Right</igc-toggle-button>
</igc-button-group>
`;

for (const fixture of [csrFixture, ssrHydratedFixture, ssrNonHydratedFixture]) {
describe(`[${fixture.name}] - igc-button-group`, () => {
it('renders as expected', async () => {
const element = await fixture<IgcButtonGroupComponent>(template, {
modules: ['./button-group-auto-register.js'],
});

isSsrRendered(element);
isSsrStyled(element);
});
});
}
5 changes: 5 additions & 0 deletions src/components/button/button-auto-register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// NOTE: Self-registering import for SSR fixtures.
import Component from './button.js';
Component.register();

export default Component;
27 changes: 27 additions & 0 deletions src/components/button/button.ssr.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
cleanupFixtures,
csrFixture,
ssrHydratedFixture,
ssrNonHydratedFixture,
} from '@lit-labs/testing/fixtures.js';

import { html } from 'lit';
import { isSsrRendered, isSsrStyled } from '../common/utils.spec.js';
import type IgcButtonComponent from './button.js';

afterEach(() => cleanupFixtures());

const template = html`<igc-button variant="outlined">Click</igc-button>`;

for (const fixture of [csrFixture, ssrHydratedFixture, ssrNonHydratedFixture]) {
describe(`[${fixture.name}] - igc-button`, () => {
it('renders as expected', async () => {
const element = await fixture<IgcButtonComponent>(template, {
modules: ['./button-auto-register.js'],
});

isSsrRendered(element);
isSsrStyled(element);
});
});
}
5 changes: 5 additions & 0 deletions src/components/button/icon-button-auto-register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// NOTE: Self-registering import for SSR fixtures.
import Component from './icon-button.js';
Component.register();

export default Component;
29 changes: 29 additions & 0 deletions src/components/button/icon-button.ssr.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
cleanupFixtures,
csrFixture,
ssrHydratedFixture,
ssrNonHydratedFixture,
} from '@lit-labs/testing/fixtures.js';

import { html } from 'lit';
import { isSsrRendered, isSsrStyled } from '../common/utils.spec.js';
import type IgcIconButtonComponent from './icon-button.js';

afterEach(() => cleanupFixtures());

const template = html`
<igc-icon-button name="icon" variant="outlined">Click</igc-icon-button>
`;

for (const fixture of [csrFixture, ssrHydratedFixture, ssrNonHydratedFixture]) {
describe(`[${fixture.name}] - igc-icon-button`, () => {
it('renders as expected', async () => {
const element = await fixture<IgcIconButtonComponent>(template, {
modules: ['./icon-button-auto-register.js'],
});

isSsrRendered(element);
isSsrStyled(element);
});
});
}
5 changes: 5 additions & 0 deletions src/components/calendar/calendar-auto-register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// NOTE: Self-registering import for SSR fixtures.
import Component from './calendar.js';
Component.register();

export default Component;
27 changes: 27 additions & 0 deletions src/components/calendar/calendar.ssr.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
cleanupFixtures,
csrFixture,
ssrHydratedFixture,
ssrNonHydratedFixture,
} from '@lit-labs/testing/fixtures.js';

import { html } from 'lit';
import { isSsrRendered, isSsrStyled } from '../common/utils.spec.js';
import type IgcCalendarComponent from './calendar.js';

afterEach(() => cleanupFixtures());

const template = html`<igc-calendar></igc-calendar>`;

for (const fixture of [csrFixture, ssrHydratedFixture, ssrNonHydratedFixture]) {
describe(`[${fixture.name}] - igc-calendar`, () => {
it('renders as expected', async () => {
const element = await fixture<IgcCalendarComponent>(template, {
modules: ['./calendar-auto-register.js'],
});

isSsrRendered(element);
isSsrStyled(element);
});
});
}
11 changes: 9 additions & 2 deletions src/components/calendar/days-view/days-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import { IgcCalendarResourceStringEN } from '../../common/i18n/calendar.resource
import { createDateTimeFormatters } from '../../common/localization/intl-formatters.js';
import type { Constructor } from '../../common/mixins/constructor.js';
import { EventEmitterMixin } from '../../common/mixins/event-emitter.js';
import { chunk, first, last, partNameMap, take } from '../../common/util.js';
import {
chunk,
first,
last,
partNameMap,
ssrAddEventListener,
take,
} from '../../common/util.js';
import { IgcCalendarBaseComponent } from '../base.js';
import {
areSameMonth,
Expand Down Expand Up @@ -137,7 +144,7 @@ export default class IgcDaysViewComponent extends EventEmitterMixin<
bindingDefaults: { preventDefault: true },
}).setActivateHandler(this.handleInteraction);

this.addEventListener('click', this.handleInteraction);
ssrAddEventListener(this, 'click', this.handleInteraction);
}

public override connectedCallback() {
Expand Down
5 changes: 5 additions & 0 deletions src/components/card/card-auto-register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// NOTE: Self-registering import for SSR fixtures.
import Component from './card.js';
Component.register();

export default Component;
Loading
Loading