Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion test/morph-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import QUnit from 'qunitjs';
import Morph from 'morph-range';

import { document, fragment, element, comment, domHelper } from 'support';
import { document, fragment, element, comment, text, domHelper } from 'support';

QUnit.module('Morph tests');

Expand Down Expand Up @@ -65,3 +65,66 @@ QUnit.test("When destroying a morph, do not explode if a parentNode does not exi
morph.destroy();
assert.ok(true, "The test did not crash");
});

// Chrome bug https://code.google.com/p/chromium/issues/detail?id=475337
QUnit.test('can setContent options on a morph with whitespace', function (assert) {
var morph = new Morph(domHelper());
var select = element('select');
var placeholder = comment();
select.appendChild(placeholder);
morph.setNode(placeholder);

var frag = fragment(
element('option'),
text(''),
element('option')
);

morph.setContent(frag);

assert.equal(select.selectedIndex, 0, 'selectedIndex is the first item inserted');
});

QUnit.test('can setContent selected option on a morph with whitespace', function (assert) {
var morph = new Morph(domHelper());
var select = element('select');
var placeholder = comment();
select.appendChild(placeholder);
morph.setNode(placeholder);

var selectedOption = element('option');
selectedOption.selected = true;

var frag = fragment(
selectedOption,
text(''),
element('option')
);

morph.setContent(frag);

assert.equal(select.selectedIndex, 0, 'selectedIndex is the first item');
});

QUnit.test('can setContent option with a selectedIndex already set', function (assert) {
var morph = new Morph(domHelper());
var select = element('select');
var placeholder = comment();
select.appendChild(placeholder);

var selectedOption = element('option');
selectedOption.selected = true;
select.appendChild(selectedOption);

morph.setNode(placeholder);

var frag = fragment(
element('option'),
text(''),
element('option')
);

morph.setContent(frag);

assert.equal(select.selectedIndex, 2, 'selectedIndex is the first item');
});