-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
7617742
commit d947c55
Showing
14 changed files
with
187 additions
and
42 deletions.
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 was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
WebApplication1/WebApplication1/Jasmine/spec/ComponentExampleControllerSpec.js
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 @@ | ||
/// <reference path="_tests_references.js"/> | ||
|
||
describe("controller: componentExampleController", function () { | ||
var model = { | ||
players: [ | ||
{ Name: "Player1", Age: 20, Hits: 0 }, | ||
{ Name: "Player2", Age: 30, Hits: 0 } | ||
] | ||
}; | ||
|
||
beforeEach(function() { | ||
module("myApp"); | ||
|
||
module(function ($provide) { | ||
$provide.factory("dataService", function () { | ||
var data = model; | ||
return data; | ||
}); | ||
}); | ||
}); | ||
|
||
beforeEach(inject(function ($controller, $rootScope) { | ||
this.scope = $rootScope.$new(); | ||
$controller("componentExampleController", { | ||
$scope: this.scope | ||
}); | ||
})); | ||
|
||
describe("check componentExampleController", function () { | ||
it("should contain players", function () { | ||
expect(this.scope.model).toEqual(model); | ||
}); | ||
|
||
it("should hit player", function () { | ||
var player = { Name: "PlayerX", Age: 1, Hits: 0 }; | ||
|
||
this.scope.hitFn(player); | ||
expect(player.Hits).toBe(1); | ||
|
||
this.scope.hitFn(player); | ||
expect(player.Hits).toBe(2); | ||
}); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
WebApplication1/WebApplication1/Jasmine/spec/ComponentExamplePlayerSpec.js
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,43 @@ | ||
/// <reference path="_tests_references.js"/> | ||
|
||
describe("module: componentExamplePlayer", function () { | ||
beforeEach(function() { | ||
module("myApp"); | ||
}); | ||
|
||
beforeEach(inject(function ($controller, $rootScope) { | ||
this.scope = $rootScope.$new(); | ||
$controller("componentExampleController", { | ||
$scope: this.scope | ||
}); | ||
spyOn(this.scope, "hitFn"); | ||
})); | ||
|
||
beforeEach(inject(function ($compile) { | ||
this.scope.myPlayer = { Name: "Player1", Age: 20, Hits: 0 }; | ||
|
||
this.element = | ||
"<div class=\"playerDirective\" player=\"myPlayer\" hit=\"hitFn(player)\">" + | ||
"<h4>Player Info</h4>" + | ||
"<p>Name: {{player.Name}}</p>" + | ||
"<p>Age: {{player.Age}}</p>" + | ||
"<p>Hits: {{player.Hits}}</p>" + | ||
"<button ng-click=\"hit({player: player})\">Hit {{player.Name}}</button>" + | ||
"</div>"; | ||
this.element = $compile(this.element)(this.scope); | ||
this.scope.$digest(); | ||
})); | ||
|
||
describe("check componentExampleController", function () { | ||
it("should contain myPlayer", function () { | ||
var isolated = this.element.isolateScope(); | ||
expect(isolated.player).toEqual(this.scope.myPlayer); | ||
}); | ||
|
||
it("should hit myPlayer", function () { | ||
var isolated = this.element.isolateScope(); | ||
isolated.hit({player: isolated.player}); | ||
expect(this.scope.hitFn).toHaveBeenCalledWith(isolated.player); | ||
}); | ||
}); | ||
}); |
9 changes: 2 additions & 7 deletions
9
WebApplication1/WebApplication1/Jasmine/spec/SimpleControllerSpec.js
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
7 changes: 1 addition & 6 deletions
7
WebApplication1/WebApplication1/Jasmine/spec/SubControllerSpec.js
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
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions
18
WebApplication1/WebApplication1/Views/Home/ComponentExample.cshtml
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,18 @@ | ||
@{ | ||
ViewBag.Title = "Component Example"; | ||
} | ||
|
||
<h3>@ViewBag.Title</h3> | ||
|
||
<br/> | ||
|
||
<div ng-controller="componentExampleController"> | ||
<div class="playerDirective" ng-repeat="myPlayer in model.players" player="myPlayer" hit="hitFn(player)"> | ||
<h4>Player Info</h4> | ||
<p>Name: {{player.Name}}</p> | ||
<p>Age: {{player.Age}}</p> | ||
<p>Hits: {{player.Hits}}</p> | ||
|
||
<button ng-click="hit({player: player})">Hit {{player.Name}}</button> | ||
</div> | ||
</div> |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
(function () { | ||
"use strict"; | ||
|
||
angular.module("myApp", []); | ||
angular.module("myApp", ["myApp.player"]); | ||
})(); |
32 changes: 32 additions & 0 deletions
32
WebApplication1/WebApplication1/dist/ComponentExamplePlayerModule.js
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 @@ | ||
(function () { | ||
"use strict"; | ||
|
||
function playerDirective() { | ||
function linkFn(scope, element, attrs, ctrls, transclude) { | ||
transclude(scope, function (clone) { | ||
element.append(clone); | ||
}); | ||
} | ||
|
||
function controllerFn($scope) { | ||
$scope.defaultAttribute = $scope.defaultAttribute || "defaultAttributeValue"; | ||
} | ||
controllerFn.$inject = ["$scope"]; | ||
|
||
return { | ||
restrict: "C", | ||
scope: { | ||
player: "=", | ||
defaultAttribute: "=", | ||
undefinedAttribute: "=", | ||
hit: "&" | ||
}, | ||
transclude: true, | ||
link: linkFn, | ||
controller: controllerFn | ||
}; | ||
} | ||
|
||
angular.module("myApp.player", []) | ||
.directive("playerDirective", playerDirective); | ||
})(); |
34 changes: 34 additions & 0 deletions
34
WebApplication1/WebApplication1/dist/ComponentExampleView.js
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,34 @@ | ||
(function () { | ||
"use strict"; | ||
|
||
function dataService() { | ||
var data = { | ||
players: [ | ||
{ | ||
Name: "Player1", | ||
Age: 20, | ||
Hits: 0 | ||
}, | ||
{ | ||
Name: "Player2", | ||
Age: 30, | ||
Hits: 0 | ||
} | ||
] | ||
}; | ||
return data; | ||
} | ||
|
||
function componentExampleController($scope, dataService) { | ||
$scope.model = dataService; | ||
|
||
$scope.hitFn = function (player) { | ||
player.Hits++; | ||
}; | ||
} | ||
componentExampleController.$inject = ["$scope", "dataService"]; | ||
|
||
angular.module("myApp") | ||
.controller("componentExampleController", componentExampleController) | ||
.factory("dataService", dataService); | ||
})(); |