@@ -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