Skip to content

Commit

Permalink
Add parameterizedComponentModule helper, test w/ and w/out ember arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Oct 30, 2019
1 parent c5c9cee commit d7d8405
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 12 deletions.
15 changes: 13 additions & 2 deletions tests/dummy/app/utils/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import { A as emberA } from '@ember/array';
import { toBase26 } from './base-26';
import faker from 'faker';

const DEFAULT_USE_EMBER_ARRAY = true;
let useEmberArray = DEFAULT_USE_EMBER_ARRAY;

export function configureTableGeneration({ useEmberArray: _useEmberArray }) {
useEmberArray = _useEmberArray;
}

export function resetTableGenerationConfig() {
useEmberArray = DEFAULT_USE_EMBER_ARRAY;
}

export function getRandomInt(max, min) {
return faker.random.number({ min, max });
}
Expand Down Expand Up @@ -43,7 +54,7 @@ export function generateRows(rowCount, depth, format, idPrefix = '') {
arr.push(row);
}

return emberA(arr);
return useEmberArray ? emberA(arr) : arr;
}

export function generateColumn(id, options) {
Expand Down Expand Up @@ -95,5 +106,5 @@ export function generateColumns(
columns[columnCount - i - 1].isFixed = 'right';
}

return emberA(columns);
return useEmberArray ? emberA(columns) : columns;
}
9 changes: 7 additions & 2 deletions tests/helpers/generate-table.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import hbs from 'htmlbars-inline-precompile';
import wait from 'ember-test-helpers/wait';
import { generateColumns, generateRows } from 'dummy/utils/generators';
import {
configureTableGeneration,
generateColumns,
generateRows,
resetTableGenerationConfig,
} from 'dummy/utils/generators';

// reexport for use in tests
export { generateColumns, generateRows };
export { configureTableGeneration, resetTableGenerationConfig, generateColumns, generateRows };

const fullTable = hbs`
<div style="height: 500px;">
Expand Down
19 changes: 19 additions & 0 deletions tests/helpers/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,22 @@ export function componentModule(moduleName, callback) {

callback();
}

export function parameterizedComponentModule(moduleName, parameters, callback) {
Object.keys(parameters).forEach(key => {
let { values, hooks } = parameters[key];

for (let value of values) {
moduleForComponent('ember-table', `${moduleName} with param ${key}=${value}`, {
integration: true,
beforeEach() {
hooks.beforeEach && hooks.beforeEach(value);
},
afterEach() {
hooks.afterEach && hooks.afterEach(value);
},
});
callback();
}
});
}
29 changes: 24 additions & 5 deletions tests/integration/components/headers/reorder-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { module, test, skip } from 'ember-qunit';

import { generateTable, generateColumns } from '../../../helpers/generate-table';
import { componentModule } from '../../../helpers/module';
import {
configureTableGeneration,
generateTable,
generateColumns,
resetTableGenerationConfig,
} from '../../../helpers/generate-table';
import { parameterizedComponentModule } from '../../../helpers/module';

import { find, findAll, scrollTo } from 'ember-native-dom-helpers';
import { mouseDown, mouseMove, mouseUp } from 'ember-table/test-support/helpers/mouse';
Expand Down Expand Up @@ -36,6 +41,20 @@ export async function scrollToEdge(targetElement, edgeOffset, direction) {
await mouseUp(targetElement);
}

const USE_EMBER_ARRAY_PARAMETERS = {
useEmberArray: {
values: [true, false],
hooks: {
beforeEach(value) {
configureTableGeneration({ useEmberArray: value });
},
afterEach() {
resetTableGenerationConfig();
},
},
},
};

async function reorderToLeftEdge(column, edgeOffset = 0) {
await scrollToEdge(column, edgeOffset, 'left', true);
}
Expand All @@ -45,7 +64,7 @@ async function reorderToRightEdge(column, edgeOffset = 0) {
}

module('Integration | headers | reorder', function() {
componentModule('reordering', function() {
parameterizedComponentModule('reordering', USE_EMBER_ARRAY_PARAMETERS, function() {
test('standard columns', async function(assert) {
await generateTable(this);

Expand Down Expand Up @@ -181,7 +200,7 @@ module('Integration | headers | reorder', function() {
});
});

componentModule('fixed columns', function() {
parameterizedComponentModule('fixed columns', USE_EMBER_ARRAY_PARAMETERS, function() {
test('left fixed column can be reordered with other left fixed columns', async function(assert) {
await generateTable(this, { columnOptions: { fixedLeftCount: 2 } });

Expand Down Expand Up @@ -290,7 +309,7 @@ module('Integration | headers | reorder', function() {
});
});

componentModule('subheaders', function() {
parameterizedComponentModule('subheaders', USE_EMBER_ARRAY_PARAMETERS, function() {
test('subheaders can be reordered', async function(assert) {
await generateTable(this, { columnCount: 1, columnOptions: { subcolumnCount: 2 } });

Expand Down
24 changes: 21 additions & 3 deletions tests/integration/components/row-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { module, test } from 'ember-qunit';

import { generateTable } from '../../helpers/generate-table';
import { componentModule } from '../../helpers/module';
import {
generateTable,
configureTableGeneration,
resetTableGenerationConfig,
} from '../../helpers/generate-table';
import { parameterizedComponentModule } from '../../helpers/module';

import TablePage from 'ember-table/test-support/pages/ember-table';
import { collection, hasClass } from 'ember-classy-page-object';
Expand All @@ -14,8 +18,22 @@ let table = new TablePage({
},
});

const USE_EMBER_ARRAY_PARAMETERS = {
useEmberArray: {
values: [true, false],
hooks: {
beforeEach(value) {
configureTableGeneration({ useEmberArray: value });
},
afterEach() {
resetTableGenerationConfig();
},
},
},
};

module('Integration | row', function() {
componentModule('basic', function() {
parameterizedComponentModule('basic', USE_EMBER_ARRAY_PARAMETERS, function() {
test('can use a custom row component', async function(assert) {
await generateTable(this, {
rowComponent: 'custom-row',
Expand Down

0 comments on commit d7d8405

Please sign in to comment.