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

test: plugin manager unit tests #1583

Merged
merged 70 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
1cfefb0
refactor: properly mount PluginInstallModal in tests
dated Dec 11, 2019
14ee7b8
refactor: properly mount PluginManagerTable in tests
dated Dec 11, 2019
a0a2cc7
Merge branch 'develop' into tests/plugin-manager
dated Dec 11, 2019
c1a69f8
Merge branch 'develop' into tests/plugin-manager
dated Jan 8, 2020
42535d6
Merge branch 'develop' into tests/plugin-manager
dated Jan 8, 2020
3e562a4
Merge branch 'develop' into tests/plugin-manager
dated Jan 8, 2020
8d46ac7
Merge branch 'develop' into tests/plugin-manager
dated Jan 16, 2020
a0a0d03
refactor: pass labels to switch button component
dated Jan 16, 2020
05e8fa4
test: initial tests for plugin store module
dated Jan 16, 2020
5ed7f19
Merge branch 'develop' into tests/plugin-manager
dated Jan 27, 2020
b213be6
test: more unit tests
dated Jan 27, 2020
573adff
refactor: restart store unit tests
dated Feb 16, 2020
b99202b
tests: more unit tests
dated Feb 16, 2020
633bd05
Merge branch 'develop' into tests/plugin-manager
dated Feb 17, 2020
094fa12
tests: restructure and add tests
dated Feb 17, 2020
f897150
tests: add tests for enabled getter
dated Feb 17, 2020
99b1ccb
tests: add tests for isBlacklisted getter
dated Feb 17, 2020
db5a6b8
tests: add tests for isWhitelisted getter
dated Feb 17, 2020
66eda93
tests: add tests for isUpdateAvailable getter
dated Feb 17, 2020
068b3e6
tests: add tests for latestVersion getter
dated Feb 17, 2020
8d3ae2c
refactor: return boolean values from isEnabled getter
dated Feb 17, 2020
c117d83
tests: add tests for isEnabled getter
dated Feb 17, 2020
aa64e68
tests: add tests for isInstalledSupported getter
dated Feb 18, 2020
85dac01
Merge branch 'develop' into tests/plugin-manager
dated Feb 19, 2020
aea8c31
tests: add tests for isLoaded getter
dated Feb 20, 2020
d9cc21e
refactor: return boolean values from profileHasPluginOptions getter
dated Feb 20, 2020
d095ce1
tests: add tests for profileHasPluginOptions getter
dated Feb 20, 2020
190f1fb
tests: add tests for pluginOptions getter
dated Feb 20, 2020
0e50211
style: fix strange whitespace
dated Feb 20, 2020
658ead4
chore: remove blacklist fix for tainted profiles
dated Feb 20, 2020
a4c8efb
tests: add tests for reset action
dated Feb 20, 2020
40e564e
tests: add tests for loadPluginsForProfiles action
dated Feb 20, 2020
c78fad1
refactor: use dispatch in isWhitelisted test
dated Feb 20, 2020
5c51b1c
style: missing space
dated Feb 20, 2020
a3e27ad
tests: add tests for loadPluginsForProfile action
dated Feb 20, 2020
3dc7157
tests: add tests for setBlacklisted action
dated Feb 20, 2020
1c16fa8
refactor: mock release service
dated Feb 20, 2020
9459f1e
refactor: remove releaseService mock, spy on getter instead
dated Feb 21, 2020
50de369
refactor: group getters in describe block
dated Feb 21, 2020
167fb76
refactor: simplify store setups
dated Feb 21, 2020
bd63d3a
tests: add tests for filtered getter
dated Feb 21, 2020
69aca6d
tests: add tests for setLoaded action
dated Feb 21, 2020
b40fce2
tests: add tests for setEnabled action
dated Feb 21, 2020
bd428ab
Merge branch 'develop' into tests/plugin-manager
dated Feb 21, 2020
56b3265
style: resolve style guide violations
dated Feb 21, 2020
116a805
refactor: change setLoaded test to cover all branches
dated Feb 21, 2020
7aa6752
refactor: setup state only once in setEnabled tests
dated Feb 21, 2020
81810fe
tests: add tests for deletePlugin action
dated Feb 21, 2020
2639591
Merge branch 'develop' into tests/plugin-manager
dated Feb 22, 2020
3862fb8
tests: add tests for avatar getter
dated Feb 22, 2020
552b67a
refactor: change assignment of loadedPlugins in avatars getters
dated Feb 22, 2020
6bd9a07
tests: add tests for menuItems getter
dated Feb 22, 2020
6a8f503
tests: add tests for setMenuItems action
dated Feb 22, 2020
84eb97e
tests: cover missing branch in setMenuItems action
dated Feb 22, 2020
66fb686
tests: add tests for themes getter
dated Feb 24, 2020
1a2b593
tests: add tests for setThemes action
dated Feb 24, 2020
46cb592
tests: add tests for deleteLoaded action
dated Feb 24, 2020
6bb8e38
tests: add tests for deletePluginOptionsForProfile action
dated Feb 24, 2020
704d97f
tests: add tests for deleteInstalled action
dated Feb 24, 2020
8705482
tests: add tests for setAvatars action
dated Feb 24, 2020
7a887af
tests: add tests for setPluginOption action
dated Feb 24, 2020
b26b2ad
tests: add tests for avatars getter
dated Feb 24, 2020
72b3a50
tests: add tests for missing branch of deletePluginOptionsForProfile …
dated Feb 24, 2020
562a801
Merge branch 'develop' into tests/plugin-manager
dated Feb 24, 2020
d308ff6
tests: add tests for walletTabs getter
dated Feb 24, 2020
b04eb6e
tests: add tests for setWalletTabs action
dated Feb 24, 2020
db381ae
Merge branch 'develop' into tests/plugin-manager
dated Feb 24, 2020
18d3b35
Merge branch 'develop' into tests/plugin-manager
alexbarnsley Feb 25, 2020
fe7d9f9
Merge branch 'develop' into tests/plugin-manager
alexbarnsley Feb 26, 2020
1db3ae5
Merge branch 'develop' into tests/plugin-manager
alexbarnsley Feb 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})
})
})
})
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