@@ -15,7 +15,8 @@ import { getByTestId } from "dom-testing-library";
1515// as a child, should not affect the latter even if they're the same container types
1616// - Tests whether the lib can work with CSS-modules built in to css-loader
1717// - Tests r-units
18- // todo add css-modules, and export the classes for reuse
18+ // - Tests the "as" ContainerQuery prop
19+ // - Tests multiple containers in a single css file and component
1920describe ( "Non OOCSS" , ( ) => {
2021const refs = { } ;
2122beforeAll ( ( ) => {
@@ -34,12 +35,15 @@ describe("Non OOCSS", () => {
3435
3536refs . root1 = getByTestId ( document . body , "root-1" ) ;
3637refs . marker1 = getByTestId ( refs . root1 , "marker-1" ) ;
38+ refs . label1 = getByTestId ( refs . root1 , "label-1" ) ;
3739refs . child1 = getByTestId ( refs . root1 , "child-1" ) ;
3840refs . root2 = getByTestId ( document . body , "root-2" ) ;
3941refs . marker2 = getByTestId ( refs . root2 , "marker-2" ) ;
42+ refs . label2 = getByTestId ( refs . root2 , "label-2" ) ;
4043refs . child2 = getByTestId ( refs . root2 , "child-2" ) ;
4144refs . root3 = getByTestId ( document . body , "root-3" ) ;
4245refs . marker3 = getByTestId ( refs . root3 , "marker-3" ) ;
46+ refs . label3 = getByTestId ( refs . root3 , "label-3" ) ;
4347
4448const wrapper = document . createElement ( "div" ) ;
4549wrapper . style . width = "100px" ;
@@ -57,6 +61,9 @@ describe("Non OOCSS", () => {
5761refs . unrelatedChild = document . createElement ( "div" ) ;
5862refs . unrelatedChild . className = styles . child ;
5963wrapper . appendChild ( refs . unrelatedChild ) ;
64+ refs . unrelatedLabel = document . createElement ( "div" ) ;
65+ refs . unrelatedLabel . className = styles . label ;
66+ wrapper . appendChild ( refs . unrelatedLabel ) ;
6067
6168document . body . appendChild ( wrapper ) ;
6269} ) ;
@@ -80,6 +87,9 @@ describe("Non OOCSS", () => {
8087width :"0px" ,
8188height :"0px"
8289} ) ;
90+ await waitForElementToHaveStyle ( refs . unrelatedLabel , {
91+ color :"rgb(255, 0, 0)"
92+ } ) ;
8393} ;
8494
8595it ( "should render container query styles with non-oocss classnames" , async ( ) => {
@@ -100,10 +110,19 @@ describe("Non OOCSS", () => {
100110
101111// Child wrappers should be adjusted with rh
102112await waitForElementToHaveStyle ( refs . child1 , {
103- height :"90px "
113+ height :"75px "
104114} ) ;
105115await waitForElementToHaveStyle ( refs . child2 , {
106- height :"81px"
116+ height :"56px"
117+ } ) ;
118+ await waitForElementToHaveStyle ( refs . label1 , {
119+ color :"rgb(255, 0, 0)"
120+ } ) ;
121+ await waitForElementToHaveStyle ( refs . label2 , {
122+ color :"rgb(255, 0, 0)"
123+ } ) ;
124+ await waitForElementToHaveStyle ( refs . label3 , {
125+ color :"rgb(255, 0, 0)"
107126} ) ;
108127
109128await expectUnrelatedElementsToBeUntouched ( ) ;
@@ -129,10 +148,19 @@ describe("Non OOCSS", () => {
129148
130149// Child wrapper heights should not change
131150await waitForElementToHaveStyle ( refs . child1 , {
132- height :"90px "
151+ height :"75px "
133152} ) ;
134153await waitForElementToHaveStyle ( refs . child2 , {
135- height :"81px"
154+ height :"56px"
155+ } ) ;
156+ await waitForElementToHaveStyle ( refs . label1 , {
157+ color :"rgb(255, 0, 0)"
158+ } ) ;
159+ await waitForElementToHaveStyle ( refs . label2 , {
160+ color :"rgb(255, 0, 0)"
161+ } ) ;
162+ await waitForElementToHaveStyle ( refs . label3 , {
163+ color :"rgb(255, 0, 0)"
136164} ) ;
137165
138166await expectUnrelatedElementsToBeUntouched ( ) ;
@@ -158,10 +186,19 @@ describe("Non OOCSS", () => {
158186
159187// Child wrapper heights should not change
160188await waitForElementToHaveStyle ( refs . child1 , {
161- height :"90px "
189+ height :"75px "
162190} ) ;
163191await waitForElementToHaveStyle ( refs . child2 , {
164- height :"81px"
192+ height :"56px"
193+ } ) ;
194+ await waitForElementToHaveStyle ( refs . label1 , {
195+ color :"rgb(0, 128, 0)"
196+ } ) ;
197+ await waitForElementToHaveStyle ( refs . label2 , {
198+ color :"rgb(255, 0, 0)"
199+ } ) ;
200+ await waitForElementToHaveStyle ( refs . label3 , {
201+ color :"rgb(255, 0, 0)"
165202} ) ;
166203
167204await expectUnrelatedElementsToBeUntouched ( ) ;
@@ -187,10 +224,19 @@ describe("Non OOCSS", () => {
187224
188225// Child wrapper heights should not change
189226await waitForElementToHaveStyle ( refs . child1 , {
190- height :"90px "
227+ height :"75px "
191228} ) ;
192229await waitForElementToHaveStyle ( refs . child2 , {
193- height :"81px"
230+ height :"56px"
231+ } ) ;
232+ await waitForElementToHaveStyle ( refs . label1 , {
233+ color :"rgb(0, 128, 0)"
234+ } ) ;
235+ await waitForElementToHaveStyle ( refs . label2 , {
236+ color :"rgb(0, 128, 0)"
237+ } ) ;
238+ await waitForElementToHaveStyle ( refs . label3 , {
239+ color :"rgb(255, 0, 0)"
194240} ) ;
195241
196242await expectUnrelatedElementsToBeUntouched ( ) ;
@@ -216,10 +262,57 @@ describe("Non OOCSS", () => {
216262
217263// Child wrapper heights should not change
218264await waitForElementToHaveStyle ( refs . child1 , {
219- height :"90px"
265+ height :"75px"
266+ } ) ;
267+ await waitForElementToHaveStyle ( refs . child2 , {
268+ height :"56px"
269+ } ) ;
270+ await waitForElementToHaveStyle ( refs . label1 , {
271+ color :"rgb(0, 128, 0)"
272+ } ) ;
273+ await waitForElementToHaveStyle ( refs . label2 , {
274+ color :"rgb(0, 128, 0)"
275+ } ) ;
276+ await waitForElementToHaveStyle ( refs . label3 , {
277+ color :"rgb(255, 0, 0)"
278+ } ) ;
279+
280+ await expectUnrelatedElementsToBeUntouched ( ) ;
281+ } ) ;
282+
283+ it ( "should change the last label to green" , async ( ) => {
284+ changeRootSize ( { width :291 } ) ;
285+
286+ await waitForElementToHaveStyle ( refs . marker1 , {
287+ backgroundColor :"rgb(0, 0, 255)" ,
288+ width :"86px"
289+ } ) ;
290+
291+ await waitForElementToHaveStyle ( refs . marker2 , {
292+ backgroundColor :"rgb(0, 0, 255)" ,
293+ width :"60px"
294+ } ) ;
295+
296+ await waitForElementToHaveStyle ( refs . marker3 , {
297+ backgroundColor :"rgb(0, 0, 255)" ,
298+ width :"42px"
299+ } ) ;
300+
301+ // Child wrapper heights should not change
302+ await waitForElementToHaveStyle ( refs . child1 , {
303+ height :"75px"
220304} ) ;
221305await waitForElementToHaveStyle ( refs . child2 , {
222- height :"81px"
306+ height :"56px"
307+ } ) ;
308+ await waitForElementToHaveStyle ( refs . label1 , {
309+ color :"rgb(0, 128, 0)"
310+ } ) ;
311+ await waitForElementToHaveStyle ( refs . label2 , {
312+ color :"rgb(0, 128, 0)"
313+ } ) ;
314+ await waitForElementToHaveStyle ( refs . label3 , {
315+ color :"rgb(0, 128, 0)"
223316} ) ;
224317
225318await expectUnrelatedElementsToBeUntouched ( ) ;
@@ -245,10 +338,20 @@ describe("Non OOCSS", () => {
245338
246339// Child wrappers should be adjusted with rh
247340await waitForElementToHaveStyle ( refs . child1 , {
248- height :"180px "
341+ height :"150px "
249342} ) ;
250343await waitForElementToHaveStyle ( refs . child2 , {
251- height :"162px"
344+ height :"113px"
345+ } ) ;
346+
347+ await waitForElementToHaveStyle ( refs . label1 , {
348+ color :"rgb(255, 0, 0)"
349+ } ) ;
350+ await waitForElementToHaveStyle ( refs . label2 , {
351+ color :"rgb(255, 0, 0)"
352+ } ) ;
353+ await waitForElementToHaveStyle ( refs . label3 , {
354+ color :"rgb(255, 0, 0)"
252355} ) ;
253356
254357await expectUnrelatedElementsToBeUntouched ( ) ;