UNPKG

4.62 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2021 Ericsson and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18const jsdom_1 = require("../test/jsdom");
19let disableJSDOM = (0, jsdom_1.enableJSDOM)();
20const assert = require("assert");
21const inversify_1 = require("inversify");
22const frontend_application_bindings_1 = require("../frontend-application-bindings");
23const preference_contribution_1 = require("./preference-contribution");
24const frontend_application_config_provider_1 = require("../frontend-application-config-provider");
25disableJSDOM();
26process.on('unhandledRejection', (reason, promise) => {
27 console.error(reason);
28 throw reason;
29});
30// const { expect } = require('chai');
31let testContainer;
32function createTestContainer() {
33 const result = new inversify_1.Container();
34 (0, frontend_application_bindings_1.bindPreferenceService)(result.bind.bind(result));
35 return result;
36}
37const EDITOR_FONT_SIZE_PROPERTIES = {
38 'editor.fontSize': {
39 type: 'number',
40 default: 14,
41 overridable: true
42 },
43};
44const EDITOR_INSERT_SPACES_PROPERTIES = {
45 'editor.insertSpaces': {
46 type: 'boolean',
47 default: true,
48 overridable: true
49 },
50};
51describe('Preference Schema Provider', () => {
52 let prefSchema;
53 before(() => {
54 disableJSDOM = (0, jsdom_1.enableJSDOM)();
55 frontend_application_config_provider_1.FrontendApplicationConfigProvider.set({
56 preferences: {
57 'editor.fontSize': 20,
58 '[typescript]': { 'editor.fontSize': 24 }
59 }
60 });
61 });
62 after(() => {
63 disableJSDOM();
64 });
65 beforeEach(async () => {
66 testContainer = createTestContainer();
67 prefSchema = testContainer.get(preference_contribution_1.PreferenceSchemaProvider);
68 });
69 it('Should load all preferences specified in the frontend config.', () => {
70 assert.strictEqual(prefSchema.get('editor.fontSize'), 20);
71 assert.strictEqual(prefSchema.get('[typescript].editor.fontSize'), 24);
72 });
73 it('Should favor the default specified in the package.json over a default registered by a schema', () => {
74 prefSchema.setSchema({
75 properties: {
76 ...EDITOR_FONT_SIZE_PROPERTIES
77 }
78 });
79 assert.strictEqual(prefSchema.get('editor.fontSize'), 20);
80 });
81 it('Should merge language-specific overrides from schemas and the package.json', () => {
82 prefSchema.setSchema({
83 properties: {
84 ...EDITOR_FONT_SIZE_PROPERTIES,
85 ...EDITOR_INSERT_SPACES_PROPERTIES,
86 '[typescript]': {
87 type: 'object',
88 default: {
89 'editor.insertSpaces': false
90 }
91 }
92 }
93 });
94 assert.strictEqual(prefSchema.get('editor.insertSpaces'), true);
95 assert.strictEqual(prefSchema.get('[typescript].editor.insertSpaces'), false);
96 assert.strictEqual(prefSchema.get('[typescript].editor.fontSize'), 24);
97 });
98 it('Should favor package.json specifications in the merge process', () => {
99 prefSchema.setSchema({
100 properties: {
101 ...EDITOR_FONT_SIZE_PROPERTIES,
102 ...EDITOR_INSERT_SPACES_PROPERTIES,
103 '[typescript]': {
104 type: 'object',
105 default: {
106 'editor.insertSpaces': false,
107 'editor.fontSize': 36,
108 }
109 }
110 }
111 });
112 assert.strictEqual(prefSchema.get('[typescript].editor.insertSpaces'), false);
113 assert.strictEqual(prefSchema.get('[typescript].editor.fontSize'), 24);
114 });
115});
116//# sourceMappingURL=preference-schema-provider.spec.js.map
\No newline at end of file