|
1 | 1 | import {fixture, expect} from '@open-wc/testing'; |
2 | 2 | import {html} from 'lit'; |
3 | 3 | import {CssChain as $$, CssChainT} from '../src/CssChain.js'; |
| 4 | +import {HTMLElementMixin} from "../src/HTMLElementMixin"; |
4 | 5 |
|
5 | 6 | interface A { |
6 | 7 | ma: string; |
@@ -325,5 +326,51 @@ describe('CssChain', () => { |
325 | 326 | expect($$('button',el).length).to.equal(2); |
326 | 327 | expect($$('button',el).txt()).to.equal('action1action2'); |
327 | 328 | }); |
| 329 | + it('$(css).txt(str)', async () => { |
| 330 | + |
| 331 | + const el = await fixture<HTMLElement>( |
| 332 | + html`<div><button>action1</button><button>action2</button></div>` |
| 333 | + ); |
| 334 | + const $e = $$(el); |
| 335 | + expect($e.length).to.equal(1); |
| 336 | + const s:string = $e.txt() |
| 337 | + expect(s).to.equal('action1action2'); |
| 338 | + expect($e.txt('erased').length).to.equal(1); |
| 339 | + expect($e.txt()).to.equal('erased'); |
| 340 | + expect($e.$('button').length).to.equal(0); |
| 341 | + expect($e.$('button').txt()).to.equal(''); |
| 342 | + }); |
| 343 | + it('$(css).txt(str|cb)', async () => { |
| 344 | + |
| 345 | + const el = await fixture<HTMLElement>( |
| 346 | + html`<div><button id="b1">action1</button>:<button id="b2">action2</button></div>` |
| 347 | + ); |
| 348 | + const $e = $$(el); |
| 349 | + expect($e.txt()).to.equal('action1:action2'); |
| 350 | + |
| 351 | + expect($e.txt(e=>e.id,'button').length).to.equal(1); |
| 352 | + expect($e.txt()).to.equal('b1:b2'); |
| 353 | + expect($e.$('button').length).to.equal(2); |
| 354 | + expect($e.$('button').txt()).to.equal('b1b2'); |
| 355 | + |
| 356 | + |
| 357 | + const cb1 = (e:HTMLElementMixin)=>`${e.id}`; |
| 358 | + expect($e.txt(cb1,'button').length).to.equal(1); |
| 359 | + expect($e.txt()).to.equal('b1:b2'); |
| 360 | + expect($e.$('button').length).to.equal(2); |
| 361 | + expect($e.$('button').txt()).to.equal('b1b2'); |
| 362 | + |
| 363 | + const cb2 = (e:HTMLElementMixin,i:number)=>`${e.id}-${i}`; |
| 364 | + expect($e.txt(cb2,'button').length).to.equal(1); |
| 365 | + expect($e.txt()).to.equal('b1-0:b2-1'); |
| 366 | + expect($e.$('button').length).to.equal(2); |
| 367 | + expect($e.$('button').txt()).to.equal('b1-0b2-1'); |
| 368 | + |
| 369 | + const cb3 = (e:HTMLElementMixin,i:number,arr: HTMLElementMixin[])=>`${e.id}-${i}-${arr.length}`; |
| 370 | + expect($e.txt(cb3,'button').length).to.equal(1); |
| 371 | + expect($e.txt()).to.equal('b1-0-2:b2-1-2'); |
| 372 | + expect($e.$('button').length).to.equal(2); |
| 373 | + expect($e.$('button').txt()).to.equal('b1-0-2b2-1-2'); |
| 374 | + }); |
328 | 375 |
|
329 | 376 | }); |
0 commit comments