(function() {
'use strict';
if (window.guard && !guard.isNavigatorSupported) { return; }
require.config({ baseUrl: '../', paths: { hlf: 'dist', test: 'tests/js' } });
define(['test/base', 'hlf/media-grid'], function(base, MediaGrid) {
if (window.QUnit) {
const { module, test } = QUnit;
module('HLF.MediaGrid', {
beforeEach() {
let element = document.createElement('div');
element.innerHTML = (
`<div>
<div class="js-mg-item"></div>
<div class="js-mg-item"></div>
<div class="js-mg-item"></div>
</div>`
);
document.getElementById('qunit-fixture').appendChild(element);
this.mediaGrid = MediaGrid.extend(element);
},
});
test('#_updateMetrics', function(assert) {
const { mediaGrid } = this;
let { style } = mediaGrid.element;
style.boxSizing = 'border-box';
style.padding = '10px';
mediaGrid.itemElements.forEach((itemElement) => {
let { style } = itemElement;
style.borderWidth = '1px';
style.boxSizing = 'border-box';
style.marginRight = '10px';
style.padding = '9px';
style.width = style.height = '200px';
});
style = mediaGrid.element.parentElement.style;
style.width = '610px';
let metrics;
mediaGrid._updateMetrics({ hard: true });
metrics = mediaGrid.metrics;
assert.strictEqual(metrics.gutter, 10, 'It bases gutter on item margin sizes.');
assert.strictEqual(metrics.itemWidth, 200, "It uses the item's 'outerWidth' as width.");
assert.strictEqual(metrics.rowSize, 2, 'It bases row size on item and wrap sizes.');
assert.strictEqual(metrics.colSize, 2, 'It bases column size on row size.');
style.width = '620px';
mediaGrid._updateMetrics({ hard: true });
metrics = mediaGrid.metrics;
assert.strictEqual(metrics.rowSize, 3, 'It bases row size on item and wrap sizes.');
assert.strictEqual(mediaGrid.selectAllByClass('samples').length, 1,
'It cleans up after multiple hard updates.');
});
QUnit.start();
return true;
}
HLF Media Grid Visual Tests
Page | Source