state.heroes.forEach(function(hero) { rows.push(h('tr', [ h('td', hero.title), h('td', String(hero.gilded)), h('td', String(hero.level)) ])); });
it('should identity a correct tag', function() { var div = h('div'); var p = h('p'); expect(isTag(div, 'div')).to.be.true; expect(isTag(p, 'p')).to.be.true; });
it('should identity an incorrct tag', function() { var div = h('div'); var p = h('p'); expect(isTag(div, 'p')).to.be.false; expect(isTag(p, 'div')).to.be.false; })
it('should identify when the caret is within a note', function(){ var marker = h('em.scribe-marker'); var tree = h('gu-note', [ marker ]); tree = new VFocus(tree); expect(isSelectionWithinNote(tree)).to.be.true; });
beforeEach(function() { var canDownTree = h('div', [ h('p') ]); top = canDownTree; bottom = canDownTree.children[0]; });
function vrenderFooter() { return h('footer#info', [ h('p', ['Double-click to edit a todo']), h('p', ['Written by Jim Fitzpatrick']), h('p', [ 'Part of ', h('a', { href: 'http://todomvc.com' }, ['TodoMVC']) ]) ]); }
it('should return the correct number of notes', function(){ var tree = h('div', [ h('gu-note', {'data-note-id': 1}), h('gu-note', {'data-note-id': 2}), h('gu-note', {'data-note-id': 1}) ]); tree = new VFocus(tree); expect(findNoteById(tree, 1).length).to.equal(2); expect(findNoteById(tree, 2).length).to.equal(1); });
function vrenderSectionFooter(todosData) { var numIncomplete = todosData .filter(function(todo) { return !todo.completed; }).length, numCompleted = todosData .filter(function(todo) { return todo.completed; }).length, children = [ h('span#todo-count', [ h('strong', [ numIncomplete.toString() ]), (numIncomplete === 1) ? ' item left' : ' items left' ]), h('ul#filters', [ h('li', [ h('a', { href: '#/', className: 'selected' }, ['All']), h('a', { href: '#/active' }, ['Active']), h('a', { href: '#/completed' }, ['Completed']) ]) ]) ]; if (numCompleted) { children.push( h('button#clear-completed', { 'ev-click': function(ev) { todoClearCompletedTodos$.onNext(ev); } }, ['Clear completed (' + numCompleted + ')']) ); } return h('footer#footer', { style: { display: todosData.length ? 'block' : 'none' } }, children); }
it('should return true when a selection is within a note', function() { var tree = h('gu-note', [ h('em.scribe-marker'), new VText('This is some text'), h('em.scribe-marker') ]) tree = new VFocus(tree); expect(isSelectionWithinNote(tree)).to.be.true; });
function vrenderTopButtons() { return h('div.topButtons', {}, [ h('button', {'ev-click': function (ev) { addOneClicks$.onNext(ev); }}, 'Add New Item' ), h('button', {'ev-click': function (ev) { addManyClicks$.onNext(ev); }}, 'Add Many Items' ) ]); }
it('should return false if the caret is next to a flag', function(){ var focus = h('p', [ h('em.scribe-marker'), h('gu-flag', [ new VText('some'), new VText('content') ]) ]); focus = new VFocus(focus); expect(isCaretNextToNote(focus)).to.be.false; expect(isCaretNextToNote(focus, 'next', 'gu-flag')).to.be.true; });
function vrenderSectionHeader() { return h('header#header', {}, [ h('h1', ['todos']), h('input', { id: 'new-todo', value: '', placeholder: 'What needs to be done?', autofocus: true, 'ev-keypress': function(ev) { newTodoKeypress$.onNext(ev); } }) ]); }
it('should remove all empty notes', function() { var tree = h('div', [ h('gu-note'), h('gu-note') ]); tree = new VFocus(tree); removeEmptyNotes(tree); expect(tree.vNode.children.length).to.equal(0); });
beforeEach(function() { var tree = h('div', [ h('p', [ h('b', [ new VText('Some bolded text') ]), new VText('This is some text') ]), h('p', [ new VText('This is some more text') ]) ]); treeFocus = new VFocus(tree); });
it('should return false if the caret is in a different paragraph', function(){ var focus = h('div', [ h('p', [ h('gu-note', [ new VText('This'), new VText('is') ]) ]), h('p', [ h('em.scribe-marker') ]) ]); focus = new VFocus(focus); expect(isCaretNextToNote(focus, 'prev')).to.be.false; });
function render(state) { return h("div", [ h("div", [ h("span", "hello "), h("span.name", state.name) ]), h("ul", state.fruits.map(renderFruit)) ]) function renderFruit(fruitName) { return h("li", [ h("span", fruitName) ]) } }
test('replace content (with h generated content)', function(t) { t.plan(2); fragment({ '.content': h('span', 'foo') }, function(err, output) { t.ifError(err); t.equal(output, '<html>\n<body>\n<div class="content"><span>foo</span></div>\n</body>\n</html>\n'); }); });
function vrender(inputDiagrams, marbleMouseDown$, completionMouseDown$) { return h("div", {}, inputDiagrams.map(function(diagramData) { return Diagram.vrender(diagramData, true, marbleMouseDown$, completionMouseDown$); }) ) }
it('should return false for in-valid attributes', function() { var div = h('div'); expect(hasAttribute(div, 'title', 'This is a title')).to.be.false; expect(hasAttribute(div, 'data-component', 'my-component')).to.be.false; });
it('should identify when a selection spans a note on the right hand side', function(){ var tree = h('p', [ new VText('This'), new VText('is'), h('gu-note', [ h('em.scribe-marker'), new VText('some'), ]), new VText('content'), h('em.scribe-marker') ]); tree = new VFocus(tree); var result = isSelectionWithinNote(tree); expect(result).to.be.true; });
it('should leave notes where some child is non-empty', function() { var tree = h('div', [ h('gu-note'), h('gu-note', [ new VText('This is some text'), new VText('This is some text'), new VText('') ]), h('gu-note') ]) tree = new VFocus(tree); removeEmptyNotes(tree); expect(tree.vNode.children.length).to.equal(1); })
function list(state) { var ret = []; state.output.forEach(function(o) { ret.push(h('li', o)); }); return h('ul', ret); }
beforeEach(function() { text1 = new VText('This is some text'); text1 = new VFocus(text1); text2 = new VText('This is some text2'); text2 = new VFocus(text2); div = h('div'); div = new VFocus(div); });
it('should select note contents', function() { var tree = h('p', [ h('gu-note', [ new VText('This'), new VText('is'), new VText('some'), h('em.scribe-marker'), new VText('content'), ]) ]); tree = new VFocus(tree); var noteSegment = tree.next().next(); selectNote(noteSegment); expect(tree.next().vNode.children[0].tagName).to.equal('em'); expect(tree.next().vNode.children.slice(-1)[0].tagName).to.equal('em'); });
module.exports = function (state) { return h('html', [ h('head', [ h('title', state.title || 'Wave Farm'), h('link', { href: '//fonts.googleapis.com/css?family=Roboto:400,300', rel: 'stylesheet' }), h('link', {href: '/style.css', rel: 'stylesheet'}), h('script', {src: '/ua.js'}) ]), h('body', [ require('./')(state), require('./listen')(state), h('script', 'window.initialState = ' + JSON.stringify(state)), h('script', {src: '/scripts/jquery.js'}), h('script', {src: '/bundle.js'}) ]) ]) }
it('should unwrap a note', function() { var note = h('gu-note', [ new VText('This'), new VText('is'), new VText('some'), new VText('text'), ]); var div = new VFocus(h('div', [note])); var tree = new VFocus(note, div); tree = unWrapNote(tree); expect(tree.vNode.tagName).not.to.equal('gu-note'); tree.vNode.children.forEach(function(child) { expect(child.tagName).not.to.equal('gu-note'); }); });
function composeSummary (params, total) { var sum = [] if (params.q || params.date) sum.push('A search') if (params.q) { sum.push(' for ') sum.push(h('b', params.q)) } if (params.date && params.date2) { sum.push(' between ') sum.push(h('b', params.date)) sum.push(' and ') sum.push(h('b', params.date2)) } else if (params.date) { sum.push(' on ') sum.push(h('b', params.date)) } if (params.q || params.date) sum.push(' returned ') sum.push(h('b', ''+total)) sum.push(' items.') return sum }
function vrenderItem(itemData) { return h('div', { style: { 'border': '1px solid #000', 'background': 'none repeat scroll 0% 0% ' + itemData.color, 'width': itemData.width + 'px', 'height': '70px', 'display': 'block', 'padding': '20px', 'margin': '10px 0px' }}, [ h('input', { type: 'text', value: itemData.color, 'attributes': {'data-item-id': itemData.id}, 'ev-input': function (ev) { itemColorChanged$.onNext(ev); } }), h('div', [ h('input', { type: 'range', min:'200', max:'1000', value: itemData.width, 'attributes': {'data-item-id': itemData.id}, 'ev-input': function (ev) { itemWidthChanged$.onNext(ev); } }) ]), h('div', String(itemData.width)), h('button', { 'attributes': {'data-item-id': itemData.id}, 'ev-click': function (ev) { removeClicks$.onNext(ev); } }, 'Remove') ] ); }
.map(function(todosData) { todosData = todosData || []; return h('div.container', {}, [ h('section#todoapp', [ vrenderSectionHeader(), h('section#main', { style: { display: todosData.length ? 'block' : 'none' } }, [ h('input#toggle-all', { type: 'checkbox', 'ev-change': function(ev) { todoToggleAll$.onNext(ev); } }), h('label', { attributes: { 'for': 'toggle-all' } }, ['Mark all as complete']), h('ul', { id: 'todo-list' }, [ todosData.map(vrenderTodo) ]) ]), vrenderSectionFooter(todosData) ]), vrenderFooter() ]); });
beforeEach(()=>{ afterFocus = h('p', [ h('gu-note', [ new VText('\u200B'), new VText('this'), new VText('is'), new VText('some'), new VText('content') ]), new VText('\u200B'), h('em.scribe-marker') ]); afterFocus = new VFocus(afterFocus); beforeFocus = h('p', [ h('em.scribe-marker'), h('gu-note', [ new VText('\u200B'), new VText('this'), new VText('is'), new VText('some'), new VText('content') ]), new VText('\u200B'), ]); beforeFocus = new VFocus(beforeFocus); });