Retrieve plugin dependencies from datatable
This commit is contained in:
parent
70d59642b1
commit
9400d6f7c1
|
|
@ -71,9 +71,6 @@ class PluginController extends Controller
|
|||
|
||||
return json(trans('admin.plugins.operations.enabled', ['plugin' => $plugin->title]), 0);
|
||||
|
||||
case 'requirements':
|
||||
return json($this->getPluginDependencies($plugin));
|
||||
|
||||
case 'disable':
|
||||
$plugins->disable($name);
|
||||
|
||||
|
|
|
|||
|
|
@ -407,16 +407,18 @@ describe('tests for "plugins" module', () => {
|
|||
|
||||
it('enable a plugin', async () => {
|
||||
const fetch = jest.fn()
|
||||
.mockReturnValueOnce(Promise.resolve({ requirements: [] }))
|
||||
.mockReturnValueOnce(Promise.resolve({ requirements: [] }))
|
||||
.mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success' }))
|
||||
.mockReturnValueOnce(Promise.resolve({
|
||||
isRequirementsSatisfied: false,
|
||||
requirements: { 'a': '^1.1.0', 'b': '^2.1.0', 'c': '^3.3.0' },
|
||||
unsatisfiedRequirements: { 'c': '^3.3.0' }
|
||||
}))
|
||||
.mockReturnValueOnce(Promise.resolve({ errno: 1, msg: 'notice', reason: ['reason1', 'reason2'] }))
|
||||
.mockReturnValueOnce(Promise.reject());
|
||||
const getPluginDependencies = jest.fn()
|
||||
.mockReturnValueOnce({ dependencies: { requirements: [] } })
|
||||
.mockReturnValue({
|
||||
dependencies: {
|
||||
isRequirementsSatisfied: false,
|
||||
requirements: { 'a': '^1.1.0', 'b': '^2.1.0', 'c': '^3.3.0' },
|
||||
unsatisfiedRequirements: { 'c': '^3.3.0' }
|
||||
}
|
||||
});
|
||||
const url = jest.fn(path => path);
|
||||
const swal = jest.fn()
|
||||
.mockReturnValueOnce(Promise.reject())
|
||||
|
|
@ -435,23 +437,22 @@ describe('tests for "plugins" module', () => {
|
|||
$.pluginsTable = {
|
||||
ajax: {
|
||||
reload: reloadTable
|
||||
}
|
||||
},
|
||||
row: () => ({
|
||||
data: getPluginDependencies
|
||||
})
|
||||
};
|
||||
|
||||
const enablePlugin = require(modulePath).enablePlugin;
|
||||
|
||||
await enablePlugin('plugin');
|
||||
expect(fetch).toBeCalledWith({
|
||||
type: 'POST',
|
||||
url: 'admin/plugins/manage?action=requirements&name=plugin',
|
||||
dataType: 'json'
|
||||
});
|
||||
expect(getPluginDependencies).toBeCalled();
|
||||
expect(swal).toBeCalledWith({
|
||||
text: 'admin.noDependenciesNotice',
|
||||
type: 'warning',
|
||||
showCancelButton: true
|
||||
});
|
||||
expect(fetch.mock.calls.length).toBe(1);
|
||||
expect(fetch).not.toBeCalled();
|
||||
|
||||
await enablePlugin('plugin');
|
||||
expect(fetch).toBeCalledWith({
|
||||
|
|
|
|||
|
|
@ -82,12 +82,10 @@ const pluginsTableColumnDefs = [
|
|||
];
|
||||
|
||||
async function enablePlugin(name) {
|
||||
const dataTable = $.pluginsTable || $.marketTable;
|
||||
|
||||
try {
|
||||
const { requirements } = await fetch({
|
||||
type: 'POST',
|
||||
url: url(`admin/plugins/manage?action=requirements&name=${name}`),
|
||||
dataType: 'json'
|
||||
});
|
||||
const { requirements } = dataTable.row(`#plugin-${name}`).data().dependencies;
|
||||
|
||||
if (requirements.length === 0) {
|
||||
await swal({
|
||||
|
|
@ -106,7 +104,7 @@ async function enablePlugin(name) {
|
|||
if (errno === 0) {
|
||||
toastr.success(msg);
|
||||
|
||||
$.pluginsTable.ajax.reload(null, false);
|
||||
dataTable.ajax.reload(null, false);
|
||||
} else {
|
||||
swal({ type: 'warning', html: `<p>${msg}</p><ul><li>${reason.join('</li><li>')}</li></ul>` });
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user