gristlabs_grist-core/test/client/lib/ObservableSet.js
Jarosław Sadziński a52d56f613 (core) Moving client and common tests to core
Summary:
- Moved /test/client and /test/common to core.
- Moved two files (CircularArray and RecentItems) from app/common to core/app/common.
- Moved resetOrg test to gen-server.
- `testrun.sh` is now invoking common and client test from core.
- Added missing packages to core's package.json (and revealed underscore as it is used in the main app).
- Removed Coord.js as it is not used anywhere.

Test Plan: Existing tests

Reviewers: paulfitz

Reviewed By: paulfitz

Subscribers: paulfitz

Differential Revision: https://phab.getgrist.com/D3590
2022-08-23 19:20:10 +02:00

51 lines
1.3 KiB
JavaScript

/* global describe, it */
var assert = require('chai').assert;
var ko = require('knockout');
var clientUtil = require('../clientUtil');
var ObservableSet = require('app/client/lib/ObservableSet');
describe('ObservableSet', function() {
clientUtil.setTmpMochaGlobals();
it("should keep track of items", function() {
var set = ObservableSet.create();
assert.equal(set.count(), 0);
assert.deepEqual(set.all(), []);
var obs1 = ko.observable(true), val1 = { foo: 5 },
obs2 = ko.observable(false), val2 = { foo: 17 };
var sub1 = set.add(obs1, val1),
sub2 = set.add(obs2, val2);
assert.equal(set.count(), 1);
assert.deepEqual(set.all(), [val1]);
obs1(false);
assert.equal(set.count(), 0);
assert.deepEqual(set.all(), []);
obs2(true);
assert.equal(set.count(), 1);
assert.deepEqual(set.all(), [val2]);
obs1(true);
assert.equal(set.count(), 2);
assert.deepEqual(set.all(), [val1, val2]);
sub1.dispose();
assert.equal(set.count(), 1);
assert.deepEqual(set.all(), [val2]);
assert.equal(obs1.getSubscriptionsCount(), 0);
assert.equal(obs2.getSubscriptionsCount(), 1);
sub2.dispose();
assert.equal(set.count(), 0);
assert.deepEqual(set.all(), []);
assert.equal(obs1.getSubscriptionsCount(), 0);
assert.equal(obs2.getSubscriptionsCount(), 0);
});
});