diff --git a/resources/assets/src/js/__tests__/admin.test.js b/resources/assets/src/js/__tests__/admin.test.js index d59bbf11..22c1169e 100644 --- a/resources/assets/src/js/__tests__/admin.test.js +++ b/resources/assets/src/js/__tests__/admin.test.js @@ -418,6 +418,8 @@ describe('tests for "plugins" module', () => { }); describe('tests for "update" module', () => { + const modulePath = '../admin/update'; + it('download updates', async () => { const fetch = jest.fn() .mockReturnValueOnce(Promise.resolve({ @@ -441,7 +443,9 @@ describe('tests for "update" module', () => { `; - await require('../admin/update')(); + const downloadUpdates = require(modulePath).downloadUpdates; + + await downloadUpdates(); expect(fetch).toBeCalledWith(expect.objectContaining({ url: 'admin/update/download?action=prepare-download', type: 'GET', @@ -458,6 +462,39 @@ describe('tests for "update" module', () => { dataType: 'json' }); }); + + it('check for updates', async () => { + const fetch = jest.fn() + .mockReturnValueOnce(Promise.resolve({ + available: false, + latest: '1.1.4' + })) + .mockReturnValueOnce(Promise.resolve({ + available: true, + latest: '5.1.4' + })); + const url = jest.fn(path => path); + + window.fetch = fetch; + window.url = url; + + document.body.innerHTML = ` + Check Update + `; + + const checkForUpdates = require(modulePath).checkForUpdates; + + await checkForUpdates(); + expect($('#target').html()).toBe( + ' Check Update' + ); + + await checkForUpdates(); + expect($('#target').html()).toBe( + ' Check Update'+ + 'v5.1.4' + ); + }); }); describe('tests for "users" module', () => {