@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
2
2
import { html , render , type TemplateResult } from 'lit' ;
3
3
import { createStory , createVariantStory } from '../../utilities/index' ;
4
4
import { type StoryOptions } from '../../types/StoryOptions' ;
5
-
5
+ import CUSTOM_BACKGROUNDS from '../../.storybook/backgrounds' ;
6
6
type ComponentProps = {
7
7
size : string ;
8
8
variant : string ;
@@ -89,4 +89,67 @@ describe('createVariantStory', () => {
89
89
// Check if argTypes are applied
90
90
expect ( story . argTypes ) . toEqual ( storyOpts . argTypes ) ;
91
91
} ) ;
92
+
93
+ it ( 'should apply custom background color from CUSTOM_BACKGROUNDS' , ( ) => {
94
+ const propOptions = {
95
+ size : [ 'small' ] ,
96
+ variant : [ 'primary' ]
97
+ } ;
98
+
99
+ const story = createVariantStory ( template , propOptions , { bgColor : 'background-subtle' } ) ;
100
+ const renderResult = story . render ( ) ;
101
+
102
+ const container = document . createElement ( 'div' ) ;
103
+ render ( renderResult , container ) ;
104
+
105
+ const templateContainer = container . querySelector ( '.template-container' ) ;
106
+ const computedStyle = window . getComputedStyle ( templateContainer ! ) ;
107
+
108
+ const backgroundColor = computedStyle . getPropertyValue ( '--background-color' ) ;
109
+ expect ( backgroundColor ) . toBeTruthy ( ) ;
110
+ expect ( backgroundColor ) . not . toBe ( '#ffffff' ) ;
111
+
112
+ const matchingBackground = CUSTOM_BACKGROUNDS . values . find ( bg => bg . name === 'background-subtle' ) ;
113
+ expect ( backgroundColor ) . toBe ( matchingBackground ?. value ) ;
114
+ } ) ;
115
+
116
+ it ( 'should fallback to default white background when invalid bgColor is provided' , ( ) => {
117
+ const propOptions = {
118
+ size : [ 'small' ] ,
119
+ variant : [ 'primary' ]
120
+ } ;
121
+
122
+ // @ts -expect-error - Testing invalid background color
123
+ const story = createVariantStory ( template , propOptions , { bgColor : 'background-invalid' } ) ;
124
+ const renderResult = story . render ( ) ;
125
+
126
+ const container = document . createElement ( 'div' ) ;
127
+ render ( renderResult , container ) ;
128
+
129
+ const templateContainer = container . querySelector ( '.template-container' ) ;
130
+ const computedStyle = window . getComputedStyle ( templateContainer ! ) ;
131
+
132
+ // Should fallback to default white background
133
+ const backgroundColor = computedStyle . getPropertyValue ( '--background-color' ) ;
134
+ expect ( backgroundColor ) . toBe ( '#ffffff' ) ;
135
+ } ) ;
136
+
137
+ it ( 'should use default white background when bgColor is undefined' , ( ) => {
138
+ const propOptions = {
139
+ size : [ 'small' ] ,
140
+ variant : [ 'primary' ]
141
+ } ;
142
+
143
+ const story = createVariantStory ( template , propOptions ) ;
144
+ const renderResult = story . render ( ) ;
145
+
146
+ const container = document . createElement ( 'div' ) ;
147
+ render ( renderResult , container ) ;
148
+
149
+ const templateContainer = container . querySelector ( '.template-container' ) ;
150
+ const computedStyle = window . getComputedStyle ( templateContainer ! ) ;
151
+
152
+ const backgroundColor = computedStyle . getPropertyValue ( '--background-color' ) ;
153
+ expect ( backgroundColor ) . toBe ( '#ffffff' ) ;
154
+ } ) ;
92
155
} ) ;
0 commit comments