-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Ticket: AUT-2324 Co-authored-by: Tamas Toth <[email protected]>
- Loading branch information
Showing
6 changed files
with
233 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 18 additions & 3 deletions
21
src/renderer/components/settings-dialog/settings-dialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
import { ipcRenderer } from 'electron'; | ||
import { setDataPath, getSync, setSync } from 'electron-json-storage'; | ||
|
||
export const SETTING_FILE_NAME = 'secret-editor-settings'; | ||
|
||
export default { | ||
name: 'settings-dialog', | ||
template: require('./settings-dialog.html'), | ||
data: () => ({ | ||
dialogOpened: false | ||
dialogOpened: false, | ||
gcloudPath: '' | ||
}), | ||
methods: { | ||
save() { | ||
console.log('save'); | ||
setSync(SETTING_FILE_NAME, { gcloudPath: this.gcloudPath }); | ||
ipcRenderer.send('restart'); | ||
} | ||
}, | ||
mounted() { | ||
ipcRenderer.on('show-settings', async () => { | ||
ipcRenderer.on('show-settings', (event, path) => { | ||
setDataPath(path); | ||
this.gcloudPath = loadSettings().gcloudPath || ''; | ||
this.dialogOpened = true; | ||
}); | ||
} | ||
}; | ||
|
||
const loadSettings = () => { | ||
try { | ||
return getSync(SETTING_FILE_NAME); | ||
} catch (error) { | ||
return {}; | ||
} | ||
}; |
93 changes: 93 additions & 0 deletions
93
src/renderer/components/settings-dialog/settings-dialog.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { rmSync, writeFileSync } from 'fs'; | ||
import SettingsDialog, { SETTING_FILE_NAME } from './settings-dialog'; | ||
import { ipcRenderer } from 'electron'; | ||
import { getDataPath, getSync, setDataPath, setSync } from 'electron-json-storage'; | ||
|
||
describe('SettingsDialog', () => { | ||
const settingsFilePath = '/tmp/secret-editor-test/'; | ||
|
||
context('when show-settings event arrives', () => { | ||
it('should display dialog', async () => { | ||
const wrapper = mount(SettingsDialog); | ||
expect(wrapper.vm.dialogOpened).to.be.false; | ||
|
||
await emitShowSettings(wrapper); | ||
|
||
expect(wrapper.vm.dialogOpened).to.be.true; | ||
}); | ||
|
||
it('should call setDataPath on electron-storage-json', async () => { | ||
const wrapper = mount(SettingsDialog); | ||
setDataPath('/oldTestPath'); | ||
|
||
await emitShowSettings(wrapper); | ||
|
||
expect(getDataPath()).to.eql(settingsFilePath); | ||
}); | ||
|
||
it('should initialise settings when settings file does not exist', async () => { | ||
rmSync(settingsFilePath, { force: true, recursive: true }); | ||
const wrapper = mount(SettingsDialog); | ||
|
||
await emitShowSettings(wrapper); | ||
|
||
expect(wrapper.find('#gcloud-path').element.value).to.eql(''); | ||
}); | ||
|
||
it('should initialise glcoud path when settings file exists but path is not set', async () => { | ||
setSync(SETTING_FILE_NAME, {}, { dataPath: settingsFilePath }); | ||
const wrapper = mount(SettingsDialog); | ||
|
||
await emitShowSettings(wrapper); | ||
|
||
expect(wrapper.find('#gcloud-path').element.value).to.eql(''); | ||
}); | ||
|
||
it('should initialise glcoud path when settings file contains invalid json', async () => { | ||
writeFileSync(`${settingsFilePath}/${SETTING_FILE_NAME}.json`, 'INVALID'); | ||
const wrapper = mount(SettingsDialog); | ||
|
||
await emitShowSettings(wrapper); | ||
|
||
expect(wrapper.find('#gcloud-path').element.value).to.eql(''); | ||
}); | ||
|
||
it('should initialise glcoud path when settings file exists and path is set', async () => { | ||
setSync(SETTING_FILE_NAME, { gcloudPath: '/some-interesting-path' }, { dataPath: settingsFilePath }); | ||
const wrapper = mount(SettingsDialog); | ||
|
||
await emitShowSettings(wrapper); | ||
|
||
expect(wrapper.find('#gcloud-path').element.value).to.eql('/some-interesting-path'); | ||
}); | ||
}); | ||
|
||
describe('#save', () => { | ||
it('should update settings file', async () => { | ||
setSync(SETTING_FILE_NAME, { gcloudPath: '/some-interesting-path' }, { dataPath: settingsFilePath }); | ||
const wrapper = mount(SettingsDialog); | ||
await emitShowSettings(wrapper); | ||
|
||
await wrapper.find('#gcloud-path').setValue('/an-even-more-interesting-path'); | ||
await wrapper.find('#saveButton').trigger('click'); | ||
|
||
expect(getSync(SETTING_FILE_NAME)).to.eql({ gcloudPath: '/an-even-more-interesting-path' }); | ||
}); | ||
|
||
it('should send restart message to main process when save button clicked', async () => { | ||
sinon.stub(ipcRenderer, 'send'); | ||
const wrapper = mount(SettingsDialog); | ||
await emitShowSettings(wrapper); | ||
|
||
await wrapper.find('#saveButton').trigger('click'); | ||
|
||
expect(ipcRenderer.send).to.have.been.calledWith('restart'); | ||
}); | ||
}); | ||
|
||
const emitShowSettings = async (wrapper) => { | ||
ipcRenderer.emit('show-settings', {}, settingsFilePath); | ||
await wrapper.vm.$nextTick(); | ||
}; | ||
}); |