Add Commit and Rollback buttons to the Query Tool. Fixes #2418

This commit is contained in:
Akshay Joshi
2019-02-22 14:28:05 +00:00
committed by Dave Page
parent 0766b17726
commit 38b034ec3c
19 changed files with 453 additions and 110 deletions

View File

@@ -22,6 +22,7 @@ describe('#callRenderAfterPoll', () => {
trigger: jasmine.createSpy('SQLEditor.trigger'),
update_msg_history: jasmine.createSpy('SQLEditor.update_msg_history'),
disable_tool_buttons: jasmine.createSpy('SQLEditor.disable_tool_buttons'),
disable_transaction_buttons: jasmine.createSpy('SQLEditor.disable_transaction_buttons'),
query_start_time: new Date(),
};
alertify = jasmine.createSpyObj('alertify', ['success']);

View File

@@ -44,6 +44,7 @@ describe('ExecuteQuery', () => {
'initTransaction',
'handle_connection_lost',
'update_notifications',
'disable_transaction_buttons',
]);
sqlEditorMock.transId = 123;
sqlEditorMock.rows_affected = 1000;
@@ -112,6 +113,46 @@ describe('ExecuteQuery', () => {
});
});
describe('when query was successful but in transaction block', () => {
beforeEach(() => {
response = {
data: {status: 'Success', notifies: [{'pid': 100}], transaction_status: 2},
};
networkMock.onGet('/sqleditor/query_tool/poll/123').reply(200, response);
executeQuery.poll();
});
it('enable the transaction buttons', (done) => {
setTimeout(
() => {
expect(sqlEditorMock.disable_transaction_buttons)
.toHaveBeenCalledWith(false);
done();
}, 0);
});
});
describe('when query was successful but not in transaction block', () => {
beforeEach(() => {
response = {
data: {status: 'Success', notifies: [{'pid': 100}], transaction_status: 0},
};
networkMock.onGet('/sqleditor/query_tool/poll/123').reply(200, response);
executeQuery.poll();
});
it('disable the transaction buttons', (done) => {
setTimeout(
() => {
expect(sqlEditorMock.disable_transaction_buttons)
.toHaveBeenCalledWith(true);
done();
}, 0);
});
});
describe('when query is still running', () => {
context('when no additional information is returned', () => {
beforeEach(() => {

View File

@@ -93,6 +93,22 @@ describe('the keyboard shortcuts', () => {
key_code: null,
},
},
commit_transaction: {
alt: false,
shift: true,
control: true,
key: {
key_code: 'm',
},
},
rollback_transaction: {
alt: false,
shift: true,
control: true,
key: {
key_code: 'r',
},
},
};
queryToolActionsSpy = jasmine.createSpyObj(queryToolActions, [
@@ -103,6 +119,8 @@ describe('the keyboard shortcuts', () => {
'commentLineCode',
'uncommentLineCode',
'executeQuery',
'executeCommit',
'executeRollback',
]);
});
@@ -521,6 +539,80 @@ describe('the keyboard shortcuts', () => {
});
});
describe('Shift+Ctrl+C', () => {
describe('when there is not a query already running', () => {
beforeEach(() => {
event.shiftKey = true;
event.which = 'm';
event.altKey = false;
event.ctrlKey = true;
keyboardShortcuts.processEventQueryTool(
sqlEditorControllerSpy, queryToolActionsSpy, event
);
});
it('should commit the transaction', () => {
expect(queryToolActionsSpy.executeCommit).toHaveBeenCalledWith(sqlEditorControllerSpy);
});
expectEventPropagationToStop();
});
describe('when the query is already running', () => {
it('does nothing', () => {
event.shiftKey = true;
event.which = 'm';
event.altKey = false;
event.ctrlKey = true;
sqlEditorControllerSpy.isQueryRunning.and.returnValue(true);
keyboardShortcuts.processEventQueryTool(
sqlEditorControllerSpy, queryToolActionsSpy, event
);
expect(queryToolActionsSpy.executeCommit).not.toHaveBeenCalled();
});
});
});
describe('Shift+Ctrl+R', () => {
describe('when there is not a query already running', () => {
beforeEach(() => {
event.shiftKey = true;
event.which = 'r';
event.altKey = false;
event.ctrlKey = true;
keyboardShortcuts.processEventQueryTool(
sqlEditorControllerSpy, queryToolActionsSpy, event
);
});
it('should rollback the transaction', () => {
expect(queryToolActionsSpy.executeRollback).toHaveBeenCalledWith(sqlEditorControllerSpy);
});
expectEventPropagationToStop();
});
describe('when the query is already running', () => {
it('does nothing', () => {
event.shiftKey = true;
event.which = 'r';
event.altKey = false;
event.ctrlKey = true;
sqlEditorControllerSpy.isQueryRunning.and.returnValue(true);
keyboardShortcuts.processEventQueryTool(
sqlEditorControllerSpy, queryToolActionsSpy, event
);
expect(queryToolActionsSpy.executeRollback).not.toHaveBeenCalled();
});
});
});
function expectEventPropagationToStop() {
describe('stops all event propogation', () => {

View File

@@ -521,6 +521,32 @@ describe('queryToolActions', () => {
});
});
describe('executeCommit', () => {
describe('when commit action is being run from the query tool', () => {
beforeEach(() => {
setUpSpies('', '');
});
it('calls the execute commit function', () => {
queryToolActions.executeCommit(sqlEditorController);
expect(sqlEditorController.special_sql).toEqual('COMMIT;');
});
});
});
describe('executeRollback', () => {
describe('when rollback action is being run from the query tool', () => {
beforeEach(() => {
setUpSpies('', '');
});
it('calls the execute rollback function', () => {
queryToolActions.executeRollback(sqlEditorController);
expect(sqlEditorController.special_sql).toEqual('ROLLBACK;');
});
});
});
function setUpSpies(selectedQueryString, entireQueryString) {
getValueSpy = jasmine.createSpy('getValueSpy').and.returnValue(entireQueryString);
getSelectionSpy = jasmine.createSpy('getSelectionSpy').and.returnValue(selectedQueryString);