All files / manuel/tests mithril.v0.2.x.js

100% Statements 287/287
100% Branches 0/0
100% Functions 21/21
100% Lines 282/282
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950  1x 1x 1x 1x 1x   1x 1x 1x 1x               1x   1x     1x                     1x         1x 1x           1x                                     1x       333x 62x             1x     1x   1x   1x   1x 44x     44x     1x   1x   1x                     1x     1x                       1x       1x   1x           1x               1x           1x             1x   1x         4x                                 1x     1x   1x 1x               1x           1x     1x       1x           1x           1x   1x                   1x     1x       1x           1x       1x     1x       1x           1x     1x       1x           1x       1x     1x       1x           1x     1x       1x             1x     1x       1x           1x           1x   1x   1x               1x           1x 1x   1x   1x     1x       1x     1x       1x             1x   1x 1x   1x           1x       1x   1x 3x         1x     1x   1x 1x 1x 1x   1x             1x 1x 1x 1x 1x   1x   1x                 1x   1x 1x   1x           1x           1x             1x   1x   1x               1x 1x 2x   1x   1x   3x         1x       1x 4x   1x   1x             1x 1x   1x 1x   5x           1x 1x   1x   1x 1x       1x           1x   1x   1x 1x       1x             1x 1x 1x 1x   1x           1x 1x   1x   4x               1x 4x   1x   1x                     8x   1x   1x             1x 1x   1x   1x 1x       1x   1x           1x             1x 1x   1x   1x 1x   1x           1x     1x 1x   1x   1x 1x   1x           1x     1x 1x 1x   1x 1x   1x           1x     1x 1x 1x 1x   1x   4x                 1x             1x 1x 1x   1x   1x           1x     1x 1x 4x     1x       1x   1x                 1x 1x 1x       1x 1x 4x     1x       1x   1x           1x 1x 1x       1x 1x 1x     1x   1x           1x 1x     1x 1x 1x     1x   1x           1x 1x     1x 1x 1x     1x   1x           1x 1x     1x 1x   4x     4x     4x       1x   1x   1x   4x                 1x           1x 1x     1x 1x 1x     1x 1x 1x       1x     1x           1x       1x             1x     1x   1x     1x             1x 1x   1x   1x           1x           1x             1x 1x   1x   1x           1x           1x               1x 1x   1x   1x               1x          
/* eslint-disable fp/no-mutating-methods, fp/no-mutation */
const test = require('tape')
const manuel = require('../')
const m = require('mithril')
const mithrilQuery = require('mithril-query')
const UNUSED_KEY_CODE = 1
 
const KEY_UP = 38
const KEY_DOWN = 40
const KEY_ESC = 27
const KEY_ENTER = 13
 
const {
	compose
	, append
	, prepend
	, split
	, join
} = require('ramda')
const render =
	require('mithril-node-render')
 
const renderStdout =
	compose(
		console.log
		, join('\n')
		, prepend('--HTML-BEGIN--')
		, append('--HTML-END--')
		, split('\n')
		, render
	)
 
function query(app){
	const context =
		mithrilQuery(app)
 
	const {
		first: $
		, find: $$
	} = context
	return { context, $, $$ }
}
 
 
function Model(){
 
	return {
		model: {
			list: [[]]
			,input: ['']
			,chosen: [null]
			,open: [false]
			,highlighted: [null]
		}
		,modelKeys: {
			list: 'list'
			,input: 'input'
			,chosen: 'chosen'
			,open: 'open'
			,highlighted: 'highlighted'
		}
	}
 
}
function mithrilAutocomplete({model, modelKeys}){
	return {
		autocomplete:
			manuel({
				hyperscript: m
				,get: k => model[k][0]
				,set: (k,v) => model[k].unshift(v)
			})
		,model
		,modelKeys
	}
}
 
test('Mithril v0.2.x', function(t){
 
	const { model, modelKeys, autocomplete } =
		mithrilAutocomplete( Model() )
 
	var overrides = {}
 
	const App = {
		controller: function Controller(){
			return function view(){
				return autocomplete(modelKeys, overrides)
			}
		}
		,view: f => f()
	}
 
	const { $, $$, context } = query(App)
 
	t.comment('Basic Rendering'); {
 
		t.equals(
			render(
				m('.manuel-complete'
					,m('input', { value: "" })
					,m('ul')
				)
			)
			, render(context.rootEl)
			, 'Basic structure renders'
		)
 
		model.input.unshift('Che'); context.redraw()
 
 
		t.equals(
			render(
				m('.manuel-complete.not-empty'
					,m('input', { value: model.input[0]})
					,m('ul')
				)
			)
			, render(context.rootEl)
			, 'Autocomplete updates to reflect model, not-empty classes added'
 
		)
 
		$('input').attrs.oninput({
			currentTarget: { value: 'Cher' }
		})
 
		context.redraw()
 
		t.equals(
			model.input[0]
			, 'Cher'
			, 'Input event updated model'
		)
 
		t.equals(
			context.rootEl.attrs.className
			,'manuel-complete not-empty'
			,`Typing with an empty list did not show the drawer
			but did add not-empty class to input
			`
		)
 
		t.equals(
			model.open[0]
			, true
			,'Typing set open to true, even though the list is empty'
		)
 
		model.list.unshift([
			'Cher'
			,'Cherry'
			,'Cherries'
			,'Chereth Cutestory'
		])
 
		context.redraw()
 
		t.equals(
			render(
				m('.manuel-complete.open.not-empty.loaded'
					,m('input', { value: model.input[0]})
					,m('ul', model.list[0].map(
						x => m(
							'li', { class: ""}, [
								m('mark', 'Cher')
								, x.slice(4)
							]
						)
					) )
				)
			)
			, render(context.rootEl)
			, `After adding items to the list:
				open and loaded are both added to the root classnames
				and matching text is highlighted
			`
 
		)
 
		context.redraw()
	}
 
	t.comment('Keyboard Interaction'); {
 
		const prevented = []
		context.rootEl.attrs.onkeydown({
			keyCode: UNUSED_KEY_CODE
			,preventDefault(){
				// istanbul ignore next
				prevented.unshift(UNUSED_KEY_CODE)
			}
		})
 
		t.equals(
			prevented.length
			, 0
			, 'Pressing an unsed key does not e.preventDefault('
		)
 
		context.rootEl.attrs.onkeydown({
			keyCode: KEY_DOWN
			,preventDefault(){
				prevented.unshift(KEY_DOWN)
			}
		})
 
		t.deepEquals(
			prevented
			,[KEY_DOWN]
			,'Pressing a used key (KEY_DOWN) did prevent default'
		)
 
		t.equals(
			model.list[0][0]
			,model.highlighted[0]
			,'First item on a KEY DOWN led to the first item being highlighted'
		)
 
		context.redraw()
 
		t.equals(
			render($('.highlight'))
			,render(
				m('li.highlight'
					,m('mark', model.highlighted[0] )
				)
			)
			,'Highlight class added to element'
		)
 
		context.rootEl.attrs.onkeydown({
			keyCode: KEY_DOWN
			,preventDefault(){
				prevented.unshift(KEY_DOWN)
			}
		})
 
		t.equals(
			model.list[0][1]
			,model.highlighted[0]
			,'on press KEY DOWN again led to the second item being highlighted'
		)
 
		model.highlighted.unshift(
			model.list[0][0]
		)
 
		context.rootEl.attrs.onkeydown({
			keyCode: KEY_UP
			,preventDefault(){
				prevented.unshift(KEY_UP)
			}
		})
 
		t.equals(
			model.list[0][model.list[0].length-1]
			,model.highlighted[0]
			,'KEY UP on first item leads to wrap around to last item highlight'
		)
 
		context.rootEl.attrs.onkeydown({
			keyCode: KEY_DOWN
			,preventDefault(){
				prevented.unshift(KEY_DOWN)
			}
		})
 
		t.equals(
			model.list[0][0]
			,model.highlighted[0]
			,'KEY DOWN on last item wraps around to first item highlight'
		)
 
		model.highlighted.unshift(
			model.list[0][model.list[0].length-1]
		)
 
		context.rootEl.attrs.onkeydown({
			keyCode: KEY_UP
			,preventDefault(){
				prevented.unshift(KEY_UP)
			}
		})
 
		t.equals(
			model.list[0][model.list[0].length -2 ]
			,model.highlighted[0]
			,'KEY UP on last item steps backwards'
		)
 
		context.rootEl.attrs.onkeydown({
			keyCode: KEY_DOWN
			,preventDefault(){
				prevented.unshift(KEY_DOWN)
			}
		})
 
		t.equals(
			model.list[0][model.list[0].length -1 ]
			,model.highlighted[0]
			,'KEY DOWN in middle of list steps forward'
		)
 
 
		context.rootEl.attrs.onkeydown({
			keyCode: KEY_ESC
			,preventDefault(){
				prevented.unshift(KEY_ESC)
			}
		})
 
		t.equals(
			model.open[0]
			,false
			,'Escape Key closes the dialog'
		)
 
		t.equals(
			prevented[0]
			,KEY_ESC
			,'Pressing escape prevents default'
		)
 
		model.input.unshift('XYZ')
 
		context.redraw()
 
		context.rootEl.attrs.onkeydown({
			keyCode: KEY_ENTER
			,preventDefault(){
				// istanbul ignore next
				prevented.unshift(KEY_ENTER)
			}
		})
 
		t.equals(
			model.chosen[0]
			, null
			, 'Pressing enter when nothing is highlighted does nothing'
		)
 
		model.input.unshift('Ch')
		model.open.unshift(true)
 
		context.redraw()
 
		context.rootEl.attrs.onkeydown({
			keyCode: KEY_DOWN
			,preventDefault(){
				prevented.unshift(KEY_DOWN)
			}
		})
 
		context.rootEl.attrs.onkeydown({
			keyCode: KEY_ENTER
			,preventDefault(){
				prevented.unshift(KEY_ENTER)
			}
		})
 
		t.equals(
			model.chosen[0]
			,model.highlighted[0]
			,'Pressing enter when highlighting chooses the highlighted item'
		)
	}
 
	t.comment('Filtering and Sorting'); {
 
		model.input.unshift('')
		context.redraw()
 
		t.equals(
			$$('li').length
			,model.list[0].length
			,'When input is empty default filter always returns true'
		)
 
		model.list.unshift(
			['bbbb', 'cccc', 'aaaa']
		)
 
		context.redraw()
 
		t.deepEquals(
			$$('li').map( x => x.children[0] )
			,['aaaa', 'bbbb', 'cccc']
			,'When terms are the same length, sort by alphabetical order'
		)
 
		model.list.shift()
	}
 
	t.comment('Overrides'); {
 
		t.comment('null overrides'); {
			overrides = null
			model.input.unshift('')
			context.redraw()
 
			t.equals(
				$$('li').length
				, 4
				, 'manuel runs fine with null overrides'
			)
		}
 
		t.comment('minChars'); {
			overrides = {}
			overrides.minChars = 0
			model.input.unshift('')
			model.open.unshift(true)
 
			context.redraw()
 
			t.equals(
				$('.manuel-complete')
					.attrs.className.includes('open')
				,true
				,'Overriding minchars allows drawer to open even with "" input'
			)
 
		}
 
		t.comment('maxItems'); {
 
			overrides.maxItems = 0
			context.redraw()
 
			t.equals(
				$$('li').length
				, 0
				, 'Setting maxItems=0 prevents open rendering of suggestions'
			)
 
			t.equals(
				model.open[0]
				,true
				,'Despite model.open being set to true...'
			)
 
			t.equals(
				$('.manuel-complete')
					.attrs.className.includes('open')
				,false
				,'The open class is not set because there are no items rendered'
			)
 
			overrides.showingDrawer = true
 
			context.redraw()
 
			t.equals(
				$('.manuel-complete')
					.attrs.className.includes('open')
				,true
				,'Overriding showingDrawer forces suggestions list to render'
			)
		}
 
		t.comment('sort'); {
			model.list.unshift(['B','A','C'])
			overrides = { sort: () => 0 }
 
			context.redraw()
 
			t.deepEquals(
				$$('li')
					.map( x => x.children[0] )
				,model.list[0]
				,'Overriding sort to a noop leaves list as is'
			)
 
			model.list.shift()
 
		}
 
		t.comment('filter'); {
			overrides = { filter: () => false }
 
			context.redraw()
 
			t.deepEquals(
				$$('li').length
				,0
				,'Overriding filter to K(false) forces the list to be empty'
			)
		}
 
		t.comment('filteredList'); {
			overrides = { filteredList: ['Not', 'even', 'in', 'the', 'model']}
 
			context.redraw()
			t.deepEquals(
				$$('li')
					.map( x => x.children[0] )
				, overrides.filteredList
				,'Overriding filteredList forces suggestions to be different'
			)
		}
 
		t.comment('chosen'); {
			overrides = { choose(){} }
 
			model.chosen.unshift(null)
 
			context.redraw()
			$('li').attrs.onmousedown({
				stopPropagation(){}
			})
 
			t.equals(
				model.chosen[0]
				,null
				,'Overriding choose=noop prevents clickItem from setting chosen'
			)
 
			overrides = { clickItem(){} }
 
			model.chosen.unshift(null)
 
			context.redraw()
			$('li').attrs.onmousedown({
				stopPropagation(){}
			})
 
			t.equals(
				model.chosen[0]
				,null
				,'Overriding clickItem = noop prevents setting chosen'
			)
		}
 
		t.comment('PATTERN_INPUT'); {
			overrides = { PATTERN_INPUT: null }
			model.input.unshift('Ch')
			context.redraw()
 
			t.equals(
				$$('mark').length
				,0
				,'Setting PATTERN_INPUT=null prevents mark highlighting'
			)
 
			overrides = { PATTERN_INPUT: /th/gi }
			context.redraw()
 
			t.equals(
				render($$('li')
					.find( x => mithrilQuery(x).find('mark').length > 0 )
					.children
				)
				,render(['Chere',m('mark', 'th'), ' Cutestory'])
				,'Setting PATTERN_INPUT=/th/ overrides input matching'
			)
		}
 
		t.comment('mark'); {
			overrides = { mark: x => m('blink', x) }
 
			context.redraw()
 
			t.equals(
				render($('li'))
				,render(
					m('li', { class:"" }, [
						m('blink', 'Ch')
						,'er'
					])
				)
				,'Overriding mark to m("blink", x) does what you expect'
			)
 
			overrides = { highlight: x => x }
 
			context.redraw()
 
			t.equals(
				$$('mark').length
				,0
				,'Setting highlight to I prevents marking'
			)
		}
 
		t.comment('oninput'); {
			context.redraw()
 
			overrides =
				{ oninput: (e) => {
					const value = e.currentTarget.value
					model.input.unshift(value.split('').reverse().join(''))
				}
				}
 
			context.redraw()
 
			$('input').attrs.oninput({
				currentTarget: {
					value: 'OLLEH'
				}
			})
 
			t.equals(
				model.input[0]
				,'HELLO'
				,'Overriding oninput to reverse input updated the model'
			)
		}
 
		t.comment('onfocus'); {
			overrides = { onfocus() {} }
 
			context.redraw()
 
			model.open.unshift(false)
			$('input').attrs.onfocus()
 
			t.equals(
				model.open[0]
				,false
				,'Overriding onfocus to a noop leaves model.open = false'
			)
 
			model.open.shift()
		}
 
		t.comment('onblur'); {
			overrides = { onblur() {} }
 
			context.redraw()
 
			model.open.unshift(true)
			$('input').attrs.onblur()
 
			t.equals(
				model.open[0]
				,true
				,'Overriding onblur to a noop leaves model.open = true'
			)
 
			model.open.shift()
		}
 
		t.comment('close'); {
			overrides = { close() {} }
			context.redraw()
 
			model.open.unshift(true)
			$('input').attrs.onblur()
 
			t.equals(
				model.open[0]
				,true
				,'Overriding close to a noop leaves model.open = false'
			)
 
			model.open.shift()
		}
 
		t.comment('onkeydown'); {
			overrides = { onkeydown(){} }
			context.redraw();
			const prevents = []
 
			;[KEY_DOWN, KEY_ENTER, KEY_ESC, KEY_UP]
				.forEach(function(keyCode){
					context.rootEl.attrs.onkeydown({
						keyCode
						,preventDefault(){
							// istanbul ignore next
							prevents.push(keyCode)
						}
					})
				})
 
			t.equals(
				prevents.length
				, 0
				,'Overriding onkeydown disables every key interaction'
			)
		}
 
		t.comment('classNames'); {
			overrides = { classNames(){
				return 'manuel-complete something else'
			}}
			context.redraw()
 
			t.equals(
				context.rootEl.attrs.className
				,'manuel-complete something else'
				,'Overriding classnames via classNames'
			)
 
			overrides = {}
		}
 
		t.comment('itemClassNames'); {
			overrides = { itemClassNames(){
				return 'wowee'
			}}
 
			model.input.unshift(
				model.list[0][0]
			)
 
			context.redraw()
 
			t.equals(
				$('ul')
					.children[0]
					.attrs
					.className
				, 'wowee'
				, 'item classname changed to override value'
			)
 
			model.input.shift()
			overrides = {}
			context.redraw()
 
		}
 
		t.comment('renderItem'); {
			overrides = { renderItem(){
				return 'jambalaya'
			}}
 
			model.input.unshift(
				model.list[0][0]
			)
 
			context.redraw()
 
			t.equals(
				$('ul').children[0]
				, 'jambalaya'
				, 'item rendered differently after override'
			)
 
			model.input.shift()
			overrides = {}
			context.redraw()
 
		}
 
		t.comment('renderItems'); {
			overrides = { renderItems(){
				return 'jambalaya'
			}}
 
			context.redraw()
 
			t.equals(
				context.rootEl.children[1]
				, 'jambalaya'
				, 'ul replace with override value'
			)
 
			overrides = {}
			context.redraw()
		}
 
		t.comment('renderRoot'); {
			overrides = { renderRoot(){
				return 'jambalaya'
			}}
 
			context.redraw()
 
			t.equals(
				context.rootEl
				, 'jambalaya'
				, 'root element replace with override value'
			)
 
			overrides = {}
			context.redraw()
		}
 
		t.comment('renderInput'); {
			overrides = { renderInput(){
				return 'jambalaya'
			}}
 
			context.redraw()
 
			t.equals(
				context.rootEl.children[0]
				, 'jambalaya'
				, 'input element replace with override value'
			)
 
			overrides = {}
			context.redraw()
		}
 
		t.comment('keyboard overrides'); {
			overrides = {
				keyboardSubmit(){
					return []
				}
				,keyboardDismiss(){
					return []
				}
				,keyboardNavigate(){
					return []
				}
			}
 
			context.redraw()
 
			const prevents = []
 
			;[KEY_DOWN, KEY_ENTER, KEY_ESC, KEY_UP]
				.forEach(function(keyCode){
					context.rootEl.attrs.onkeydown({
						keyCode
						,preventDefault(){
							// istanbul ignore next
							prevents.push(keyCode)
						}
					})
				})
 
			t.equals(
				prevents.length
				, 0
				,'Overriding keyboard fns disables every key interaction'
			)
 
			overrides = {}
			context.redraw()
		}
 
		renderStdout(context.rootEl)
		overrides = {}
		context.redraw()
	}
 
	t.comment('Focus and Blur - Open and Close'); {
		model.open.unshift(false)
		model.input.unshift(
			model.list[0][0].slice(0,2)
		)
 
		$('input')
			.attrs.onfocus()
 
		t.equals(
			model.open[0]
			,true
			,'Clicking on the input opens the suggestion list'
		)
 
		$('input')
			.attrs.onblur()
 
 
		t.equals(
			model.open[0]
			,false
			,'Clicking anywhere else closes the suggestion list'
		)
 
		{
			model.open.unshift(true)
 
			const oldLength =
				model.open.length
 
			$('input')
				.attrs.onfocus()
 
			t.equals(
				oldLength
				,model.open.length
				,'Open is not set if its already set.'
			)
		}
 
		model.chosen.unshift('Hello')
		model.open.unshift(false)
 
		context.redraw()
 
		$('input').attrs.oninput({
			currentTarget: {
				value: 'Something Else'
			}
		})
 
		t.equals(
			model.chosen[0]
			,null
			,'If inputted value does not match chosen, chosen is set to null'
		)
 
		t.equals(
			model.open[0]
			,true
			,'If suggestions list is closed, typing will open it'
		)
 
		{
			model.chosen.unshift( 'Same as input' )
			model.open.unshift(true)
 
			const oldLength = model.open.length
 
			$('input').attrs.oninput({
				currentTarget: {
					value: 'Same as input'
				}
			})
 
			t.equals(
				model.chosen[0]
				,'Same as input'
				,'If inputted value doesmatch chosen, the value is retained'
			)
 
			t.equals(
				model.open.length
				,oldLength
				,'If suggestions is already open, typing will leave open unset'
			)
		}
 
		{
			model.open.unshift(false)
			const oldLength = model.open.length
 
			$('input').attrs.onblur()
 
			t.equals(
				oldLength
				,model.open.length
				,'When closing, if open is already false, it is left unset'
			)
		}
	}
 
	t.end()
})
 
// istanbul ignore next
// eslint-disable-next-line
process.on('unhandledRejection', r => console.error(r));