Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
refactor(toast): remove deprecated content() method and option and up…
Browse files Browse the repository at this point in the history
…dateContent() method

BREAKING CHANGE: The deprecated `content()` and `updateContent()` methods have been removed.

If you had:
```js
  $mdToast.show($mdToast.simple().content('This no longer works.'));
```
You will need to change to:
```js
  $mdToast.show($mdToast.simple().textContent('This works.'));
```

If you had:
```js
  $mdToast.updateContent('This no longer works.');
```
You will need to change to:
```js
  $mdToast.updateTextContent('This works.');
```

If you had:
```js
  $mdToast.show($mdToast.simple({parent: parent, content: 'This no longer works.', theme: 'some-theme', capsule: true}));
```
You will need to change to:
```js
  $mdToast.show($mdToast.simple({parent: parent, textContent: 'This works.', theme: 'some-theme', capsule: true}));
```
  • Loading branch information
Splaktar committed Jul 17, 2020
1 parent 4c75858 commit cf3d56c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 38 deletions.
11 changes: 3 additions & 8 deletions src/components/toast/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function MdToastProvider($$interimElementProvider) {
})
.addPreset('simple', {
argOption: 'textContent',
methods: ['textContent', 'content', 'action', 'actionKey', 'actionHint', 'highlightAction',
methods: ['textContent', 'action', 'actionKey', 'actionHint', 'highlightAction',
'highlightClass', 'theme', 'parent', 'dismissHint'],
options: /* @ngInject */ function($mdToast, $mdTheming) {
return {
Expand All @@ -363,10 +363,7 @@ function MdToastProvider($$interimElementProvider) {
};
}
})
.addMethod('updateTextContent', updateTextContent)
// updateContent is deprecated. Use updateTextContent instead.
// TODO remove this in 1.2.
.addMethod('updateContent', updateTextContent);
.addMethod('updateTextContent', updateTextContent);

function updateTextContent(newContent) {
activeToastContent = newContent;
Expand Down Expand Up @@ -466,9 +463,7 @@ function MdToastProvider($$interimElementProvider) {
* @return {*}
*/
function onShow(scope, element, options) {
// support deprecated #content method
// TODO remove support for content in 1.2.
activeToastContent = options.textContent || options.content;
activeToastContent = options.textContent;

var isSmScreen = !$mdMedia('gt-sm');

Expand Down
55 changes: 25 additions & 30 deletions src/components/toast/toast.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('$mdToast service', function() {
}));

function setup(options) {
var promise;
inject(function($mdToast, $material, $timeout) {
var promise = null;
inject(function($mdToast, $material) {
options = options || {};
promise = $mdToast.show(options);
$material.flushOutstandingAnimations();
Expand All @@ -26,15 +26,15 @@ describe('$mdToast service', function() {

describe('simple()', function() {

hasConfigMethods(['content', 'action', 'capsule', 'highlightAction', 'theme', 'toastClass']);
hasConfigMethods(['textContent', 'action', 'capsule', 'highlightAction', 'theme', 'toastClass']);

it('should have `._md` class indicator', inject(function($mdToast, $material) {
var parent = angular.element('<div>');

$mdToast.show(
$mdToast.simple({
parent: parent,
content: 'Do something',
textContent: 'Do something',
theme: 'some-theme',
capsule: true
}));
Expand All @@ -43,18 +43,18 @@ describe('$mdToast service', function() {
expect(parent.find('md-toast').hasClass('_md')).toBe(true);
}));

it('supports a basic toast', inject(function($mdToast, $rootScope, $timeout, $material, $browser) {
var openAndclosed = false;
it('supports a basic toast', inject(function($mdToast, $rootScope, $timeout, $material) {
var openAndClosed = false;
var parent = angular.element('<div>');
$mdToast.show(
$mdToast.simple({
parent: parent,
content: 'Do something',
textContent: 'Do something',
theme: 'some-theme',
capsule: true
})
).then(function() {
openAndclosed = true;
openAndClosed = true;
});

$material.flushOutstandingAnimations();
Expand All @@ -66,11 +66,10 @@ describe('$mdToast service', function() {

$material.flushInterimElement();

expect(openAndclosed).toBe(true);
expect(openAndClosed).toBe(true);
}));

it('supports dynamically updating the content', inject(function($mdToast, $rootScope, $rootElement) {
var parent = angular.element('<div>');
$mdToast.showSimple('Hello world');
$rootScope.$digest();
$mdToast.updateTextContent('Goodbye world');
Expand All @@ -83,7 +82,7 @@ describe('$mdToast service', function() {
var parent = angular.element('<div>');
$mdToast.show(
$mdToast.simple({
content: 'Do something',
textContent: 'Do something',
parent: parent
})
.action('Click me')
Expand All @@ -104,7 +103,7 @@ describe('$mdToast service', function() {

$mdToast.show(
$mdToast.simple({
content: 'Marked as read',
textContent: 'Marked as read',
parent: parent
})
.action('UNDO')
Expand Down Expand Up @@ -142,7 +141,7 @@ describe('$mdToast service', function() {
it('displays correctly', inject(function($mdToast, $rootScope) {
var parent = angular.element('<div>');
var toast = $mdToast.simple({
content: 'Do something',
textContent: 'Do something',
parent: parent
}).action('Click me');

Expand All @@ -160,7 +159,7 @@ describe('$mdToast service', function() {
it('displays correctly with parent()', inject(function($mdToast, $rootScope) {
var parent = angular.element('<div>');
var toast = $mdToast.simple({
content: 'Do something',
textContent: 'Do something',
})
.parent(parent)
.action('Click me');
Expand Down Expand Up @@ -334,7 +333,6 @@ describe('$mdToast service', function() {
it('after duration', inject(function($timeout, $animate, $rootElement) {
disableAnimations();

var parent = angular.element('<div>');
var hideDelay = 1234;
setup({
template: '<md-toast />',
Expand All @@ -348,7 +346,7 @@ describe('$mdToast service', function() {
it('and resolve with default `true`', inject(function($timeout, $material, $mdToast) {
disableAnimations();

var hideDelay = 1234, result, fault;
var result = null, fault = null;
setup({
template: '<md-toast />',
hideDelay: 1234
Expand All @@ -361,15 +359,14 @@ describe('$mdToast service', function() {

$material.flushInterimElement();

expect(result).toBe(undefined);
expect(angular.isUndefined(fault)).toBe(true);

expect(angular.isUndefined(result)).toBe(true);
expect(fault).toBe(null);
}));

it('and resolve with specified value', inject(function($timeout, $animate, $material, $mdToast) {
disableAnimations();

var hideDelay = 1234, result, fault;
var result = null, fault = null;
setup({
template: '<md-toast />',
hideDelay: 1234
Expand All @@ -383,14 +380,13 @@ describe('$mdToast service', function() {
$material.flushInterimElement();

expect(result).toBe("secret");
expect(angular.isUndefined(fault)).toBe(true);

expect(fault).toBe(null);
}));

it('and resolve `true` after timeout', inject(function($timeout, $material) {
disableAnimations();

var hideDelay = 1234, result, fault;
var result = null, fault = null;
setup({
template: '<md-toast />',
hideDelay: 1234
Expand All @@ -401,17 +397,16 @@ describe('$mdToast service', function() {

$material.flushInterimElement();

expect(result).toBe(undefined);
expect(angular.isUndefined(fault)).toBe(true);

expect(angular.isUndefined(result)).toBe(true);
expect(fault).toBe(null);
}));

it('and resolve `ok` with click on OK button', inject(function($mdToast, $rootScope, $timeout, $material, $browser) {
var result, fault;
it('and resolve `ok` with click on OK button', inject(function($mdToast, $rootScope, $timeout, $material) {
var result = null, fault = null;
var parent = angular.element('<div>');
var toast = $mdToast.simple({
parent: parent,
content: 'Do something'
textContent: 'Do something'
}).action('Close with "ok" response');

$mdToast
Expand All @@ -428,7 +423,7 @@ describe('$mdToast service', function() {
$material.flushInterimElement();

expect(result).toBe('ok');
expect(angular.isUndefined(fault)).toBe(true);
expect(fault).toBe(null);
}));
});

Expand Down

0 comments on commit cf3d56c

Please sign in to comment.