diff --git a/resources/assets/src/js/__tests__/admin.test.js b/resources/assets/src/js/__tests__/admin.test.js index d89c31a7..a425cbe1 100644 --- a/resources/assets/src/js/__tests__/admin.test.js +++ b/resources/assets/src/js/__tests__/admin.test.js @@ -302,6 +302,42 @@ describe('tests for "players" module', () => { expect(showAjaxError).toBeCalled(); }); + it('show nickname in swal', async () => { + const fetch = jest.fn() + .mockReturnValueOnce(Promise.resolve({ user: { nickname: 'name' } })) + .mockReturnValueOnce(Promise.reject()); + const url = jest.fn(path => path); + const trans = jest.fn(key => key); + window.fetch = fetch; + window.url = url; + window.trans = trans; + + document.body.innerHTML = ` + +
+ `; + const { showNicknameInSwal } = require(modulePath); + + await showNicknameInSwal(); + expect(fetch).not.toBeCalled(); + + $('input').val('-8'); + await showNicknameInSwal(); + expect(fetch).not.toBeCalled(); + + $('input').val('8'); + await showNicknameInSwal(); + expect(fetch).toBeCalledWith({ + type: 'GET', + url: 'admin/user/8', + dataType: 'json' + }); + expect($('div').html().includes('name')); + + await showNicknameInSwal(); + expect($('div').html().includes('admin.noSuchUser')); + }); + it('delete player', async () => { const fetch = jest.fn() .mockReturnValueOnce(Promise.resolve({ errno: 0, msg: 'success' })) @@ -506,10 +542,13 @@ describe('tests for "update" module', () => { it('download updates', async () => { const fetch = jest.fn() - .mockReturnValueOnce(Promise.resolve({ - file_size: 5000 - })) - .mockReturnValueOnce(Promise.resolve()); + .mockImplementationOnce(({ beforeSend }) => { + beforeSend && beforeSend(); + return Promise.resolve({ + file_size: 5000 + }); + }) + .mockImplementationOnce(() => Promise.resolve()); const url = jest.fn(path => path); const toastr = { success: jest.fn(), @@ -525,6 +564,7 @@ describe('tests for "update" module', () => { document.body.innerHTML = ` + `; const downloadUpdates = require(modulePath).downloadUpdates; @@ -535,6 +575,7 @@ describe('tests for "update" module', () => { type: 'GET', dataType: 'json', })); + expect($('#update-button').prop('disabled')).toBe(true); expect($('#file-size').html()).toBe('5000'); expect(modal).toBeCalledWith({ backdrop: 'static', @@ -1048,7 +1089,7 @@ describe('tests for "common" module', () => { version: '8.1.0' }; - const sendFeedback = require(modulePath); + const { sendFeedback } = require(modulePath); await sendFeedback(); expect(fetch).toBeCalledWith({ @@ -1064,4 +1105,27 @@ describe('tests for "common" module', () => { expect(fetch).toHaveBeenCalledTimes(1); expect(console.log).toHaveBeenCalledTimes(1); }); + + it('initialize data tables', () => { + $.fn.dataTable = { defaults: {} }; + const initUsersTable = jest.fn(); + const initPlayersTable = jest.fn(); + const initPluginsTable = jest.fn(); + window.initUsersTable = initUsersTable; + window.initPlayersTable = initPlayersTable; + window.initPluginsTable = initPluginsTable; + const { initTables } = require(modulePath); + + document.body.innerHTML = ''; + initTables(); + expect(initUsersTable).toBeCalled(); + + document.body.innerHTML = ''; + initTables(); + expect(initPlayersTable).toBeCalled(); + + document.body.innerHTML = ''; + initTables(); + expect($.pluginsTable).not.toBeNull(); + }); }); diff --git a/resources/assets/src/js/__tests__/common.test.js b/resources/assets/src/js/__tests__/common.test.js index c9a93da1..1b5b2d79 100644 --- a/resources/assets/src/js/__tests__/common.test.js +++ b/resources/assets/src/js/__tests__/common.test.js @@ -192,6 +192,135 @@ describe('tests for "polyfill" module', () => { }); }); +describe('tests for "texture-preview" module', () => { + const TexturePreview = require('../common/texture-preview'); + + it('change 2d preview', () => { + const url = jest.fn(path => path); + window.url = url; + + document.body.innerHTML = ` +