Skip to content

Commit b67f4f5

Browse files
committed
test(theme): add more generateComponentsThemeCSS tests
1 parent 39bfce5 commit b67f4f5

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

core/src/utils/test/theme.spec.ts

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ describe('generateGlobalThemeCSS', () => {
558558
});
559559

560560
describe('generateComponentsThemeCSS', () => {
561-
it('should generate component theme CSS for a given theme', () => {
561+
it('should generate component theme CSS for a given theme with a single component', () => {
562562
const components = {
563563
IonChip: {
564564
hue: {
@@ -579,7 +579,7 @@ describe('generateComponentsThemeCSS', () => {
579579
const css = generateComponentsThemeCSS(components).replace(/\s/g, '');
580580

581581
const expectedCSS = `
582-
:root ion-chip {
582+
ion-chip {
583583
--ion-chip-hue-subtle-bg: red;
584584
--ion-chip-hue-subtle-color: white;
585585
--ion-chip-hue-subtle-border-color: black;
@@ -591,6 +591,71 @@ describe('generateComponentsThemeCSS', () => {
591591

592592
expect(css).toBe(expectedCSS);
593593
});
594+
595+
it('should generate component theme CSS for a given theme with multiple components', () => {
596+
const components = {
597+
IonChip: {
598+
hue: {
599+
subtle: {
600+
bg: 'red',
601+
color: 'white',
602+
borderColor: 'black',
603+
},
604+
bold: {
605+
bg: 'blue',
606+
color: 'white',
607+
borderColor: 'black',
608+
},
609+
},
610+
},
611+
IonBadge: {
612+
hue: {
613+
subtle: {
614+
bg: 'green',
615+
color: 'white',
616+
borderColor: 'black',
617+
},
618+
bold: {
619+
bg: 'blue',
620+
color: 'white',
621+
borderColor: 'black',
622+
},
623+
},
624+
},
625+
};
626+
627+
const css = generateComponentsThemeCSS(components).replace(/\s/g, '');
628+
629+
const expectedCSS = `
630+
ion-chip {
631+
--ion-chip-hue-subtle-bg: red;
632+
--ion-chip-hue-subtle-color: white;
633+
--ion-chip-hue-subtle-border-color: black;
634+
--ion-chip-hue-bold-bg: blue;
635+
--ion-chip-hue-bold-color: white;
636+
--ion-chip-hue-bold-border-color: black;
637+
}
638+
639+
ion-badge {
640+
--ion-badge-hue-subtle-bg: green;
641+
--ion-badge-hue-subtle-color: white;
642+
--ion-badge-hue-subtle-border-color: black;
643+
--ion-badge-hue-bold-bg: blue;
644+
--ion-badge-hue-bold-color: white;
645+
--ion-badge-hue-bold-border-color: black;
646+
}
647+
`.replace(/\s/g, '');
648+
649+
expect(css).toBe(expectedCSS);
650+
});
651+
652+
it('should not generate CSS variables for an empty components object', () => {
653+
const components = {};
654+
655+
const css = generateComponentsThemeCSS(components);
656+
657+
expect(css).toBe('');
658+
});
594659
});
595660

596661
describe('generateColorClasses', () => {

0 commit comments

Comments
 (0)