Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/test/suite/views/webviewController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ suite('Connect Form View Test Suite', () => {
const stubOnDidRecieveMessage = sinon.stub();
const fakeWebview = {
html: '',
onDidReceiveMessage: stubOnDidRecieveMessage
onDidReceiveMessage: stubOnDidRecieveMessage,
asWebviewUri: sinon.fake.returns('')
};
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
webview: fakeWebview
Expand Down Expand Up @@ -74,11 +75,16 @@ suite('Connect Form View Test Suite', () => {
});
}

const fakeWebview: any = {
asWebviewUri: (jsUri) => {
return jsUri;
}
};

const extensionPath = mdbTestExtension.testExtensionContext.extensionPath;
const appUri = getReactAppUri(extensionPath);
const appUri = getReactAppUri(extensionPath, fakeWebview);
const htmlString = getConnectWebviewContent(appUri);

assert(htmlString.includes('vscode-resource:/'));
assert(htmlString.includes('dist/webviewApp.js'));

const webviewAppFileName = (): string => 'dist/webviewApp.js';
Expand Down Expand Up @@ -121,7 +127,8 @@ suite('Connect Form View Test Suite', () => {
onDidReceiveMessage: (callback): void => {
messageRecieved = callback;
messageRecievedSet = true;
}
},
asWebviewUri: sinon.fake.returns('')
};
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
webview: fakeWebview
Expand Down Expand Up @@ -193,7 +200,8 @@ suite('Connect Form View Test Suite', () => {
onDidReceiveMessage: (callback): void => {
messageRecieved = callback;
messageRecievedSet = true;
}
},
asWebviewUri: sinon.fake.returns('')
};
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
webview: fakeWebview
Expand Down Expand Up @@ -259,7 +267,8 @@ suite('Connect Form View Test Suite', () => {
},
onDidReceiveMessage: (callback): void => {
messageRecieved = callback;
}
},
asWebviewUri: sinon.fake.returns('')
};
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
webview: fakeWebview
Expand Down Expand Up @@ -318,7 +327,8 @@ suite('Connect Form View Test Suite', () => {
},
onDidReceiveMessage: (callback): void => {
messageRecieved = callback;
}
},
asWebviewUri: sinon.fake.returns('')
};
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
webview: fakeWebview
Expand Down Expand Up @@ -388,7 +398,8 @@ suite('Connect Form View Test Suite', () => {
},
onDidReceiveMessage: (callback): void => {
messageRecieved = callback;
}
},
asWebviewUri: sinon.fake.returns('')
};

const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
Expand Down Expand Up @@ -442,7 +453,8 @@ suite('Connect Form View Test Suite', () => {
},
onDidReceiveMessage: (callback): void => {
messageRecieved = callback;
}
},
asWebviewUri: sinon.fake.returns('')
};
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
webview: fakeWebview
Expand Down Expand Up @@ -494,7 +506,8 @@ suite('Connect Form View Test Suite', () => {
html: '',
onDidReceiveMessage: (callback): void => {
messageRecieved = callback;
}
},
asWebviewUri: sinon.fake.returns('')
};
const fakeVSCodeExecuteCommand = sinon.fake.resolves(false);

Expand Down
9 changes: 5 additions & 4 deletions src/views/webviewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ export const getConnectWebviewContent = (jsAppFileUrl: vscode.Uri): string => {
</html>`;
};

export const getReactAppUri = (extensionPath: string): vscode.Uri => {
const jsAppFilePath = vscode.Uri.file(
export const getReactAppUri = (extensionPath: string, webview: vscode.Webview): vscode.Uri => {
const localFilePathUri = vscode.Uri.file(
path.join(extensionPath, 'dist', 'webviewApp.js')
);
return jsAppFilePath.with({ scheme: 'vscode-resource' });
const jsAppFileWebviewUri = webview.asWebviewUri(localFilePathUri);
return jsAppFileWebviewUri;
};

export default class WebviewController {
Expand Down Expand Up @@ -177,7 +178,7 @@ export default class WebviewController {
path.join(extensionPath, 'images', 'leaf.svg')
);

const reactAppUri = getReactAppUri(extensionPath);
const reactAppUri = getReactAppUri(extensionPath, panel.webview);
panel.webview.html = getConnectWebviewContent(reactAppUri);

// Handle messages from the webview.
Expand Down