Skip to content

Commit

Permalink
add navigation guard for reloading
Browse files Browse the repository at this point in the history
-
Ticket: SUITEDEV-29114
  • Loading branch information
hawser86 committed Oct 29, 2021
1 parent 727e6c2 commit 983365c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/renderer/components/app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h1 class="e-layout__title">GAP Secret Editor</h1>
<div class="e-grid e-grid-small">
<div class="e-cell e-cell-small">
<e-tooltip content="Reload secret">
<div id="reload-button" class="e-btn" @click="loadSecret()" :disabled="!loadEnabled">
<div id="reload-button" class="e-btn" @click="reloadSecret()" :disabled="!loadEnabled">
<div class="e-btn__loading" :class="{ 'e-btn__loading-active': loading.secretLoad }">
<e-spinner data-size="small"></e-spinner>
<e-icon icon="e-refresh"></e-icon>
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ export default {
this.setBackups(backups);
this.selectedBackupTime = backups.length > 0 ? backups[0].backupTime : null;
},
async reloadSecret() {
if (!this.hasSecretChanged || await notificationDisplayer.shouldChangesBeDiscarded()) {
await this.loadSecret();
}
},
async loadSecret() {
if (!this.loadEnabled) return;

Expand Down
51 changes: 51 additions & 0 deletions src/renderer/components/app/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,57 @@ describe('App', () => {
});
});

describe('#reloadSecret', () => {
it('should not load secret when user cancels a change', async () => {
sinon.stub(kubernetesClient, 'listContexts').resolves([]);
sinon.stub(kubernetesClient, 'listNamespaces').resolves([]);
sinon.stub(kubernetesClient, 'loadSecret').resolves({ FIELD: 'loaded-value' });
sinon.stub(notificationDisplayer, 'shouldChangesBeDiscarded').resolves(false);
const { vm } = await loadApp();
vm.secretNamespace = 'space';
vm.secretName = 'name';
vm.originalSecret = { FIELD: 'original-value' };
vm.secret = [{ key: 'FIELD', value: 'changed-value' }];

await vm.reloadSecret();

expect(vm.secret).to.eql([{ key: 'FIELD', value: 'changed-value' }]);
});

it('should load secret when user discards unsaved changes', async () => {
sinon.stub(kubernetesClient, 'listContexts').resolves([]);
sinon.stub(kubernetesClient, 'listNamespaces').resolves([]);
sinon.stub(kubernetesClient, 'loadSecret').resolves({ FIELD: 'loaded-value' });
sinon.stub(notificationDisplayer, 'shouldChangesBeDiscarded').resolves(true);
const { vm } = await loadApp();
vm.secretNamespace = 'space';
vm.secretName = 'name';
vm.originalSecret = { FIELD: 'original-value' };
vm.secret = [{ key: 'FIELD', value: 'changed-value' }];

await vm.reloadSecret();

expect(vm.secret).to.eql([{ key: 'FIELD', value: 'loaded-value' }]);
});

it('should load secret without confirmation when there are no changes in the secret', async () => {
sinon.stub(kubernetesClient, 'listContexts').resolves([]);
sinon.stub(kubernetesClient, 'listNamespaces').resolves([]);
sinon.stub(kubernetesClient, 'loadSecret').resolves({ FIELD: 'loaded-value' });
sinon.stub(notificationDisplayer, 'shouldChangesBeDiscarded');
const { vm } = await loadApp();
vm.secretNamespace = 'space';
vm.secretName = 'name';
vm.originalSecret = { FIELD: 'original-value' };
vm.secret = [{ key: 'FIELD', value: 'original-value' }];

await vm.reloadSecret();

expect(vm.secret).to.eql([{ key: 'FIELD', value: 'loaded-value' }]);
expect(notificationDisplayer.shouldChangesBeDiscarded).to.not.have.been.called;
});
});

describe('#loadSecret', () => {
it('should not load secret when no secret is selected', async () => {
sinon.stub(kubernetesClient, 'listContexts').resolves([]);
Expand Down

0 comments on commit 983365c

Please sign in to comment.