This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat(modal): add component support #6179
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -131,6 +131,16 @@ describe('$uibModal', function() { | |
elem.focus(); | ||
} | ||
}; | ||
}).component('fooBar', { | ||
bindings: { | ||
resolve: '<', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to mention in the docs that this and the modal instance are one-way bound? realizing that it doesn't apply to object contents... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gah, nm. i just realized this was a test... |
||
modalInstance: '<', | ||
close: '&', | ||
dismiss: '&' | ||
}, | ||
controller: angular.noop, | ||
controllerAs: 'foobar', | ||
template: '<div>Foo Bar</div>' | ||
}); | ||
})); | ||
|
||
|
@@ -930,16 +940,89 @@ describe('$uibModal', function() { | |
}); | ||
}); | ||
|
||
describe('option by option', function () { | ||
describe('template and templateUrl', function () { | ||
it('should throw an error if none of template and templateUrl are provided', function() { | ||
describe('option by option', function() { | ||
describe('component', function() { | ||
function getModalComponent($document) { | ||
return $document.find('body > div.modal > div.modal-dialog > div.modal-content foo-bar'); | ||
} | ||
|
||
it('should use as modal content', function() { | ||
open({ | ||
component: 'fooBar' | ||
}); | ||
|
||
var component = getModalComponent($document); | ||
expect(component.html()).toBe('<div>Foo Bar</div>'); | ||
}); | ||
|
||
it('should bind expected values', function() { | ||
var modal = open({ | ||
component: 'fooBar', | ||
resolve: { | ||
foo: function() { | ||
return 'bar'; | ||
} | ||
} | ||
}); | ||
|
||
var component = getModalComponent($document); | ||
var componentScope = component.isolateScope(); | ||
|
||
expect(componentScope.foobar.resolve.foo).toBe('bar'); | ||
expect(componentScope.foobar.modalInstance).toBe(modal); | ||
expect(componentScope.foobar.close).toEqual(jasmine.any(Function)); | ||
expect(componentScope.foobar.dismiss).toEqual(jasmine.any(Function)); | ||
}); | ||
|
||
it('should close the modal', function() { | ||
var modal = open({ | ||
component: 'fooBar', | ||
resolve: { | ||
foo: function() { | ||
return 'bar'; | ||
} | ||
} | ||
}); | ||
|
||
var component = getModalComponent($document); | ||
var componentScope = component.isolateScope(); | ||
|
||
componentScope.foobar.close({ | ||
$value: 'baz' | ||
}); | ||
|
||
expect(modal.result).toBeResolvedWith('baz'); | ||
}); | ||
|
||
it('should dismiss the modal', function() { | ||
var modal = open({ | ||
component: 'fooBar', | ||
resolve: { | ||
foo: function() { | ||
return 'bar'; | ||
} | ||
} | ||
}); | ||
|
||
var component = getModalComponent($document); | ||
var componentScope = component.isolateScope(); | ||
|
||
componentScope.foobar.dismiss({ | ||
$value: 'baz' | ||
}); | ||
|
||
expect(modal.result).toBeRejectedWith('baz'); | ||
}); | ||
}); | ||
|
||
describe('template and templateUrl', function() { | ||
it('should throw an error if none of component, template and templateUrl are provided', function() { | ||
expect(function(){ | ||
var modal = open({}); | ||
}).toThrow(new Error('One of template or templateUrl options is required.')); | ||
}).toThrow(new Error('One of component or template or templateUrl options is required.')); | ||
}); | ||
|
||
it('should not fail if a templateUrl contains leading / trailing white spaces', function() { | ||
|
||
$templateCache.put('whitespace.html', ' <div>Whitespaces</div> '); | ||
open({templateUrl: 'whitespace.html'}); | ||
expect($document).toHaveModalOpenWithContent('Whitespaces', 'div'); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this implies that this is a BC, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a completely new option - it isn't supported currently, so it isn't a BC at all.