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

Commit

Permalink
Merge branch 'staging' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian committed Mar 26, 2020
2 parents bd657cb + 4e5c4a8 commit 268a84b
Show file tree
Hide file tree
Showing 22 changed files with 342 additions and 96 deletions.
89 changes: 89 additions & 0 deletions __tests__/unit/components/Plugin/PluginWrapper.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { createLocalVue, mount } from '@vue/test-utils'
import PluginWrapper from '@/components/Plugin/PluginWrapper'
import { Wormhole } from 'portal-vue'

const vue = createLocalVue()

jest.mock('portal-vue', () => ({
Wormhole: {
open: jest.fn(),
close: jest.fn()
}
}))

describe('PluginWrapper', () => {
const mountComponent = config => {
return mount(PluginWrapper, config)
}

describe('when there is a footer slot', () => {
it('should open a Wormhole when mounted', done => {
const spy = jest.spyOn(Wormhole, 'open')

const wrapper = mountComponent({
slots: {
footer: '<div></div>'
}
})

vue.nextTick(() => {
expect(spy).toHaveBeenCalledWith({
to: 'plugin-footer',
from: 'plugin-wrapper',
passengers: wrapper.vm.footerSlot
})
done()
})

spy.mockRestore()
})

it('should close a Wormhole when destroyed', done => {
const spy = jest.spyOn(Wormhole, 'close')

mountComponent({
slots: {
footer: '<div></div>'
}
}).destroy()

vue.nextTick(() => {
expect(spy).toHaveBeenCalledWith({
to: 'plugin-footer',
from: 'plugin-wrapper'
})
done()
})

spy.mockRestore()
})
})

describe('when there is no footer slot', () => {
it('should not open a Wormhole when mounted', done => {
const spy = jest.spyOn(Wormhole, 'open')

mountComponent()

vue.nextTick(() => {
expect(spy).not.toHaveBeenCalled()
done()
})

spy.mockRestore()
})

it('should not close a Wormhole when destroyed', done => {
const spy = jest.spyOn(Wormhole, 'close')

mountComponent().destroy()

vue.nextTick(() => {
expect(spy).not.toHaveBeenCalled()
done()
})

spy.mockRestore()
})
})
})
32 changes: 6 additions & 26 deletions __tests__/unit/services/plugin-manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const app = {
getters: {
'plugin/isEnabled': jest.fn((pluginId) => pluginId === 'plugin-test'),
'plugin/isInstalledSupported': jest.fn(() => true),
'plugin/isGrant': jest.fn(() => true),
'plugin/lastFetched': jest.fn(() => 0),
'profile/byId': jest.fn(() => {}),
'session/pluginAdapter': 'npm'
Expand Down Expand Up @@ -93,14 +94,14 @@ describe('Plugin Manager', () => {
name: 'test-plugin-1',
keywords: PLUGINS.keywords,
'desktop-wallet': {
minVersion: '1.0'
minimumVersion: '1.0'
}
}
const invalidPlugin = {
name: 'test-plugin-2',
keywords: PLUGINS.keywords,
'desktop-wallet': {
minVersion: '3.0'
minimumVersion: '3.0'
}
}

Expand Down Expand Up @@ -241,40 +242,19 @@ describe('Plugin Manager', () => {
})
})

describe('fetchBlacklist', () => {
describe('fetchPluginsList', () => {
it('should fetch using cache-busted url', async () => {
const spy = jest.spyOn(Date.prototype, 'getTime').mockReturnValue(1234)
const spyError = jest.spyOn(console, 'error')

nock('https://raw.githubusercontent.com')
.get('/ark-ecosystem-desktop-plugins/config/master/blacklist.json')
.get('/ark-ecosystem-desktop-plugins/config/master/plugins.json')
.query({
ts: 1234
})
.reply(200, [])

await pluginManager.fetchBlacklist()

expect(spyError).not.toHaveBeenCalled()

spy.mockRestore()
spyError.mockRestore()
})
})

describe('fetchWhitelist', () => {
it('should fetch using cache-busted url', async () => {
const spy = jest.spyOn(Date.prototype, 'getTime').mockReturnValue(1234)
const spyError = jest.spyOn(console, 'error')

nock('https://raw.githubusercontent.com')
.get('/ark-ecosystem-desktop-plugins/config/master/whitelist.json')
.query({
ts: 1234
})
.reply(200, [])

await pluginManager.fetchWhitelist()
await pluginManager.fetchPluginsList()

expect(spyError).not.toHaveBeenCalled()

Expand Down
69 changes: 59 additions & 10 deletions __tests__/unit/store/modules/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ describe('PluginModule', () => {
},
whitelisted: {
global: {
[availablePlugins[0].config.id]: availablePlugins[0].config.version
[availablePlugins[0].config.id]: {
version: availablePlugins[0].config.version
}
}
}
}
Expand Down Expand Up @@ -203,8 +205,12 @@ describe('PluginModule', () => {
},
whitelisted: {
global: {
[plugin1.config.id]: plugin1.config.version,
[plugin2.config.id]: plugin2.config.version
[plugin1.config.id]: {
version: plugin1.config.version
},
[plugin2.config.id]: {
version: plugin2.config.version
}
}
}
}
Expand Down Expand Up @@ -242,8 +248,12 @@ describe('PluginModule', () => {
},
whitelisted: {
global: {
[plugin1.config.id]: plugin1.config.version,
[plugin2.config.id]: plugin2.config.version
[plugin1.config.id]: {
version: plugin1.config.version
},
[plugin2.config.id]: {
version: plugin2.config.version
}
}
}
}
Expand Down Expand Up @@ -282,8 +292,12 @@ describe('PluginModule', () => {
},
whitelisted: {
global: {
[plugin1.config.id]: plugin1.config.version,
[plugin2.config.id]: plugin2.config.version
[plugin1.config.id]: {
version: plugin1.config.version
},
[plugin2.config.id]: {
version: plugin2.config.version
}
}
}
}
Expand Down Expand Up @@ -626,7 +640,9 @@ describe('PluginModule', () => {
store.dispatch('plugin/setWhitelisted', {
scope: 'global',
plugins: {
[availablePlugins[0].config.id]: availablePlugins[0].config.version
[availablePlugins[0].config.id]: {
version: availablePlugins[0].config.version
}
}
})
})
Expand Down Expand Up @@ -656,6 +672,39 @@ describe('PluginModule', () => {
})
})

describe('isGrant', () => {
beforeAll(() => {
store.replaceState(JSON.parse(JSON.stringify(initialState)))

store.dispatch('plugin/setWhitelisted', {
scope: 'global',
plugins: {
[availablePlugins[0].config.id]: {
isGrant: true,
version: availablePlugins[0].config.version
},
[availablePlugins[1].config.id]: {
version: availablePlugins[1].config.version
}
}
})
})

it('should return true if the plugin is whitelisted and is a funded by ark grants', () => {
const pluginId = availablePlugins[0].config.id
expect(store.getters['plugin/isGrant'](pluginId)).toBe(true)
})

it('should return false if the plugin is whitelisted and is a not funded by ark grants', () => {
const pluginId = availablePlugins[1].config.id
expect(store.getters['plugin/isGrant'](pluginId)).toBe(false)
})

it('should return false if the plugin is not whitelisted and is a not funded by ark grants', () => {
expect(store.getters['plugin/isGrant']('plugin-not-grants')).toBe(false)
})
})

describe('isInstalledSupported', () => {
let spy

Expand All @@ -677,7 +726,7 @@ describe('PluginModule', () => {
store.dispatch('plugin/setInstalled', {
config: {
...installedPlugins[0].config,
minVersion: '1.0.0'
minimumVersion: '1.0.0'
}
})
expect(store.getters['plugin/isInstalledSupported'](installedPlugins[0].config.id)).toBe(true)
Expand All @@ -687,7 +736,7 @@ describe('PluginModule', () => {
store.dispatch('plugin/setInstalled', {
config: {
...installedPlugins[0].config,
minVersion: '3.0.0'
minimumVersion: '3.0.0'
}
})
expect(store.getters['plugin/isInstalledSupported'](installedPlugins[0].config.id)).toBe(false)
Expand Down
3 changes: 1 addition & 2 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ exports.MARKET = {

exports.PLUGINS = {
adapters: ['npm'],
blacklistUrl: 'https://raw.githubusercontent.com/ark-ecosystem-desktop-plugins/config/master/blacklist.json',
whitelistUrl: 'https://raw.githubusercontent.com/ark-ecosystem-desktop-plugins/config/master/whitelist.json',
pluginsUrl: 'https://raw.githubusercontent.com/ark-ecosystem-desktop-plugins/config/master/plugins.json',
categories: [
'gaming',
'theme',
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export default {
ipcRenderer.send('splashscreen:app-ready')
await Promise.all([this.$plugins.fetchPluginsFromAdapter(), this.$plugins.fetchBlacklist(), this.$plugins.fetchWhitelist()])
await Promise.all([this.$plugins.fetchPluginsFromAdapter(), this.$plugins.fetchPluginsList()])
},
__watchProfile () {
Expand Down
23 changes: 23 additions & 0 deletions src/renderer/assets/svg/ark-checkmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/renderer/assets/svg/ark-grants.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 19 additions & 3 deletions src/renderer/components/Plugin/PluginWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@ import { Wormhole } from 'portal-vue'
export default {
name: 'PluginWrapper',
computed: {
footerSlot () {
return this.$slots.footer
}
},
mounted () {
const footerSlot = this.$slots.footer
if (footerSlot) {
if (this.footerSlot) {
this.$nextTick(() => {
Wormhole.open({
to: 'plugin-footer',
from: 'plugin-wrapper',
passengers: footerSlot
passengers: this.footerSlot
})
})
}
},
beforeDestroy () {
if (this.footerSlot) {
this.$nextTick(() => {
Wormhole.close({
to: 'plugin-footer',
from: 'plugin-wrapper'
})
})
}
Expand Down
Loading

0 comments on commit 268a84b

Please sign in to comment.