Skip to content

Commit

Permalink
display spinner when user clicks on Install Now
Browse files Browse the repository at this point in the history
-
Ticket: SUITEDEV-24431
  • Loading branch information
hawser86 committed Jan 22, 2021
1 parent b4268a1 commit d27fe6a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/renderer/components/app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,13 @@ <h1 class="e-layout__title">GAP Secret Editor</h1>
</div>
</section>
</main>

<div class="overlaycontainer" :class="{ 'e-hidden': !updateInProgress }">
<div class="e-overlay e-overlay-centered" style="border-radius: 0">
<div class="e-overlay__center">
<e-spinner></e-spinner>
</div>
</div>
</div>
</div>
</div>
5 changes: 3 additions & 2 deletions src/renderer/components/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export default {
context: '',
searchTerm: '',
backups: [],
selectedBackupTime: null
selectedBackupTime: null,
updateInProgress: false
}),
computed: {
availableContexts() {
Expand Down Expand Up @@ -200,7 +201,7 @@ export default {
},
async mounted() {
await this.initialize();
listenForUpdates();
listenForUpdates(confirmed => this.updateInProgress = confirmed);
ipcRenderer.send('ui-ready');
logger.info('ui-ready');
}
Expand Down
20 changes: 20 additions & 0 deletions src/renderer/components/app/app.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { shallowMount } from '@vue/test-utils';
import flushPromises from 'flush-promises';
import { ipcRenderer } from 'electron';
import kubernetesClient from '../../lib/kubernetes-client/kubernetes-client';
import notificationDisplayer from '../../lib/notification-displayer';

Expand Down Expand Up @@ -519,6 +520,25 @@ describe('App', () => {
});
});
});

describe('when update is available', () => {
it('should show loading indicator when update request is confirmed', async () => {
sinon.stub(kubernetesClient, 'listContexts').resolves([]);
sinon.stub(kubernetesClient, 'listNamespaces').resolves([]);
sinon.stub(window.e.utils, 'openConsequentialConfirmationDialog').callsFake(config => {
config.confirm.callback();
});

const fakeEvent = { sender: { send: () => {} } };
const { vm } = await loadApp();

ipcRenderer.emit('confirm-update', fakeEvent, { update: 'info' });
await vm.$nextTick();
await vm.$nextTick();

expect(vm.updateInProgress).to.eql(true);
});
});
});

const loadApp = async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ipcRenderer } from 'electron';

export const listenForUpdates = () => {
export const listenForUpdates = updateConfirmedCallback => {
ipcRenderer.on('confirm-update', async (event, updateInfo) => {
const confirmed = await confirm(updateInfo);
event.sender.send('confirm-update-response', confirmed);
updateConfirmedCallback(confirmed);
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,51 @@ describe('auto-update-confirmation', () => {
sinon.stub(window.e.utils, 'openConsequentialConfirmationDialog').callsFake(config => {
config.confirm.callback();
});
let callBackResponse;
let eventResponse;
const fakeEvent = {
sender: {}
sender: {
send: (channel, isConfirmed) => {
eventResponse = { channel, isConfirmed };
}
}
};
const responseArguments = new Promise(resolve => {
fakeEvent.sender.send = (channel, isConfirmed) => {
resolve({ channel, isConfirmed });
};
});

listenForUpdates();
listenForUpdates(isConfirmed => { callBackResponse = isConfirmed; });
ipcRenderer.emit('confirm-update', fakeEvent, { update: 'info' });
await nextTick();

expect(await responseArguments).to.eql({
expect(eventResponse).to.eql({
channel: 'confirm-update-response',
isConfirmed: true
});
expect(callBackResponse).to.eql(true);
});

it('should respond with false when user cancelled the update', async () => {
sinon.stub(window.e.utils, 'openConsequentialConfirmationDialog').callsFake(config => {
config.cancel.callback();
});
let callBackResponse;
let eventResponse;
const fakeEvent = {
sender: {}
sender: {
send: (channel, isConfirmed) => {
eventResponse = { channel, isConfirmed };
}
}
};
const responseArguments = new Promise(resolve => {
fakeEvent.sender.send = (channel, isConfirmed) => {
resolve({ channel, isConfirmed });
};
});

listenForUpdates();
listenForUpdates(isConfirmed => { callBackResponse = isConfirmed; });
ipcRenderer.emit('confirm-update', fakeEvent, { update: 'info' });
await nextTick();

expect(await responseArguments).to.eql({
expect(eventResponse).to.eql({
channel: 'confirm-update-response',
isConfirmed: false
});
expect(callBackResponse).to.eql(false);
});
});

const nextTick = () => new Promise(resolve => setTimeout(resolve, 0));

0 comments on commit d27fe6a

Please sign in to comment.