Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
test: plugin manager unit tests (#1583)
Browse files Browse the repository at this point in the history
* refactor: properly mount PluginInstallModal in tests

* refactor: properly mount PluginManagerTable in tests

* refactor: pass labels to switch button component

* test: initial tests for plugin store module

* test: more unit tests

* refactor: restart store unit tests

* tests: more unit tests

* tests: restructure and add tests

* tests: add tests for enabled getter

* tests: add tests for isBlacklisted getter

* tests: add tests for isWhitelisted getter

* tests: add tests for isUpdateAvailable getter

* tests: add tests for latestVersion getter

* refactor: return boolean values from isEnabled getter

* tests: add tests for isEnabled getter

* tests: add tests for isInstalledSupported getter

* tests: add tests for isLoaded getter

* refactor: return boolean values from profileHasPluginOptions getter

* tests: add tests for profileHasPluginOptions getter

* tests: add tests for pluginOptions getter

* style: fix strange whitespace

* chore: remove blacklist fix for tainted profiles

* tests: add tests for reset action

* tests: add tests for loadPluginsForProfiles action

* refactor: use dispatch in isWhitelisted test

* style: missing space

* tests: add tests for loadPluginsForProfile action

* tests: add tests for setBlacklisted action

* refactor: mock release service

* refactor: remove releaseService mock, spy on getter instead

* refactor: group getters in describe block

* refactor: simplify store setups

* tests: add tests for filtered getter

* tests: add tests for setLoaded action

* tests: add tests for setEnabled action

* style: resolve style guide violations

* refactor: change setLoaded test to cover all branches

* refactor: setup state only once in setEnabled tests

* tests: add tests for deletePlugin action

* tests: add tests for avatar getter

* refactor: change assignment of loadedPlugins in avatars getters

* tests: add tests for menuItems getter

* tests: add tests for setMenuItems action

* tests: cover missing branch in setMenuItems action

* tests: add tests for themes getter

* tests: add tests for setThemes action

* tests: add tests for deleteLoaded action

* tests: add tests for deletePluginOptionsForProfile action

* tests: add tests for deleteInstalled action

* tests: add tests for setAvatars action

* tests: add tests for setPluginOption action

* tests: add tests for avatars getter

* tests: add tests for missing branch of deletePluginOptionsForProfile actions

* tests: add tests for walletTabs getter

* tests: add tests for setWalletTabs action

Co-authored-by: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com>
  • Loading branch information
dated and alexbarnsley committed Feb 26, 2020
1 parent 4a1a424 commit b2832b2
Show file tree
Hide file tree
Showing 9 changed files with 1,913 additions and 68 deletions.
25 changes: 21 additions & 4 deletions __tests__/unit/__fixtures__/store/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@ const profile1 = {
currency: 'usd',
language: 'en',
name: 'Profile 1',
theme: 'light'
theme: 'light',
filterBlacklistedPlugins: true,
avatar: {
pluginId: 'avatar-plugin',
avatarName: 'avatar'
}
}

export default {
profile1
const profile2 = {
id: 'profile2',
networkId: 'main',
background: 'bg',
currency: 'usd',
language: 'en',
name: 'Profile 2',
theme: 'light'
}

export default [
profile1,
profile2
]

export {
profile1
profile1,
profile2
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { shallowMount } from '@vue/test-utils'
import useI18nGlobally from '../../../__utils__/i18n'
import { PluginManagerButtonSwitch } from '@/components/PluginManager/PluginManagerButtons'

const i18n = useI18nGlobally()

let wrapper

beforeEach(() => {
wrapper = shallowMount(PluginManagerButtonSwitch)
wrapper = shallowMount(PluginManagerButtonSwitch, { i18n })
})

describe('PluginManagerButtonSwitch', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,107 @@
import { shallowMount } from '@vue/test-utils'
import { mount } from '@vue/test-utils'
import useI18nGlobally from '../../../__utils__/i18n'
import { PluginInstallModal } from '@/components/PluginManager/PluginManagerModals'

jest.mock('electron', () => ({
ipcRenderer: {
on: jest.fn()
on: jest.fn(),
send: jest.fn(),
removeListener: jest.fn()
}
}))

const i18n = useI18nGlobally()
let wrapper

const plugin = {
id: 'test',
source: 'source'
}

const availablePlugin = {
config: {
id: 'test',
source: 'store-source'
}
}

const mocks = {
$store: {
getters: {
'plugin/availableById': jest.fn(() => availablePlugin)
}
},
formatter_bytes: jest.fn(bytes => bytes),
formatter_percentage: jest.fn()
}

beforeEach(() => {
wrapper = shallowMount(PluginInstallModal, {
wrapper = mount(PluginInstallModal, {
i18n,
mocks,
propsData: {
plugin: {
id: 'test'
}
plugin
},
stubs: {
Portal: '<div><slot /></div>'
}
})

wrapper.setData({
progress: {
percent: 0.5,
transferredBytes: 50,
totalBytes: 100
}
})
})

afterEach(() => {
wrapper.destroy()
})

describe('PluginInstallModal', () => {
it('should render', () => {
expect(wrapper.isVueInstance()).toBeTrue()
})

describe('Methods', () => {
it('should emit install event', () => {
wrapper.vm.emitInstall()
expect(wrapper.emitted('install')).toBeTruthy()
})

describe('emitDownload', () => {
it('should emit download event with plugin source', () => {
wrapper.vm.emitDownload()
expect(wrapper.emitted('download', plugin.source)).toBeTruthy()
})

it('should emit download event with available plugin source if update', () => {
wrapper.setProps({ isUpdate: true })
wrapper.vm.emitDownload()
expect(wrapper.emitted('download', availablePlugin.config.source)).toBeTruthy()
})
})

describe('emitClose', () => {
it('should emit close event', () => {
wrapper.vm.emitClose()
expect(wrapper.emitted('close')).toBeTruthy()
})

it('should call cancel()', () => {
jest.spyOn(wrapper.vm, 'cancel')
wrapper.vm.emitClose()
expect(wrapper.vm.cancel).toHaveBeenCalled()
})

it('should call cleanup() if download failed', () => {
wrapper.setData({ isDownloadFailed: true })
jest.spyOn(wrapper.vm, 'cleanup')
wrapper.vm.emitClose()
expect(wrapper.vm.cleanup).toHaveBeenCalled()
})
})
})
})
74 changes: 59 additions & 15 deletions __tests__/unit/components/PluginManager/PluginManagerTable.spec.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
import { shallowMount } from '@vue/test-utils'
import { mount } from '@vue/test-utils'
import useI18nGlobally from '../../__utils__/i18n'
import { PluginManagerTable } from '@/components/PluginManager'

const i18n = useI18nGlobally()
let wrapper

const plugins = [
{ id: 'plugin-enabled' },
{ id: 'plugin-disabled' },
{ id: 'plugin-available' }
]

beforeEach(() => {
wrapper = shallowMount(PluginManagerTable, {
wrapper = mount(PluginManagerTable, {
i18n,
mocks: {
$store: {
getters: {
'plugin/isEnabled': jest.fn((pluginId) => pluginId === 'test'),
'plugin/isInstalled': jest.fn((pluginId) => pluginId === 'test'),
'plugin/isUpdateAvailable': jest.fn((pluginId) => pluginId === 'test')
'plugin/isEnabled': jest.fn((pluginId) => pluginId === 'plugin-enabled'),
'plugin/isInstalled': jest.fn((pluginId) => pluginId === 'plugin-enabled' || pluginId === 'plugin-disabled'),
'plugin/isUpdateAvailable': jest.fn((pluginId) => pluginId === 'plugin-enabled')
}
}
},
formatter_bytes: jest.fn()
},
propsData: {
activeCategory: 'all'
}
},
attrs: {
rows: plugins.map(plugin => ({ ...plugin, categories: ['other'] }))
},
sync: false
})
})

Expand All @@ -28,44 +39,77 @@ describe('PluginManagerTable', () => {
expect(wrapper.isVueInstance()).toBeTrue()
})

it('should include the categories column only if activeCategory is \'all\'', () => {
expect(wrapper.vm.columns.filter(column => column.field === 'categories')).toHaveLength(1)

wrapper.setProps({ activeCategory: 'other' })

expect(wrapper.vm.columns.filter(column => column.field === 'categories')).toHaveLength(0)
})

it('should emit sort-change event when clicking on a categories header', () => {
wrapper.findAll('th').filter(node => node.text() === 'PLUGIN_TABLE.CATEGORY').at(0).trigger('click')
expect(wrapper.emitted('on-sort-change')).toBeTruthy()
})

it('should emit sort-change event when clicking on a status header', () => {
wrapper.findAll('th').filter(node => node.text() === 'PLUGIN_TABLE.STATUS').at(0).trigger('click')
expect(wrapper.emitted('on-sort-change')).toBeTruthy()
})

describe('Methods', () => {
it('should emit on-sort-change event', () => {
wrapper.vm.onSortChange(['foobar'])
expect(wrapper.emitted('on-sort-change', 'foobar')).toBeTruthy()
})

it('should emit show-details event', () => {
wrapper.vm.emitShowDetails({ id: 'test' })
expect(wrapper.emitted('show-details', { id: 'test' })).toBeTruthy()
wrapper.vm.emitShowDetails({ id: 'enabled' })
expect(wrapper.emitted('show-details', plugins[0])).toBeTruthy()
})

describe('getStatusText', () => {
it('should return \'enabled\' for installed and enabled plugins', () => {
expect(wrapper.vm.getStatusText(plugins[0].id)).toBe('enabled')
})

it('should return \'disabled\' for installed and disabled plugins', () => {
expect(wrapper.vm.getStatusText(plugins[1].id)).toBe('disabled')
})

it('should return \'available\' for not installed plugins', () => {
expect(wrapper.vm.getStatusText(plugins[2].id)).toBe('available')
})
})

describe('isEnabled', () => {
it('should return true for enabled plugins', () => {
expect(wrapper.vm.isEnabled('test')).toBeTrue()
expect(wrapper.vm.isEnabled(plugins[0].id)).toBeTrue()
})

it('should return false for disabled plugins', () => {
expect(wrapper.vm.isEnabled('not-enabled')).toBeFalse()
expect(wrapper.vm.isEnabled(plugins[1].id)).toBeFalse()
})
})

describe('isInstalled', () => {
it('should return true for installed plugins', () => {
expect(wrapper.vm.isInstalled('test')).toBeTrue()
expect(wrapper.vm.isInstalled(plugins[0].id)).toBeTrue()
expect(wrapper.vm.isInstalled(plugins[1].id)).toBeTrue()
})

it('should return false for not installed plugins', () => {
expect(wrapper.vm.isInstalled('not-installed')).toBeFalse()
expect(wrapper.vm.isInstalled(plugins[2].id)).toBeFalse()
})
})

describe('isUpdateAvailable', () => {
it('should return true if there is an available update', () => {
expect(wrapper.vm.isUpdateAvailable('test')).toBeTrue()
expect(wrapper.vm.isUpdateAvailable(plugins[0].id)).toBeTrue()
})

it('should return false if there is no available update', () => {
expect(wrapper.vm.isUpdateAvailable('no-update')).toBeFalse()
expect(wrapper.vm.isUpdateAvailable(plugins[1].id)).toBeFalse()
})
})
})
Expand Down
13 changes: 10 additions & 3 deletions __tests__/unit/services/release.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import release from '@/services/release'
import releaseService from '@/services/release'
import packageJson from '@package.json'

const releaseUrl = 'https://github.com/ArkEcosystem/desktop-wallet/releases/latest'

describe('Services > Release', () => {
describe('currentVersion', () => {
it('should return the current version', () => {
expect(releaseService.currentVersion).toEqual(packageJson.version)
})
})

describe('latestReleaseUrl', () => {
it('returns the URL of the latest release endpoint', () => {
expect(release.latestReleaseUrl).toEqual(releaseUrl)
it('should return the URL of the latest release endpoint', () => {
expect(releaseService.latestReleaseUrl).toEqual(releaseUrl)
})
})
})
Loading

0 comments on commit b2832b2

Please sign in to comment.