-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as dom from '../../src/utils/dom/index' | ||
import { warn } from '../../src/utils/utils' | ||
import sweetAlert from '../sweetalert2' | ||
import privateProps from '../privateProps' | ||
|
||
/** | ||
* Updates popup options. | ||
*/ | ||
export function update (params) { | ||
const validUpdatableParams = {} | ||
|
||
// assign valid params from `params` to `defaults` | ||
Object.keys(params).forEach(param => { | ||
if (sweetAlert.isUpdatableParameter(param)) { | ||
validUpdatableParams[param] = params[param] | ||
} else { | ||
warn(`Invalid parameter to update: "${param}". Updatable params are listed here: TODO (@limonte) add link`) | ||
} | ||
}) | ||
|
||
const innerParams = privateProps.innerParams.get(this) | ||
const updatedParams = Object.assign({}, innerParams, validUpdatableParams) | ||
|
||
// Actions | ||
dom.renderActions(updatedParams) | ||
|
||
// Content | ||
dom.renderContent(updatedParams) | ||
|
||
// Icon | ||
dom.renderIcon(updatedParams) | ||
|
||
// Image | ||
dom.renderImage(updatedParams) | ||
|
||
// Progress steps | ||
dom.renderProgressSteps(updatedParams) | ||
|
||
// Title | ||
dom.renderTitle(updatedParams) | ||
|
||
|
||
privateProps.innerParams.set(this, updatedParams) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { Swal, SwalWithoutAnimation, isVisible } = require('../helpers') | ||
|
||
QUnit.test('update() method', (assert) => { | ||
SwalWithoutAnimation.fire() | ||
|
||
Swal.update({ | ||
title: 'New title', | ||
html: 'New content', | ||
type: 'success', | ||
showConfirmButton: false, | ||
showCancelButton: true, | ||
cancelButtonText: 'New cancel button text', | ||
imageUrl: '/assets/swal2-logo.png' | ||
}) | ||
|
||
assert.equal(Swal.getTitle().textContent, 'New title') | ||
assert.equal(Swal.getContent().textContent, 'New content') | ||
|
||
assert.ok(isVisible(Swal.getIcons().filter(icon => icon.classList.contains('swal2-success'))[0])) | ||
|
||
assert.ok(isVisible(Swal.getImage())) | ||
assert.ok(Swal.getImage().src.indexOf('/assets/swal2-logo.png') > 0) | ||
|
||
assert.notOk(isVisible(Swal.getConfirmButton())) | ||
assert.ok(isVisible(Swal.getCancelButton())) | ||
assert.equal(Swal.getCancelButton().textContent, 'New cancel button text') | ||
}) | ||
|
||
QUnit.test('isUpdatableParameter() method', (assert) => { | ||
assert.ok(Swal.isUpdatableParameter('title')) | ||
assert.notOk(Swal.isUpdatableParameter('preConfirm')) | ||
}) |