|
| 1 | +export default { |
| 2 | + props: { |
| 3 | + items: [ |
| 4 | + { done: false, text: 'one' }, |
| 5 | + { done: true, text: 'two' }, |
| 6 | + { done: false, text: 'three' } |
| 7 | + ] |
| 8 | + }, |
| 9 | + |
| 10 | + html: ` |
| 11 | + <div> |
| 12 | + <input type="checkbox"> |
| 13 | + <input type="text"><p>one</p> |
| 14 | + </div> |
| 15 | + <div> |
| 16 | + <input type="checkbox"> |
| 17 | + <input type="text"><p>two</p> |
| 18 | + </div> |
| 19 | + <div> |
| 20 | + <input type="checkbox"> |
| 21 | + <input type="text"><p>three</p> |
| 22 | + </div> |
| 23 | +
|
| 24 | + <p>remaining:one / done:two / remaining:three</p> |
| 25 | + `, |
| 26 | + |
| 27 | + ssrHtml: ` |
| 28 | + <div> |
| 29 | + <input type="checkbox"> |
| 30 | + <input type="text" value=one><p>one</p> |
| 31 | + </div> |
| 32 | + <div> |
| 33 | + <input type="checkbox" checked=""> |
| 34 | + <input type="text" value=two><p>two</p> |
| 35 | + </div> |
| 36 | + <div> |
| 37 | + <input type="checkbox"> |
| 38 | + <input type="text" value=three><p>three</p> |
| 39 | + </div> |
| 40 | +
|
| 41 | + <p>remaining:one / done:two / remaining:three</p> |
| 42 | + `, |
| 43 | + |
| 44 | + async test({ assert, component, target, window }) { |
| 45 | + function set_text(i, text) { |
| 46 | + const input = target.querySelectorAll('input[type="text"]')[i]; |
| 47 | + input.value = text; |
| 48 | + input.dispatchEvent(new window.Event('input')); |
| 49 | + } |
| 50 | + |
| 51 | + function set_done(i, done) { |
| 52 | + const input = target.querySelectorAll('input[type="checkbox"]')[i]; |
| 53 | + input.checked = done; |
| 54 | + input.dispatchEvent(new window.Event('change')); |
| 55 | + } |
| 56 | + |
| 57 | + component.filter = 'remaining'; |
| 58 | + |
| 59 | + assert.htmlEqual(target.innerHTML, ` |
| 60 | + <div> |
| 61 | + <input type="checkbox"> |
| 62 | + <input type="text"><p>one</p> |
| 63 | + </div> |
| 64 | + <div> |
| 65 | + <input type="checkbox"> |
| 66 | + <input type="text"><p>three</p> |
| 67 | + </div> |
| 68 | +
|
| 69 | + <p>remaining:one / done:two / remaining:three</p> |
| 70 | + `); |
| 71 | + |
| 72 | + await set_text(1, 'four'); |
| 73 | + |
| 74 | + assert.htmlEqual(target.innerHTML, ` |
| 75 | + <div> |
| 76 | + <input type="checkbox"> |
| 77 | + <input type="text"><p>one</p> |
| 78 | + </div> |
| 79 | + <div> |
| 80 | + <input type="checkbox"> |
| 81 | + <input type="text"><p>four</p> |
| 82 | + </div> |
| 83 | +
|
| 84 | + <p>remaining:one / done:two / remaining:four</p> |
| 85 | + `); |
| 86 | + |
| 87 | + assert.deepEqual(component.items, [ |
| 88 | + { done: false, text: 'one' }, |
| 89 | + { done: true, text: 'two' }, |
| 90 | + { done: false, text: 'four' } |
| 91 | + ]); |
| 92 | + |
| 93 | + await set_done(0, true); |
| 94 | + |
| 95 | + assert.htmlEqual(target.innerHTML, ` |
| 96 | + <div> |
| 97 | + <input type="checkbox"> |
| 98 | + <input type="text"><p>four</p> |
| 99 | + </div> |
| 100 | +
|
| 101 | + <p>done:one / done:two / remaining:four</p> |
| 102 | + `); |
| 103 | + |
| 104 | + assert.deepEqual(component.items, [ |
| 105 | + { done: true, text: 'one' }, |
| 106 | + { done: true, text: 'two' }, |
| 107 | + { done: false, text: 'four' } |
| 108 | + ]); |
| 109 | + |
| 110 | + component.filter = 'done'; |
| 111 | + |
| 112 | + assert.htmlEqual(target.innerHTML, ` |
| 113 | + <div> |
| 114 | + <input type="checkbox"> |
| 115 | + <input type="text"><p>one</p> |
| 116 | + </div> |
| 117 | + <div> |
| 118 | + <input type="checkbox"> |
| 119 | + <input type="text"><p>two</p> |
| 120 | + </div> |
| 121 | +
|
| 122 | + <p>done:one / done:two / remaining:four</p> |
| 123 | + `); |
| 124 | + }, |
| 125 | +}; |
0 commit comments