Skip to content

Commit

Permalink
fix: confirm on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Mar 2, 2020
1 parent 821681a commit 75b2553
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/sync-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,24 @@ module.exports = class SyncSettings {
async deleteBackup () {
const signal = notify.signal('Sync-Settings: Deleting backup...')
try {
const cancel = await notify.confirm({
type: 'warning',
message: 'Delete Backup',
detail: 'Are you sure you want to delete your backup?',
defaultId: 1,
buttons: [
'Delete Backup',
'Cancel',
],
})
if (cancel) {
return
}
const backupLocation = this.getBackupLocation()
if (!backupLocation) {
return
}

const data = await backupLocation.delete()
if (!data) {
return
Expand Down
1 change: 1 addition & 0 deletions lib/utils/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const notify = {
warning: (...args) => atom.notifications.addWarning(...args),
info: (...args) => atom.notifications.addInfo(...args),
success: (...args) => atom.notifications.addSuccess(...args),
confirm: (options) => new Promise(resolve => atom.confirm(options, resolve)),

useBusySignal (busySignal) {
notify.busySignal = busySignal
Expand Down
73 changes: 73 additions & 0 deletions spec/sync-settings-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ describe('syncSettings', () => {
})

describe('backup', () => {
it('calls update', async () => {
const backupLocation = syncSettings.getBackupLocation()
spyOn(backupLocation, 'update').and.callThrough()

await syncSettings.backup()

expect(backupLocation.update).toHaveBeenCalled()
})

it('backs up the settings', async () => {
atom.config.set('sync-settings.syncSettings', true)
await syncSettings.backup()
Expand Down Expand Up @@ -348,6 +357,15 @@ describe('syncSettings', () => {
})

describe('restore', () => {
it('calls get', async () => {
const backupLocation = syncSettings.getBackupLocation()
spyOn(backupLocation, 'get').and.callThrough()

await syncSettings.restore()

expect(backupLocation.get).toHaveBeenCalled()
})

it('updates settings', async () => {
atom.config.set('sync-settings.syncSettings', true)
atom.config.set('some-dummy', true)
Expand Down Expand Up @@ -881,6 +899,15 @@ describe('syncSettings', () => {
atom.config.unset('sync-settings.hiddenSettings._lastBackupTime')
})

it('calls get', async () => {
const backupLocation = syncSettings.getBackupLocation()
spyOn(backupLocation, 'get').and.callThrough()

await syncSettings.checkBackup()

expect(backupLocation.get).toHaveBeenCalled()
})

it('updates last time on backup', async () => {
await syncSettings.backup()

Expand Down Expand Up @@ -935,6 +962,43 @@ describe('syncSettings', () => {
})
})

describe('create', () => {
it('calls create', async () => {
const backupLocation = syncSettings.getBackupLocation()
spyOn(backupLocation, 'create').and.callThrough()

await syncSettings.createBackup()

expect(backupLocation.create).toHaveBeenCalled()
})
})

describe('delete', () => {
it('confirms and calls delete', async () => {
// eslint-disable-next-line standard/no-callback-literal
spyOn(atom, 'confirm').and.callFake((opts, cb) => cb(0))
const backupLocation = syncSettings.getBackupLocation()
spyOn(backupLocation, 'delete').and.callThrough()

await syncSettings.deleteBackup()

expect(atom.confirm).toHaveBeenCalled()
expect(backupLocation.delete).toHaveBeenCalled()
})

it('cancel does not call delete', async () => {
// eslint-disable-next-line standard/no-callback-literal
spyOn(atom, 'confirm').and.callFake((opts, cb) => cb(1))
const backupLocation = syncSettings.getBackupLocation()
spyOn(backupLocation, 'delete').and.callThrough()

await syncSettings.deleteBackup()

expect(atom.confirm).toHaveBeenCalled()
expect(backupLocation.delete).not.toHaveBeenCalled()
})
})

describe('fork gist', () => {
it('forks gist', async () => {
const gistId = atom.config.get('sync-settings.gistId')
Expand All @@ -944,6 +1008,15 @@ describe('syncSettings', () => {
expect(gistId).not.toBe(atom.config.get('sync-settings.gistId'))
})

it('calls fork', async () => {
const backupLocation = syncSettings.getBackupLocation()
spyOn(backupLocation, 'fork').and.callThrough()

await syncSettings.fork()

expect(backupLocation.fork).toHaveBeenCalled()
})

describe('notifications', () => {
beforeEach(() => {
atom.notifications.clear()
Expand Down

0 comments on commit 75b2553

Please sign in to comment.