@theia/api-tests 1.23.0-next.3 → 1.23.0-next.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@theia/api-tests",
3
- "version": "1.23.0-next.3+0ad6d10e354",
3
+ "version": "1.23.0-next.35+f7dda0890ee",
4
4
  "description": "Theia API tests",
5
5
  "dependencies": {
6
- "@theia/core": "1.23.0-next.3+0ad6d10e354"
6
+ "@theia/core": "1.23.0-next.35+f7dda0890ee"
7
7
  },
8
8
  "license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0",
9
9
  "repository": {
@@ -20,5 +20,5 @@
20
20
  "publishConfig": {
21
21
  "access": "public"
22
22
  },
23
- "gitHead": "0ad6d10e354af57b43fa7ac677c43c8a4948e494"
23
+ "gitHead": "f7dda0890eeaaa9da9246b615c6a2564bd651a26"
24
24
  }
@@ -31,6 +31,9 @@ describe('file-search', function () {
31
31
 
32
32
  describe('#compareItems', () => {
33
33
 
34
+ /** @type import ('@theia/file-search/lib/browser/quick-file-open').QuickFileOpenService['compareItems']*/
35
+ const sortByCompareItems = (a, b) => quickFileOpenService['compareItems'](a, b);
36
+
34
37
  it('should compare two quick-open-items by `label`', () => {
35
38
 
36
39
  /** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
@@ -38,8 +41,8 @@ describe('file-search', function () {
38
41
  /** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
39
42
  const b = { label: 'b', uri: new Uri.default('a') };
40
43
 
41
- assert.equal(quickFileOpenService['compareItems'](a, b), 1, 'a should be before b');
42
- assert.equal(quickFileOpenService['compareItems'](b, a), -1, 'a should be before b');
44
+ assert.deepEqual([a, b].sort(sortByCompareItems), [a, b], 'a should be before b');
45
+ assert.deepEqual([b, a].sort(sortByCompareItems), [a, b], 'a should be before b');
43
46
  assert.equal(quickFileOpenService['compareItems'](a, a), 0, 'items should be equal');
44
47
  });
45
48
 
@@ -49,10 +52,23 @@ describe('file-search', function () {
49
52
  const a = { label: 'a', uri: new Uri.default('a') };
50
53
  /** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
51
54
  const b = { label: 'a', uri: new Uri.default('b') };
55
+ assert.deepEqual([a, b].sort(sortByCompareItems), [a, b], 'a should be before b');
56
+ assert.deepEqual([b, a].sort(sortByCompareItems), [a, b], 'a should be before b');
57
+ assert.equal(sortByCompareItems(a, a), 0, 'items should be equal');
58
+ });
52
59
 
53
- assert.equal(quickFileOpenService['compareItems'](a, b), 1, 'a should be before b');
54
- assert.equal(quickFileOpenService['compareItems'](b, a), -1, 'a should be before b');
55
- assert.equal(quickFileOpenService['compareItems'](a, a), 0, 'items should be equal');
60
+ it('should not place very good matches above exact matches', () => {
61
+ const exactMatch = 'aa_bb_cc_dd.file';
62
+ const veryGoodMatch = 'aa_bb_cc_ed_fd.file';
63
+ quickFileOpenService['filterAndRange'] = { filter: exactMatch };
64
+ /** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
65
+ const a = { label: exactMatch, uri: new Uri.default(exactMatch) };
66
+ /** @type import ('@theia/file-search/lib/browser/quick-file-open').FileQuickPickItem*/
67
+ const b = { label: veryGoodMatch, uri: new Uri.default(veryGoodMatch) };
68
+ assert.deepEqual([a, b].sort(sortByCompareItems), [a, b], 'a should be before b');
69
+ assert.deepEqual([b, a].sort(sortByCompareItems), [a, b], 'a should be before b');
70
+ assert.equal(sortByCompareItems(a, a), 0, 'items should be equal');
71
+ quickFileOpenService['filterAndRange'] = quickFileOpenService['filterAndRangeDefault'];
56
72
  });
57
73
 
58
74
  });
@@ -35,8 +35,6 @@ describe('Launch Preferences', function () {
35
35
  const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service');
36
36
  const { FileService } = require('@theia/filesystem/lib/browser/file-service');
37
37
  const { FileResourceResolver } = require('@theia/filesystem/lib/browser/file-resource');
38
- const { MonacoTextModelService } = require('@theia/monaco/lib/browser/monaco-text-model-service');
39
- const { MonacoWorkspace } = require('@theia/monaco/lib/browser/monaco-workspace');
40
38
  const { AbstractResourcePreferenceProvider } = require('@theia/preferences/lib/browser/abstract-resource-preference-provider');
41
39
  const { waitForEvent } = require('@theia/core/lib/common/promise-util');
42
40
 
@@ -51,8 +49,6 @@ describe('Launch Preferences', function () {
51
49
  const folderPreferences = container.getNamed(PreferenceProvider, PreferenceScope.Folder);
52
50
  const workspaceService = container.get(WorkspaceService);
53
51
  const fileService = container.get(FileService);
54
- const textModelService = container.get(MonacoTextModelService);
55
- const workspace = container.get(MonacoWorkspace);
56
52
  const fileResourceResolver = container.get(FileResourceResolver);
57
53
 
58
54
  const defaultLaunch = {
@@ -0,0 +1,160 @@
1
+ /********************************************************************************
2
+ * Copyright (C) 2022 Ericsson and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+
17
+ // @ts-check
18
+
19
+ describe('Preferences', function () {
20
+ this.timeout(5_000);
21
+ const { assert } = chai;
22
+ const { PreferenceProvider } = require('@theia/core/lib/browser/preferences/preference-provider');
23
+ const { PreferenceService, PreferenceScope } = require('@theia/core/lib/browser/preferences/preference-service');
24
+ const { FileService } = require('@theia/filesystem/lib/browser/file-service');
25
+ const { PreferenceLanguageOverrideService } = require('@theia/core/lib/browser/preferences/preference-language-override-service');
26
+ const { MonacoTextModelService } = require('@theia/monaco/lib/browser/monaco-text-model-service');
27
+ const { container } = window.theia;
28
+ /** @type {import ('@theia/core/lib/browser/preferences/preference-service').PreferenceService} */
29
+ const preferenceService = container.get(PreferenceService);
30
+ const overrideService = container.get(PreferenceLanguageOverrideService);
31
+ const fileService = container.get(FileService);
32
+ /** @type {import ('@theia/core/lib/common/uri').default} */
33
+ const uri = preferenceService.getConfigUri(PreferenceScope.Workspace);
34
+ /** @type {import('@theia/preferences/lib/browser/folders-preferences-provider').FoldersPreferencesProvider} */
35
+ const folderPreferences = container.getNamed(PreferenceProvider, PreferenceScope.Folder);
36
+ const modelService = container.get(MonacoTextModelService);
37
+
38
+ const swift = 'swift'; // Probably not in our preference files...
39
+ const tabSize = 'editor.tabSize';
40
+ const fontSize = 'editor.fontSize';
41
+ const override = overrideService.markLanguageOverride(swift);
42
+ const overriddenTabSize = overrideService.overridePreferenceName({ overrideIdentifier: swift, preferenceName: tabSize });
43
+ const overriddenFontSize = overrideService.overridePreferenceName({ overrideIdentifier: swift, preferenceName: fontSize });
44
+ /**
45
+ * @returns {Promise<Record<string, any>>}
46
+ */
47
+ async function getPreferences() {
48
+ try {
49
+ const content = (await fileService.read(uri)).value;
50
+ return JSON.parse(content);
51
+ } catch (e) {
52
+ return {};
53
+ }
54
+ }
55
+
56
+ /**
57
+ * @param {string} key
58
+ * @param {unknown} value
59
+ */
60
+ async function setPreference(key, value) {
61
+ return preferenceService.set(key, value, PreferenceScope.Workspace);
62
+ }
63
+
64
+ async function deleteAllValues() {
65
+ const reference = await modelService.createModelReference(uri);
66
+ if (reference.object.dirty) {
67
+ await reference.object.revert();
68
+ }
69
+ /** @type {import ('@theia/preferences/lib/browser/folder-preference-provider').FolderPreferenceProvider} */
70
+ const provider = Array.from(folderPreferences['providers'].values()).find(candidate => candidate.getConfigUri().isEqual(uri));
71
+ assert.isDefined(provider);
72
+ await provider['doSetPreference']('', [], undefined);
73
+ reference.dispose();
74
+ }
75
+
76
+ let fileExistsBeforehand = false;
77
+ let contentBeforehand = '';
78
+
79
+ before(async function () {
80
+ assert.isDefined(uri, 'The workspace config URI should be defined!');
81
+ fileExistsBeforehand = await fileService.exists(uri);
82
+ contentBeforehand = await fileService.read(uri).then(({ value }) => value).catch(() => '');
83
+ await deleteAllValues();
84
+ });
85
+
86
+ after(async function () {
87
+ if (!fileExistsBeforehand) {
88
+ await fileService.delete(uri, { fromUserGesture: false }).catch(() => { });
89
+ } else {
90
+ await fileService.write(uri, contentBeforehand);
91
+ }
92
+ });
93
+
94
+ beforeEach(async function () {
95
+ const prefs = await getPreferences();
96
+ for (const key of [tabSize, fontSize, override, overriddenTabSize, overriddenFontSize]) {
97
+ shouldBeUndefined(prefs[key], key);
98
+ }
99
+ });
100
+
101
+ afterEach(async function () {
102
+ await deleteAllValues();
103
+ });
104
+
105
+ /**
106
+ * @param {unknown} value
107
+ * @param {string} key
108
+ */
109
+ function shouldBeUndefined(value, key) {
110
+ assert.isUndefined(value, `There should be no ${key} object or value in the preferences.`);
111
+ }
112
+
113
+ /**
114
+ * @returns {Promise<{newTabSize: number, newFontSize: number, startingTabSize: number, startingFontSize: number}>}
115
+ */
116
+ async function setUpOverride() {
117
+ const startingTabSize = preferenceService.get(tabSize);
118
+ const startingFontSize = preferenceService.get(fontSize);
119
+ assert.equal(preferenceService.get(overriddenTabSize), startingTabSize, 'The overridden value should equal the default.');
120
+ assert.equal(preferenceService.get(overriddenFontSize), startingFontSize, 'The overridden value should equal the default.');
121
+ const newTabSize = startingTabSize + 2;
122
+ const newFontSize = startingFontSize + 2;
123
+ await Promise.all([
124
+ setPreference(overriddenTabSize, newTabSize),
125
+ setPreference(overriddenFontSize, newFontSize),
126
+ ]);
127
+ assert.equal(preferenceService.get(overriddenTabSize), newTabSize, 'After setting, the new value should be active for the override.');
128
+ assert.equal(preferenceService.get(overriddenFontSize), newFontSize, 'After setting, the new value should be active for the override.');
129
+ return { newTabSize, newFontSize, startingTabSize, startingFontSize };
130
+ }
131
+
132
+ it('Sets language overrides as objects', async function () {
133
+ const { newTabSize, newFontSize } = await setUpOverride();
134
+ const prefs = await getPreferences();
135
+ assert.isObject(prefs[override], 'The override should be a key in the preference object.');
136
+ assert.equal(prefs[override][tabSize], newTabSize, 'editor.tabSize should be a key in the override object and have the correct value.');
137
+ assert.equal(prefs[override][fontSize], newFontSize, 'editor.fontSize should be a key in the override object and should have the correct value.');
138
+ shouldBeUndefined(prefs[overriddenTabSize], overriddenTabSize);
139
+ shouldBeUndefined(prefs[overriddenFontSize], overriddenFontSize);
140
+ });
141
+
142
+ it('Allows deletion of individual keys in the override object.', async function () {
143
+ const { startingTabSize } = await setUpOverride();
144
+ await setPreference(overriddenTabSize, undefined);
145
+ assert.equal(preferenceService.get(overriddenTabSize), startingTabSize);
146
+ const prefs = await getPreferences();
147
+ shouldBeUndefined(prefs[override][tabSize], tabSize);
148
+ shouldBeUndefined(prefs[overriddenFontSize], overriddenFontSize);
149
+ shouldBeUndefined(prefs[overriddenTabSize], overriddenTabSize);
150
+ });
151
+
152
+ it('Allows deletion of the whole override object', async function () {
153
+ const { startingFontSize, startingTabSize } = await setUpOverride();
154
+ await setPreference(override, undefined);
155
+ assert.equal(preferenceService.get(overriddenTabSize), startingTabSize, 'The overridden value should revert to the default.');
156
+ assert.equal(preferenceService.get(overriddenFontSize), startingFontSize, 'The overridden value should revert to the default.');
157
+ const prefs = await getPreferences();
158
+ shouldBeUndefined(prefs[override], override);
159
+ });
160
+ });
@@ -751,7 +751,7 @@ SPAN {
751
751
  const editor = await openEditor(serverUri);
752
752
  const currentChar = () => editor.getControl().getModel().getLineContent(lineNumber).charAt(column - 1);
753
753
 
754
- // container.load(modul)
754
+ // container.load(module)
755
755
  editor.getControl().getModel().applyEdits([{
756
756
  range: {
757
757
  startLineNumber: lineNumber,