-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
242ef05
commit ff6984c
Showing
2 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
import { test } from '@cofn/test-lib/client'; | ||
import { fromView, nextTick } from './utils.js'; | ||
|
||
const debug = document.getElementById('debug'); | ||
|
||
test('list is rendered and item within the list is updated', ({ eq }) => { | ||
const el = fromView( | ||
({ html }) => | ||
({ items = [] }) => | ||
// prettier-ignore | ||
html`<ul>${items.map(({ content, id }) => html`${id}::<li>${content}</li>`)}</ul>`, | ||
); | ||
|
||
debug.appendChild(el); | ||
eq(el.innerHTML, '<ul><!--before--><!--after--></ul>'); | ||
el.render({ | ||
items: [ | ||
{ id: 1, content: 'item1' }, | ||
{ id: 2, content: 'item2' }, | ||
{ id: 3, content: 'item3' }, | ||
], | ||
}); | ||
|
||
eq( | ||
el.innerHTML, | ||
'<ul><!--before--><li>item1</li><li>item2</li><li>item3</li><!--after--></ul>', | ||
); | ||
|
||
el.render({ | ||
items: [ | ||
{ id: 1, content: 'item1' }, | ||
{ id: 2, content: 'item2bis' }, | ||
{ id: 3, content: 'item3' }, | ||
], | ||
}); | ||
|
||
eq( | ||
el.innerHTML, | ||
'<ul><!--before--><li>item1</li><li>item2bis</li><li>item3</li><!--after--></ul>', | ||
); | ||
}); | ||
|
||
test('list is rendered and item within list is added', ({ eq }) => { | ||
const el = fromView( | ||
({ html }) => | ||
({ items = [] }) => | ||
// prettier-ignore | ||
html`<ul>${items.map(({ content, id }) => html`${id}::<li>${content}</li>`)}</ul>`, | ||
); | ||
|
||
debug.appendChild(el); | ||
eq(el.innerHTML, '<ul><!--before--><!--after--></ul>'); | ||
el.render({ | ||
items: [ | ||
{ id: 1, content: 'item1' }, | ||
{ id: 2, content: 'item2' }, | ||
{ id: 3, content: 'item3' }, | ||
], | ||
}); | ||
|
||
eq( | ||
el.innerHTML, | ||
'<ul><!--before--><li>item1</li><li>item2</li><li>item3</li><!--after--></ul>', | ||
); | ||
|
||
el.render({ | ||
items: [ | ||
{ id: 1, content: 'item1' }, | ||
{ id: 11, content: 'item11' }, | ||
{ id: 2, content: 'item2' }, | ||
{ id: 3, content: 'item3' }, | ||
], | ||
}); | ||
|
||
eq( | ||
el.innerHTML, | ||
'<ul><!--before--><li>item1</li><li>item11</li><li>item2</li><li>item3</li><!--after--></ul>', | ||
); | ||
}); | ||
|
||
test('list is rendered and item within list is removed', ({ eq }) => { | ||
const el = fromView( | ||
({ html }) => | ||
({ items = [] }) => | ||
// prettier-ignore | ||
html`<ul>${items.map(({ content, id }) => html`${id}::<li>${content}</li>`)}</ul>`, | ||
); | ||
|
||
debug.appendChild(el); | ||
eq(el.innerHTML, '<ul><!--before--><!--after--></ul>'); | ||
el.render({ | ||
items: [ | ||
{ id: 1, content: 'item1' }, | ||
{ id: 2, content: 'item2' }, | ||
{ id: 3, content: 'item3' }, | ||
], | ||
}); | ||
|
||
eq( | ||
el.innerHTML, | ||
'<ul><!--before--><li>item1</li><li>item2</li><li>item3</li><!--after--></ul>', | ||
); | ||
|
||
el.render({ | ||
items: [ | ||
{ id: 1, content: 'item1' }, | ||
{ id: 3, content: 'item3' }, | ||
], | ||
}); | ||
|
||
eq( | ||
el.innerHTML, | ||
'<ul><!--before--><li>item1</li><li>item3</li><!--after--></ul>', | ||
); | ||
}); | ||
|
||
test('list within a list is handled', ({ eq }) => { | ||
const el = fromView( | ||
({ html }) => | ||
({ items = [] }) => | ||
// prettier-ignore | ||
html`<ul>${items.map(({ children, id }) => html`${id}::<li><ul>${children.map(({ content, id: childId }) => html`${id+'-'+childId}::<li>${content}</li>`)}</ul></li>`)}</ul>`, | ||
); | ||
|
||
debug.appendChild(el); | ||
eq(el.innerHTML, '<ul><!--before--><!--after--></ul>'); | ||
el.render({ | ||
items: [ | ||
{ | ||
id: 1, | ||
children: [ | ||
{ content: 'item1', id: 'ch-1' }, | ||
{ content: 'item2', id: 'ch-2' }, | ||
], | ||
}, | ||
{ id: 2, children: [{ content: 'item11', id: 'ch-11' }] }, | ||
{ | ||
id: 3, | ||
children: [ | ||
{ content: 'item3', id: 'ch-3' }, | ||
{ content: 'item4', id: 'ch-4' }, | ||
{ content: 'item5', id: 'ch-5' }, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
eq( | ||
el.innerHTML, | ||
'<ul><!--before--><li><ul><!--before--><li>item1</li><li>item2</li><!--after--></ul></li><li><ul><!--before--><li>item11</li><!--after--></ul></li><li><ul><!--before--><li>item3</li><li>item4</li><li>item5</li><!--after--></ul></li><!--after--></ul>', | ||
); | ||
|
||
el.render({ | ||
items: [ | ||
{ | ||
id: 1, | ||
children: [{ content: 'item1', id: 'ch-1' }], | ||
}, | ||
{ | ||
id: 2, | ||
children: [ | ||
{ content: 'item11', id: 'ch-11' }, | ||
{ content: 'item2', id: 'ch-2' }, | ||
], | ||
}, | ||
{ | ||
id: 3, | ||
children: [ | ||
{ content: 'item3', id: 'ch-3' }, | ||
{ content: 'item4bis', id: 'ch-4' }, | ||
{ content: 'item5', id: 'ch-5' }, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
eq( | ||
el.innerHTML, | ||
'<ul><!--before--><li><ul><!--before--><li>item1</li><!--after--></ul></li><li><ul><!--before--><li>item11</li><li>item2</li><!--after--></ul></li><li><ul><!--before--><li>item3</li><li>item4bis</li><li>item5</li><!--after--></ul></li><!--after--></ul>', | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters