mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add query history persistence (#20700)
* initial * Fix and revert secret storage changes * persist to file * Add debounce and write on dispose * Fix run * No ext dependencies and show warning message * Remove test stuff * comments * Fix tests and console logs
This commit is contained in:
@@ -19,7 +19,7 @@ describe('QueryHistoryProvider', () => {
|
||||
let textDocumentSandbox: sinon.SinonSandbox;
|
||||
const testUri = vscode.Uri.parse('untitled://query1');
|
||||
|
||||
beforeEach(function (): void {
|
||||
beforeEach(async function (): Promise<void> {
|
||||
sinon.stub(azdata.queryeditor, 'registerQueryEventListener').callsFake((listener: azdata.queryeditor.QueryEventListener) => {
|
||||
testListener = listener;
|
||||
return { dispose: (): void => { } };
|
||||
@@ -28,7 +28,11 @@ describe('QueryHistoryProvider', () => {
|
||||
textDocumentSandbox.replaceGetter(vscode.workspace, 'textDocuments', () => [azdataTest.mocks.vscode.createTextDocumentMock(testUri).object]);
|
||||
const getConnectionStub = sinon.stub(azdata.connection, 'getConnection');
|
||||
getConnectionStub.resolves(<any>{});
|
||||
testProvider = new QueryHistoryProvider();
|
||||
// const getConfigurationStub = sinon.stub(vscode.workspace, 'getConfiguration')
|
||||
const contextMock = azdataTest.mocks.vscode.createExtensionContextMock();
|
||||
testProvider = new QueryHistoryProvider(contextMock.object);
|
||||
// Disable persistence during tests
|
||||
await testProvider.setPersistenceEnabled(false);
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
@@ -40,8 +44,8 @@ describe('QueryHistoryProvider', () => {
|
||||
should(children).length(0);
|
||||
});
|
||||
|
||||
it('Clearing empty list does not throw', function () {
|
||||
testProvider.clearAll();
|
||||
it('Clearing empty list does not throw', async function () {
|
||||
await testProvider.clearAll();
|
||||
const children = testProvider.getChildren();
|
||||
should(children).length(0);
|
||||
});
|
||||
@@ -138,7 +142,7 @@ describe('QueryHistoryProvider', () => {
|
||||
});
|
||||
|
||||
it('delete item when no items doesn\'t throw', async function () {
|
||||
const testItem: QueryHistoryItem = { queryText: 'SELECT 1', connectionProfile: azdataTest.stubs.connectionProfile.createConnectionProfile(), timestamp: new Date(), isSuccess: true };
|
||||
const testItem: QueryHistoryItem = { queryText: 'SELECT 1', connectionProfile: azdataTest.stubs.azdata.createConnectionProfile(), timestamp: new Date().toLocaleString(), isSuccess: true };
|
||||
await waitForItemRefresh(() => testProvider.deleteItem(testItem));
|
||||
const children = testProvider.getChildren();
|
||||
should(children).length(0, 'Should have no children after deleting item');
|
||||
@@ -149,7 +153,7 @@ describe('QueryHistoryProvider', () => {
|
||||
let children = testProvider.getChildren();
|
||||
should(children).length(1, 'Should have 1 child initially');
|
||||
|
||||
const testItem: QueryHistoryItem = { queryText: 'SELECT 1', connectionProfile: azdataTest.stubs.connectionProfile.createConnectionProfile(), timestamp: new Date(), isSuccess: true };
|
||||
const testItem: QueryHistoryItem = { queryText: 'SELECT 1', connectionProfile: azdataTest.stubs.azdata.createConnectionProfile(), timestamp: new Date().toLocaleString(), isSuccess: true };
|
||||
await waitForItemRefresh(() => testProvider.deleteItem(testItem));
|
||||
children = testProvider.getChildren();
|
||||
should(children).length(1, 'Should still have 1 child after deleting item');
|
||||
@@ -213,16 +217,16 @@ describe('QueryHistoryProvider', () => {
|
||||
}
|
||||
|
||||
async function fireQueryEventAndWaitForRefresh(type: azdata.queryeditor.QueryEventType, document: azdata.queryeditor.QueryDocument, queryInfo: azdata.queryeditor.QueryInfo, timeoutMs?: number): Promise<void> {
|
||||
await waitForItemRefresh(() => testListener.onQueryEvent(type, document, undefined, queryInfo), timeoutMs);
|
||||
await waitForItemRefresh(async () => testListener.onQueryEvent(type, document, undefined, queryInfo), timeoutMs);
|
||||
}
|
||||
|
||||
async function waitForItemRefresh(func: Function, timeoutMs?: number): Promise<void> {
|
||||
async function waitForItemRefresh(func: () => Promise<void>, timeoutMs?: number): Promise<void> {
|
||||
const promises: Promise<any>[] = [azdataTest.helpers.eventToPromise(testProvider.onDidChangeTreeData)];
|
||||
const timeoutPromise = timeoutMs ? new Promise<void>(r => setTimeout(() => r(), timeoutMs)) : undefined;
|
||||
if (timeoutPromise) {
|
||||
promises.push(timeoutPromise);
|
||||
}
|
||||
func();
|
||||
await func();
|
||||
await Promise.race(promises);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user