gristlabs_grist-core/test/client/components/WidgetFrame.ts
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

64 lines
2.4 KiB
TypeScript

import {assert} from 'chai';
import {MethodAccess} from 'app/client/components/WidgetFrame';
import {AccessLevel} from 'app/common/CustomWidget';
describe('WidgetFrame', function () {
it('should define access level per method', function () {
class SampleApi {
public none() {
return true;
}
public read_table() {
return true;
}
public full() {}
public notMentioned() {}
}
const checker = new MethodAccess<SampleApi>()
.require(AccessLevel.none, 'none')
.require(AccessLevel.read_table, 'read_table')
.require(AccessLevel.full, 'full');
const directTest = () => {
assert.isTrue(checker.check(AccessLevel.none, 'none'));
assert.isFalse(checker.check(AccessLevel.none, 'read_table'));
assert.isFalse(checker.check(AccessLevel.none, 'full'));
assert.isTrue(checker.check(AccessLevel.read_table, 'none'));
assert.isTrue(checker.check(AccessLevel.read_table, 'read_table'));
assert.isFalse(checker.check(AccessLevel.read_table, 'full'));
assert.isTrue(checker.check(AccessLevel.full, 'none'));
assert.isTrue(checker.check(AccessLevel.full, 'read_table'));
assert.isTrue(checker.check(AccessLevel.full, 'full'));
};
directTest();
// Check that for any other method, access is denied.
assert.isFalse(checker.check(AccessLevel.none, 'notMentioned'));
assert.isFalse(checker.check(AccessLevel.read_table, 'notMentioned'));
// Even though access is full, the method was not mentioned, so it should be denied.
assert.isFalse(checker.check(AccessLevel.full, 'notMentioned'));
// Now add a default rule.
checker.require(AccessLevel.none, '*');
assert.isTrue(checker.check(AccessLevel.none, 'notMentioned'));
assert.isTrue(checker.check(AccessLevel.read_table, 'notMentioned'));
assert.isTrue(checker.check(AccessLevel.full, 'notMentioned'));
directTest();
checker.require(AccessLevel.read_table, '*');
assert.isFalse(checker.check(AccessLevel.none, 'notMentioned'));
assert.isTrue(checker.check(AccessLevel.read_table, 'notMentioned'));
assert.isTrue(checker.check(AccessLevel.full, 'notMentioned'));
directTest();
checker.require(AccessLevel.full, '*');
assert.isFalse(checker.check(AccessLevel.none, 'notMentioned'));
assert.isFalse(checker.check(AccessLevel.read_table, 'notMentioned'));
assert.isTrue(checker.check(AccessLevel.full, 'notMentioned'));
directTest();
});
});