Upgrade sweetalert2 to v7

This commit is contained in:
Pig Fang 2018-07-31 10:19:51 +08:00
parent 8d23a14c79
commit 7206f5952b
4 changed files with 38 additions and 39 deletions

View File

@ -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",

View File

@ -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;
}

View File

@ -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() {},

View File

@ -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"