Skip to content

Commit d97770b

Browse files
paula-stachoAnemy
andauthored
feat: show survey VSCODE-562 (#780)
--------- Co-authored-by: Rhys <[email protected]> Co-authored-by: Rhys Howell <[email protected]>
1 parent a29b4e2 commit d97770b

File tree

3 files changed

+176
-0
lines changed

3 files changed

+176
-0
lines changed

src/mdbExtensionController.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export default class MDBExtensionController implements vscode.Disposable {
150150

151151
this.registerCommands();
152152
this.showOverviewPageIfRecentlyInstalled();
153+
void this.showSurveyForEstablishedUsers();
153154
}
154155

155156
registerCommands = (): void => {
@@ -815,6 +816,44 @@ export default class MDBExtensionController implements vscode.Disposable {
815816
}
816817
}
817818

819+
async showSurveyForEstablishedUsers(): Promise<void> {
820+
const surveyId = '9viN9wcbsC3zvHyg7';
821+
822+
const hasBeenShownSurveyAlready =
823+
this._storageController.get(StorageVariables.GLOBAL_SURVEY_SHOWN) ===
824+
surveyId;
825+
826+
// Show the overview page when it hasn't been show to the
827+
// user yet, and they have saved connections
828+
// -> they haven't just started using this extension
829+
if (
830+
hasBeenShownSurveyAlready ||
831+
!this._connectionStorage.hasSavedConnections()
832+
) {
833+
return;
834+
}
835+
836+
const action = 'Share your thoughts';
837+
const text = 'How can we make the MongoDB extension better for you?';
838+
const link = 'https://forms.gle/9viN9wcbsC3zvHyg7';
839+
const result = await vscode.window.showInformationMessage(
840+
text,
841+
{},
842+
{
843+
title: action,
844+
}
845+
);
846+
if (result?.title === action) {
847+
void vscode.env.openExternal(vscode.Uri.parse(link));
848+
}
849+
850+
// whether action was taken or the prompt dismissed, we won't show this again
851+
void this._storageController.update(
852+
StorageVariables.GLOBAL_SURVEY_SHOWN,
853+
surveyId
854+
);
855+
}
856+
818857
async dispose(): Promise<void> {
819858
await this.deactivate();
820859
}

src/storage/storageController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { StoreConnectionInfo } from './connectionStorage';
66
export enum StorageVariables {
77
// Only exists on globalState.
88
GLOBAL_HAS_BEEN_SHOWN_INITIAL_VIEW = 'GLOBAL_HAS_BEEN_SHOWN_INITIAL_VIEW',
9+
GLOBAL_SURVEY_SHOWN = 'GLOBAL_SURVEY_SHOWN',
910
GLOBAL_SAVED_CONNECTIONS = 'GLOBAL_SAVED_CONNECTIONS',
1011
// Analytics user identify.
1112
GLOBAL_USER_ID = 'GLOBAL_USER_ID',
@@ -50,6 +51,7 @@ interface StorageVariableContents {
5051
[StorageVariables.GLOBAL_USER_ID]: string;
5152
[StorageVariables.GLOBAL_ANONYMOUS_ID]: string;
5253
[StorageVariables.GLOBAL_HAS_BEEN_SHOWN_INITIAL_VIEW]: boolean;
54+
[StorageVariables.GLOBAL_SURVEY_SHOWN]: string;
5355
[StorageVariables.GLOBAL_SAVED_CONNECTIONS]: ConnectionsFromStorage;
5456
[StorageVariables.WORKSPACE_SAVED_CONNECTIONS]: ConnectionsFromStorage;
5557
}

src/test/suite/mdbExtensionController.test.ts

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ suite('MDBExtensionController Test Suite', function () {
175175
let fakeActiveConnectionId: SinonSpy;
176176
let showErrorMessageStub: SinonStub;
177177
let fakeCreatePlaygroundFileWithContent: SinonSpy;
178+
let openExternalStub: SinonStub;
178179

179180
const sandbox = sinon.createSandbox();
180181

@@ -183,6 +184,7 @@ suite('MDBExtensionController Test Suite', function () {
183184
vscode.window,
184185
'showInformationMessage'
185186
);
187+
openExternalStub = sandbox.stub(vscode.env, 'openExternal');
186188
openTextDocumentStub = sandbox.stub(vscode.workspace, 'openTextDocument');
187189
fakeActiveConnectionId = sandbox.fake.returns('tasty_sandwhich');
188190
sandbox.replace(
@@ -1717,5 +1719,138 @@ suite('MDBExtensionController Test Suite', function () {
17171719
});
17181720
});
17191721
});
1722+
1723+
suite('survey prompt', function () {
1724+
suite(
1725+
"when a user hasn't been shown the survey prompt yet, and they have connections saved",
1726+
() => {
1727+
[
1728+
{
1729+
description: 'clicked the button',
1730+
value: { title: 'Share your thoughts' },
1731+
},
1732+
{ description: 'dismissed', value: undefined },
1733+
].forEach((reaction) => {
1734+
suite(`user ${reaction.description}`, () => {
1735+
let connectionsUpdateStub: SinonStub;
1736+
let uriParseStub: SinonStub;
1737+
beforeEach(async () => {
1738+
showInformationMessageStub.resolves(reaction.value);
1739+
openExternalStub.resolves(undefined);
1740+
sandbox.replace(
1741+
mdbTestExtension.testExtensionController._storageController,
1742+
'get',
1743+
sandbox.fake.returns(undefined)
1744+
);
1745+
sandbox.replace(
1746+
mdbTestExtension.testExtensionController._connectionStorage,
1747+
'hasSavedConnections',
1748+
sandbox.fake.returns(true)
1749+
);
1750+
connectionsUpdateStub = sandbox.stub(
1751+
mdbTestExtension.testExtensionController._storageController,
1752+
'update'
1753+
);
1754+
uriParseStub = sandbox.stub(vscode.Uri, 'parse');
1755+
connectionsUpdateStub.resolves(undefined);
1756+
await mdbTestExtension.testExtensionController.showSurveyForEstablishedUsers();
1757+
});
1758+
1759+
afterEach(() => {
1760+
sandbox.restore();
1761+
});
1762+
1763+
test('they are shown the survey prompt', () => {
1764+
assert(showInformationMessageStub.called);
1765+
assert.strictEqual(
1766+
showInformationMessageStub.firstCall.args[0],
1767+
'How can we make the MongoDB extension better for you?'
1768+
);
1769+
});
1770+
1771+
test('the link was open if and only if they click the button', () => {
1772+
if (reaction.value === undefined) {
1773+
assert(openExternalStub.notCalled);
1774+
}
1775+
if (reaction.value) {
1776+
assert(openExternalStub.called);
1777+
assert(uriParseStub.called);
1778+
assert.strictEqual(
1779+
uriParseStub.firstCall.args[0],
1780+
'https://forms.gle/9viN9wcbsC3zvHyg7'
1781+
);
1782+
}
1783+
});
1784+
1785+
test("it sets that they've been shown the survey", () => {
1786+
assert(connectionsUpdateStub.called);
1787+
assert.strictEqual(
1788+
connectionsUpdateStub.firstCall.args[0],
1789+
StorageVariables.GLOBAL_SURVEY_SHOWN
1790+
);
1791+
assert.strictEqual(
1792+
connectionsUpdateStub.firstCall.args[1],
1793+
'9viN9wcbsC3zvHyg7'
1794+
);
1795+
});
1796+
});
1797+
});
1798+
}
1799+
);
1800+
1801+
suite('when a user has been shown the survey prompt already', () => {
1802+
let connectionsUpdateStub: SinonStub;
1803+
beforeEach(() => {
1804+
sandbox.replace(
1805+
mdbTestExtension.testExtensionController._storageController,
1806+
'get',
1807+
sandbox.fake.returns('9viN9wcbsC3zvHyg7') // survey has been shown
1808+
);
1809+
sandbox.replace(
1810+
mdbTestExtension.testExtensionController._connectionStorage,
1811+
'hasSavedConnections',
1812+
sandbox.fake.returns(true)
1813+
);
1814+
connectionsUpdateStub = sandbox.stub(
1815+
mdbTestExtension.testExtensionController._storageController,
1816+
'update'
1817+
);
1818+
connectionsUpdateStub.resolves(undefined);
1819+
1820+
void mdbTestExtension.testExtensionController.showSurveyForEstablishedUsers();
1821+
});
1822+
1823+
test('they are not shown the survey prompt', () => {
1824+
assert(showInformationMessageStub.notCalled);
1825+
});
1826+
});
1827+
1828+
suite('when a has no connections saved', () => {
1829+
let connectionsUpdateStub: SinonStub;
1830+
beforeEach(() => {
1831+
sandbox.replace(
1832+
mdbTestExtension.testExtensionController._storageController,
1833+
'get',
1834+
sandbox.fake.returns(undefined)
1835+
);
1836+
sandbox.replace(
1837+
mdbTestExtension.testExtensionController._connectionStorage,
1838+
'hasSavedConnections',
1839+
sandbox.fake.returns(false) // no connections yet - this might be the first install
1840+
);
1841+
connectionsUpdateStub = sandbox.stub(
1842+
mdbTestExtension.testExtensionController._storageController,
1843+
'update'
1844+
);
1845+
connectionsUpdateStub.resolves(undefined);
1846+
1847+
void mdbTestExtension.testExtensionController.showSurveyForEstablishedUsers();
1848+
});
1849+
1850+
test('they are not shown the survey prompt', () => {
1851+
assert(showInformationMessageStub.notCalled);
1852+
});
1853+
});
1854+
});
17201855
});
17211856
});

0 commit comments

Comments
 (0)