|
| 1 | +import { expect } from "chai"; |
| 2 | +import { html } from "fxjs/es"; |
| 3 | +import el from "../../src/el.js"; |
| 4 | +import find from "../../src/find.js"; |
| 5 | +import siblings from "../../src/siblings.js"; |
| 6 | + |
| 7 | +describe("siblings", function () { |
| 8 | + it("부모의 자식들을 반환한다.", function () { |
| 9 | + const parent_el = el(html` |
| 10 | + <div class="parent"> |
| 11 | + <div class="child one"></div> |
| 12 | + <div class="child two"></div> |
| 13 | + <div class="child me"></div> |
| 14 | + <div class="child three"></div> |
| 15 | + </div> |
| 16 | + `); |
| 17 | + |
| 18 | + const me_el = find(".me", parent_el); |
| 19 | + |
| 20 | + const silbing_els = siblings(me_el); |
| 21 | + |
| 22 | + silbing_els.map((sibling_el) => { |
| 23 | + expect(sibling_el.parentNode).to.equal(parent_el); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + it("본인 엘리먼트는 제외한다.", function () { |
| 28 | + const parent_el = el(html` |
| 29 | + <div class="parent"> |
| 30 | + <div class="child one"></div> |
| 31 | + <div class="child two"></div> |
| 32 | + <div class="child me"></div> |
| 33 | + <div class="child three"></div> |
| 34 | + </div> |
| 35 | + `); |
| 36 | + |
| 37 | + const me_el = find(".me", parent_el); |
| 38 | + |
| 39 | + const silbing_els = siblings(me_el); |
| 40 | + |
| 41 | + expect(silbing_els).not.includes(me_el); |
| 42 | + }); |
| 43 | + |
| 44 | + it("셀렉터에 해당하는 형제들만 반환한다.", function () { |
| 45 | + const parent_el = el(html` |
| 46 | + <div class="parent"> |
| 47 | + <div class="child one"></div> |
| 48 | + <div class="child two"></div> |
| 49 | + <div class="child me"></div> |
| 50 | + <div class="child three"></div> |
| 51 | + </div> |
| 52 | + `); |
| 53 | + |
| 54 | + const me_el = find(".me", parent_el); |
| 55 | + |
| 56 | + const one_el = find(".one", parent_el); |
| 57 | + const two_el = find(".two", parent_el); |
| 58 | + const three_el = find(".three", parent_el); |
| 59 | + |
| 60 | + const silbing_els = siblings(".one", me_el); |
| 61 | + |
| 62 | + expect(silbing_els).includes(one_el); |
| 63 | + expect(silbing_els).not.includes(two_el); |
| 64 | + expect(silbing_els).not.includes(three_el); |
| 65 | + }); |
| 66 | +}); |
0 commit comments