Skip to content

Commit 1c49830

Browse files
authored
VSCODE-98: Add webview tests and schema field type tooltip VSCODE-176 (#179)
1 parent ebf07fa commit 1c49830

File tree

61 files changed

+11450
-5621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+11450
-5621
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ node_modules
55
*.vsix
66
.DS_Store
77
test-results.xml
8+
test-webview-results.xml
89
constants.json
910
.env

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ steps:
5757
condition: succeededOrFailed()
5858
inputs:
5959
testRunner: JUnit
60-
testResultsFiles: 'test-results.xml'
60+
testResultsFiles: 'test*-results.xml'
6161
failTaskOnFailedTests: true
6262

6363
- bash: |

jest.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
roots: ['<rootDir>/src/test/suite/views/webview-app'],
3+
transform: {
4+
'^.+\\.tsx?$': 'ts-jest',
5+
'.+\\.(less)$': 'jest-transform-stub'
6+
},
7+
reporters: [
8+
'default',
9+
['jest-junit', {
10+
outputName: 'test-webview-results.xml'
11+
}]
12+
],
13+
testRegex: '(/test/suite/views/webview-app/.*|(\\.|/)(test|spec))\\.tsx?$',
14+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
15+
setupFiles: ['<rootDir>/src/test/suite/views/webview-app/jest-setup.js']
16+
};

package-lock.json

Lines changed: 10900 additions & 5230 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
"watch:extension": "npm run compile:extension -- -watch",
4949
"watch:extension-bundles": "webpack --mode development --info-verbosity verbose --watch",
5050
"pretest": "npm run compile && cross-env MONGODB_VERSION=4.2.3 mongodb-runner start --port=27018",
51-
"test": "cross-env NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js",
51+
"test": "npm run test-webview && npm run test-extension",
52+
"test-extension": "cross-env NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js",
53+
"test-webview": "jest",
5254
"posttest": "mongodb-runner stop --port=27018",
5355
"vscode:prepublish": "npm run clean && npm run compile:keyfile && npm run compile:resources && webpack --mode production",
5456
"check": "mongodb-js-precommit './src/**/*{.ts}'",
@@ -818,7 +820,7 @@
818820
"@fortawesome/fontawesome-svg-core": "^1.2.28",
819821
"@fortawesome/free-solid-svg-icons": "^5.13.0",
820822
"@fortawesome/react-fontawesome": "^0.1.9",
821-
"@leafygreen-ui/toggle": "^3.0.1",
823+
"@leafygreen-ui/toggle": "3.0.1",
822824
"@mongosh/browser-runtime-electron": "^0.4.2",
823825
"@mongosh/service-provider-server": "^0.4.2",
824826
"@mongosh/shell-api": "^0.4.2",
@@ -852,9 +854,10 @@
852854
"@types/chai-json-schema": "^1.4.5",
853855
"@types/debug": "^4.1.5",
854856
"@types/glob": "^7.1.1",
857+
"@types/jest": "^26.0.14",
855858
"@types/keytar": "4.4.2",
856-
"@types/mocha": "^7.0.1",
857-
"@types/node": "^14.11.2",
859+
"@types/mocha": "^8.0.3",
860+
"@types/node": "^14.11.5",
858861
"@types/react": "^16.9.25",
859862
"@types/react-dom": "^16.9.5",
860863
"@types/sinon": "^9.0.1",
@@ -869,15 +872,20 @@
869872
"chai-json-schema": "^1.5.1",
870873
"cross-env": "^7.0.2",
871874
"css-loader": "^3.4.2",
875+
"enzyme": "^3.11.0",
876+
"enzyme-adapter-react-16": "^1.15.5",
872877
"eslint": "^6.8.0",
873878
"eslint-config-mongodb-js": "^5.0.3",
874879
"eslint-plugin-react": "^7.19.0",
875880
"glob": "^7.1.6",
881+
"jest": "^26.5.2",
882+
"jest-junit": "^12.0.0",
883+
"jest-transform-stub": "^2.0.0",
876884
"less": "^3.11.1",
877885
"less-loader": "^5.0.0",
878886
"meow": "^6.0.1",
879887
"mkdirp": "^1.0.4",
880-
"mocha": "^7.0.1",
888+
"mocha": "^8.1.3",
881889
"mocha-junit-reporter": "^1.23.3",
882890
"mocha-multi": "^1.1.3",
883891
"mongodb-ace-autocompleter": "^0.4.11",
@@ -887,12 +895,14 @@
887895
"npm-run-all": "^4.1.5",
888896
"ora": "^4.0.3",
889897
"postcss-loader": "^3.0.0",
898+
"react-test-renderer": "^16.13.1",
890899
"sinon": "^9.0.0",
891900
"sinon-chai": "^3.5.0",
892901
"style-loader": "^1.1.3",
902+
"ts-jest": "^26.4.1",
893903
"ts-loader": "^6.2.2",
894904
"ts-node": "^8.6.2",
895-
"typescript": "^3.9.7",
905+
"typescript": "^4.0.3",
896906
"vsce": "^1.81.1",
897907
"vscode-test": "^1.3.0",
898908
"webpack": "^4.42.0",

src/connectionController.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,28 @@ export default class ConnectionController {
708708
return this._activeConnectionModel;
709709
}
710710

711+
public getConnectionStatusStringForConnection(connectionId: string): string {
712+
if (
713+
this.getActiveConnectionId() === connectionId
714+
) {
715+
if (this.isDisconnecting()) {
716+
return 'disconnecting...';
717+
}
718+
719+
return 'connected';
720+
}
721+
722+
if (
723+
this.isConnecting() &&
724+
this.getConnectingConnectionId() ===
725+
connectionId
726+
) {
727+
return 'connecting...';
728+
}
729+
730+
return '';
731+
}
732+
711733
// Exposed for testing.
712734
public clearAllConnections(): void {
713735
this._connections = {};

src/explorer/collectionTreeItem.ts

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ import { getImagesPath } from '../extensionConstants';
1313

1414
const log = createLogger('tree view collection folder');
1515

16+
function getIconPath(
17+
type: CollectionTypes,
18+
isExpanded: boolean
19+
): { light: string; dark: string } {
20+
const LIGHT = path.join(getImagesPath(), 'light');
21+
const DARK = path.join(getImagesPath(), 'dark');
22+
23+
if (type === CollectionTypes.collection) {
24+
if (isExpanded) {
25+
return {
26+
light: path.join(LIGHT, 'collection-folder-open.svg'),
27+
dark: path.join(DARK, 'collection-folder-open.svg')
28+
};
29+
}
30+
return {
31+
light: path.join(LIGHT, 'collection-folder-closed.svg'),
32+
dark: path.join(DARK, 'collection-folder-closed.svg')
33+
};
34+
}
35+
return {
36+
light: path.join(LIGHT, 'view-folder.svg'),
37+
dark: path.join(DARK, 'view-folder.svg')
38+
};
39+
}
40+
1641
type CollectionModelType = {
1742
name: string;
1843
type: CollectionTypes;
@@ -117,12 +142,11 @@ export default class CollectionTreeItem extends vscode.TreeItem
117142
false, // Cache is not up to date.
118143
[] // Empty cache.
119144
);
120-
}
121145

122-
get tooltip(): string {
123-
return this._type === CollectionTypes.view
146+
this.tooltip = collection.type === CollectionTypes.view
124147
? 'Read only view'
125-
: this.collectionName;
148+
: collection.name;
149+
this.iconPath = getIconPath(collection.type, isExpanded);
126150
}
127151

128152
getTreeItem(element: CollectionTreeItem): CollectionTreeItem {
@@ -362,29 +386,4 @@ export default class CollectionTreeItem extends vscode.TreeItem
362386
);
363387
});
364388
}
365-
366-
get iconPath():
367-
| string
368-
| vscode.Uri
369-
| { light: string | vscode.Uri; dark: string | vscode.Uri } {
370-
const LIGHT = path.join(getImagesPath(), 'light');
371-
const DARK = path.join(getImagesPath(), 'dark');
372-
373-
if (this._type === CollectionTypes.collection) {
374-
if (this.isExpanded) {
375-
return {
376-
light: path.join(LIGHT, 'collection-folder-open.svg'),
377-
dark: path.join(DARK, 'collection-folder-open.svg')
378-
};
379-
}
380-
return {
381-
light: path.join(LIGHT, 'collection-folder-closed.svg'),
382-
dark: path.join(DARK, 'collection-folder-closed.svg')
383-
};
384-
}
385-
return {
386-
light: path.join(LIGHT, 'view-folder.svg'),
387-
dark: path.join(DARK, 'view-folder.svg')
388-
};
389-
}
390389
}

src/explorer/connectionTreeItem.ts

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ enum ConnectionItemContextValues {
1414
}
1515
export { ConnectionItemContextValues };
1616

17+
function getIconPath(isActiveConnection: boolean): { light: string; dark: string } {
18+
const LIGHT = path.join(getImagesPath(), 'light');
19+
const DARK = path.join(getImagesPath(), 'dark');
20+
21+
return isActiveConnection ? {
22+
light: path.join(LIGHT, 'connection-active.svg'),
23+
dark: path.join(DARK, 'connection-active.svg')
24+
} : {
25+
light: path.join(LIGHT, 'connection-inactive.svg'),
26+
dark: path.join(DARK, 'connection-inactive.svg')
27+
};
28+
}
29+
1730
export default class ConnectionTreeItem extends vscode.TreeItem
1831
implements TreeItemParent, vscode.TreeDataProvider<ConnectionTreeItem> {
1932
contextValue = ConnectionItemContextValues.disconnected;
@@ -56,32 +69,14 @@ export default class ConnectionTreeItem extends vscode.TreeItem
5669
// Create a unique id to ensure the tree updates the expanded property.
5770
// (Without an id it treats this tree item like a previous tree item with the same label).
5871
this.id = `${connectionId}-${Date.now()}`;
59-
}
6072

61-
get tooltip(): string {
62-
return this._connectionController.getSavedConnectionName(this.connectionId);
63-
}
64-
65-
get description(): string {
66-
if (
67-
this._connectionController.getActiveConnectionId() === this.connectionId
68-
) {
69-
if (this._connectionController.isDisconnecting()) {
70-
return 'disconnecting...';
71-
}
72-
73-
return 'connected';
74-
}
75-
76-
if (
77-
this._connectionController.isConnecting() &&
78-
this._connectionController.getConnectingConnectionId() ===
79-
this.connectionId
80-
) {
81-
return 'connecting...';
82-
}
83-
84-
return '';
73+
this.tooltip = connectionController.getSavedConnectionName(this.connectionId);
74+
this.description = connectionController.getConnectionStatusStringForConnection(
75+
this.connectionId
76+
);
77+
this.iconPath = getIconPath(
78+
connectionController.getActiveConnectionId() === this.connectionId
79+
);
8580
}
8681

8782
getTreeItem(element: ConnectionTreeItem): ConnectionTreeItem {
@@ -174,27 +169,6 @@ export default class ConnectionTreeItem extends vscode.TreeItem
174169
return Object.values(this._childrenCache);
175170
}
176171

177-
get iconPath():
178-
| string
179-
| vscode.Uri
180-
| { light: string | vscode.Uri; dark: string | vscode.Uri } {
181-
const LIGHT = path.join(getImagesPath(), 'light');
182-
const DARK = path.join(getImagesPath(), 'dark');
183-
184-
if (
185-
this._connectionController.getActiveConnectionId() === this.connectionId
186-
) {
187-
return {
188-
light: path.join(LIGHT, 'connection-active.svg'),
189-
dark: path.join(DARK, 'connection-active.svg')
190-
};
191-
}
192-
return {
193-
light: path.join(LIGHT, 'connection-inactive.svg'),
194-
dark: path.join(DARK, 'connection-inactive.svg')
195-
};
196-
}
197-
198172
onDidCollapse(): void {
199173
this.isExpanded = false;
200174
this.cacheIsUpToDate = false;

src/explorer/databaseTreeItem.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import CollectionTreeItem from './collectionTreeItem';
88
import TreeItemParent from './treeItemParentInterface';
99
import { getImagesPath } from '../extensionConstants';
1010

11+
function getIconPath(): { light: string; dark: string } {
12+
const LIGHT = path.join(getImagesPath(), 'light');
13+
const DARK = path.join(getImagesPath(), 'dark');
14+
15+
return {
16+
light: path.join(LIGHT, 'database.svg'),
17+
dark: path.join(DARK, 'database.svg')
18+
};
19+
}
20+
1121
export default class DatabaseTreeItem extends vscode.TreeItem
1222
implements TreeItemParent, vscode.TreeDataProvider<DatabaseTreeItem> {
1323
contextValue = 'databaseTreeItem';
@@ -40,10 +50,9 @@ export default class DatabaseTreeItem extends vscode.TreeItem
4050
this.isExpanded = isExpanded;
4151
this.cacheIsUpToDate = cacheIsUpToDate;
4252
this._childrenCache = existingChildrenCache;
43-
}
4453

45-
get tooltip(): string {
46-
return this.databaseName;
54+
this.iconPath = getIconPath();
55+
this.tooltip = this.databaseName;
4756
}
4857

4958
getTreeItem(element: DatabaseTreeItem): DatabaseTreeItem {
@@ -140,19 +149,6 @@ export default class DatabaseTreeItem extends vscode.TreeItem
140149
return Object.values(this._childrenCache);
141150
}
142151

143-
get iconPath():
144-
| string
145-
| vscode.Uri
146-
| { light: string | vscode.Uri; dark: string | vscode.Uri } {
147-
const LIGHT = path.join(getImagesPath(), 'light');
148-
const DARK = path.join(getImagesPath(), 'dark');
149-
150-
return {
151-
light: path.join(LIGHT, 'database.svg'),
152-
dark: path.join(DARK, 'database.svg')
153-
};
154-
}
155-
156152
onDidCollapse(): void {
157153
this.isExpanded = false;
158154
this.cacheIsUpToDate = false;

0 commit comments

Comments
 (0)