From 7206f5952b6f50e234982be0848bdb0d5398d686 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Tue, 31 Jul 2018 10:19:51 +0800 Subject: [PATCH] Upgrade sweetalert2 to v7 --- package.json | 2 +- .../assets/src/components/user/ClosetItem.vue | 51 +++++++++---------- .../tests/components/user/ClosetItem.test.js | 18 ++++--- yarn.lock | 6 +-- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index a46868bc..98a969e7 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "jquery": "^3.3.1", "lodash.debounce": "^4.0.8", "skinview3d": "^1.1.0-alpha.4", - "sweetalert2": "^6.11.5", + "sweetalert2": "^7.26.9", "toastr": "^2.1.4", "typeface-minecraft": "^1.0.0", "typeface-ubuntu": "^0.0.54", diff --git a/resources/assets/src/components/user/ClosetItem.vue b/resources/assets/src/components/user/ClosetItem.vue index be29750d..391fc652 100644 --- a/resources/assets/src/components/user/ClosetItem.vue +++ b/resources/assets/src/components/user/ClosetItem.vue @@ -57,19 +57,16 @@ export default { }, methods: { async rename() { - let newTextureName = ''; - - try { - newTextureName = await swal({ - title: this.$t('user.renameClosetItem'), - input: 'text', - inputValue: this.textureName, - showCancelButton: true, - inputValidator: value => (new Promise((resolve, reject) => { - value ? resolve() : reject(this.$t('skinlib.emptyNewTextureName')); - })) - }); - } catch { + const { value: newTextureName, dismiss } = await swal({ + title: this.$t('user.renameClosetItem'), + input: 'text', + inputValue: this.textureName, + showCancelButton: true, + inputValidator: value => (new Promise(resolve => { + value ? resolve() : resolve(this.$t('skinlib.emptyNewTextureName')); + })) + }); + if (dismiss) { return; } @@ -86,13 +83,12 @@ export default { } }, async remove() { - try { - await swal({ - text: this.$t('user.removeFromClosetNotice'), - type: 'warning', - showCancelButton: true - }); - } catch { + const { dismiss } = await swal({ + text: this.$t('user.removeFromClosetNotice'), + type: 'warning', + showCancelButton: true + }); + if (dismiss) { return; } @@ -109,14 +105,13 @@ export default { } }, async setAsAvatar() { - try { - await swal({ - title: this.$t('user.setAvatar'), - text: this.$t('user.setAvatarNotice'), - type: 'question', - showCancelButton: true - }); - } catch { + const { dismiss } = await swal({ + title: this.$t('user.setAvatar'), + text: this.$t('user.setAvatarNotice'), + type: 'question', + showCancelButton: true + }); + if (dismiss) { return; } diff --git a/resources/assets/tests/components/user/ClosetItem.test.js b/resources/assets/tests/components/user/ClosetItem.test.js index 024af220..9987d5bc 100644 --- a/resources/assets/tests/components/user/ClosetItem.test.js +++ b/resources/assets/tests/components/user/ClosetItem.test.js @@ -45,12 +45,12 @@ test('rename texture', async () => { axios.post .mockResolvedValueOnce({ data: { errno: 0 } }) .mockResolvedValueOnce({ data: { errno: 1 } }); - swal.mockImplementationOnce(() => Promise.reject()) + swal.mockImplementationOnce(() => Promise.resolve({ dismiss: 'cancel' })) .mockImplementation(async options => { - options.inputValidator('name'); - options.inputValidator().catch(() => {}); - return 'new-name'; - }); + options.inputValidator('name'); + options.inputValidator().catch(() => {}); + return { value: 'new-name' }; + }); const wrapper = mount(ClosetItem, { propsData: factory() }); const button = wrapper.findAll('.dropdown-menu > li').at(0).find('a'); @@ -76,7 +76,9 @@ test('remove texture', async () => { axios.post .mockResolvedValueOnce({ data: { errno: 0 } }) .mockResolvedValueOnce({ data: { errno: 1 } }); - swal.mockRejectedValueOnce().mockResolvedValue(); + swal + .mockResolvedValueOnce({ dismiss: 'cancel' }) + .mockResolvedValue({}); const wrapper = mount(ClosetItem, { propsData: factory() }); const button = wrapper.findAll('.dropdown-menu > li').at(1).find('a'); @@ -100,7 +102,9 @@ test('set as avatar', async () => { axios.post .mockResolvedValueOnce({ data: { errno: 0 } }) .mockResolvedValueOnce({ data: { errno: 1 } }); - swal.mockRejectedValueOnce().mockResolvedValue(); + swal + .mockResolvedValueOnce({ dismiss: 'cancel' }) + .mockResolvedValue({}); window.$ = jest.fn(() => ({ each(fn) { fn(); }, prop() {}, diff --git a/yarn.lock b/yarn.lock index 387ee42a..dfdfa242 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7038,9 +7038,9 @@ svgo@^1.0.0: unquote "~1.1.1" util.promisify "~1.0.0" -sweetalert2@^6.11.5: - version "6.11.5" - resolved "https://registry.yarnpkg.com/sweetalert2/-/sweetalert2-6.11.5.tgz#a1ede34089225eb864898f4b613db4fec5dbe334" +sweetalert2@^7.26.9: + version "7.26.9" + resolved "https://registry.yarnpkg.com/sweetalert2/-/sweetalert2-7.26.9.tgz#d5e55f4e647c9feb7dd17dca470e482ca899bfe6" symbol-observable@1.0.1: version "1.0.1"