mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
bcbf57d590
Summary: This uses a newer version of mocha in grist-core so that tests can be run in parallel. That allows more tests to be moved without slowing things down overall. Tests moved are venerable browser tests; only the ones that "just work" or worked without too much trouble to are moved, in order to keep the diff from growing too large. Will wrestle with more in follow up. Parallelism is at the file level, rather than the individual test. The newer version of mocha isn't needed for grist-saas repo; tests are parallelized in our internal CI by other means. I've chosen to allocate files to workers in a cruder way than our internal CI, based on initial characters rather than an automated process. The automated process would need some reworking to be compatible with mocha running in parallel mode. Test Plan: this diff was tested first on grist-core, then ported to grist-saas so saas repo history will correctly track history of moved files. Reviewers: jarek Reviewed By: jarek Subscribers: jarek Differential Revision: https://phab.getgrist.com/D3927
93 lines
3.0 KiB
JavaScript
93 lines
3.0 KiB
JavaScript
var assert = require('chai').assert;
|
|
var RecentItems = require('app/common/RecentItems');
|
|
|
|
describe('RecentItems', function() {
|
|
let simpleList = ['foo', 'bar', 'baz'];
|
|
|
|
let objList = [
|
|
{ name: 'foo', path: '/foo' },
|
|
{ name: 'bar', path: '/bar' },
|
|
{ name: 'baz', path: '/baz' },
|
|
];
|
|
|
|
describe("listItems", function() {
|
|
it("should return a valid list", function() {
|
|
let recentItems = new RecentItems({
|
|
intialItems: simpleList
|
|
});
|
|
assert.deepEqual(recentItems.listItems(), ['foo', 'bar', 'baz']);
|
|
});
|
|
|
|
it("should return a valid list given a keyFunc", function() {
|
|
let recentItems = new RecentItems({
|
|
intialItems: objList,
|
|
keyFunc: item => item.path
|
|
});
|
|
assert.deepEqual(recentItems.listItems(), [
|
|
{ name: 'foo', path: '/foo' },
|
|
{ name: 'bar', path: '/bar' },
|
|
{ name: 'baz', path: '/baz' },
|
|
]);
|
|
});
|
|
|
|
it("should produce a list of objects with unique keys", function() {
|
|
let recentItems = new RecentItems({
|
|
intialItems: [
|
|
{ name: 'foo', path: '/foo' },
|
|
{ name: 'bar', path: '/bar' },
|
|
{ name: 'foo', path: '/foo' },
|
|
{ name: 'baz', path: '/baz' },
|
|
{ name: 'foobar', path: '/foo' },
|
|
],
|
|
keyFunc: item => item.path
|
|
});
|
|
assert.deepEqual(recentItems.listItems(), [
|
|
{ name: 'bar', path: '/bar' },
|
|
{ name: 'baz', path: '/baz' },
|
|
{ name: 'foobar', path: '/foo' }
|
|
]);
|
|
let recentItems2 = new RecentItems({
|
|
intialItems: simpleList,
|
|
});
|
|
assert.deepEqual(recentItems2.listItems(), ['foo', 'bar', 'baz']);
|
|
for(let i = 0; i < 30; i++) {
|
|
recentItems2.addItems(simpleList);
|
|
}
|
|
assert.deepEqual(recentItems2.listItems(), ['foo', 'bar', 'baz']);
|
|
});
|
|
|
|
it("should produce a list with the correct max length", function() {
|
|
let recentItems = new RecentItems({
|
|
intialItems: objList,
|
|
maxCount: 2,
|
|
keyFunc: item => item.path
|
|
});
|
|
assert.deepEqual(recentItems.listItems(), [
|
|
{ name: 'bar', path: '/bar' },
|
|
{ name: 'baz', path: '/baz' }
|
|
]);
|
|
recentItems.addItem({ name: 'foo', path: '/foo' });
|
|
assert.deepEqual(recentItems.listItems(), [
|
|
{ name: 'baz', path: '/baz' },
|
|
{ name: 'foo', path: '/foo' }
|
|
]);
|
|
recentItems.addItem({name: 'BAZ', path: '/baz'});
|
|
assert.deepEqual(recentItems.listItems(), [
|
|
{ name: 'foo', path: '/foo' },
|
|
{ name: 'BAZ', path: '/baz' }
|
|
]);
|
|
let recentItems2 = new RecentItems({
|
|
intialItems: simpleList,
|
|
maxCount: 10
|
|
});
|
|
let alphabet = "abcdefghijklmnopqrstuvwxyz".split("");
|
|
recentItems2.addItems(alphabet);
|
|
assert.deepEqual(recentItems2.listItems(), 'qrstuvwxyz'.split(""));
|
|
recentItems2.addItem('a');
|
|
assert.deepEqual(recentItems2.listItems(), 'rstuvwxyza'.split(""));
|
|
recentItems2.addItem('r');
|
|
assert.deepEqual(recentItems2.listItems(), 'stuvwxyzar'.split(""));
|
|
});
|
|
});
|
|
});
|