uppy/packages/@uppy/dashboard/src/index.test.js
Artur Paikin 4e54483e61 core: setOptions for Core and plugins (#1728)
* Add a method to update options in Core

* Add a method to update options in Plugin (for any plugins)

* Allow re-initializing i18n locales after they’ve been updated with .setOptions

* use rest spread instead of Object.assign

* override setOptions in plugins to include i18nInit

* merge restrictions object in setOptions

* check that newOpts exists

* add spread ...

* don’t double merge

* add i18nInit to all plugins that use translation strings

* add setOptions tests to Core and Dashboard

* add setOptions docs for Core and Plugins

* fix tests for thumbnail-generator by adding plugins: {} to mock core

cause ThumbnailGenerator now calls this.setPluginState, which expects `core.state.plugins`

* also update meta with setOptions if it’s passed, change the way this.opts is set in core

@goto-bus-stop does this look ok? merging restrictions opts in core

* if locale was passed to setOptions(), call plugin.setOptions() on all plugins, so that i18n updates

* add Dashboard test that checks if locale is updated from Core via setOptions()

* Reafactor website Dashboard example to use setOptions and allow selecting a locale

🎉
2019-11-04 10:33:30 +01:00

94 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const Core = require('@uppy/core')
const DashboardPlugin = require('./index')
const StatusBarPlugin = require('@uppy/status-bar')
const GoogleDrivePlugin = require('@uppy/google-drive')
describe('Dashboard', () => {
it('can safely be added together with the StatusBar without id conflicts', () => {
const core = new Core()
core.use(StatusBarPlugin)
expect(() => {
core.use(DashboardPlugin, { inline: false })
}).not.toThrow()
core.close()
})
it('works without any remote provider plugins', () => {
const core = new Core()
expect(() => {
core.use(DashboardPlugin, {
inline: true,
target: 'body'
})
}).not.toThrow()
core.close()
})
it('works when targeting remote provider plugins using `target`', () => {
const core = new Core()
expect(() => {
core.use(DashboardPlugin, {
inline: true,
target: 'body'
})
core.use(GoogleDrivePlugin, { target: DashboardPlugin, companionUrl: 'https://fake.uppy.io/' })
}).not.toThrow()
core.close()
})
it('works when passing plugins in `plugins` array', () => {
const core = new Core()
core.use(GoogleDrivePlugin, { companionUrl: 'https://fake.uppy.io/' })
expect(() => {
core.use(DashboardPlugin, {
inline: true,
target: 'body',
plugins: ['GoogleDrive']
})
}).not.toThrow()
core.close()
})
it('should change options on the fly', () => {
const core = new Core()
core.use(DashboardPlugin, {
inline: true,
target: 'body'
})
core.getPlugin('Dashboard').setOptions({
width: 300
})
expect(
core.getPlugin('Dashboard').opts.width
).toEqual(300)
})
it('should use updated locale from Core, when its set via Cores setOptions()', () => {
const core = new Core()
core.use(DashboardPlugin, {
inline: true,
target: 'body'
})
core.setOptions({
locale: {
strings: {
myDevice: 'Май дивайс'
}
}
})
expect(
core.getPlugin('Dashboard').i18n('myDevice')
).toEqual('Май дивайс')
})
})