diff --git a/.gitignore b/.gitignore index 636191d..3980dc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ +dist/ Thumbs.db ehthumbs.db diff --git a/Angular.WinJS.nuspec b/Angular.WinJS.nuspec index c2b661f..7be6529 100644 --- a/Angular.WinJS.nuspec +++ b/Angular.WinJS.nuspec @@ -2,7 +2,7 @@ Angular.WinJS - 3.0.0 + 1.0.0 Microsoft Corporation and other contributors https://raw.githubusercontent.com/winjs/angular-winjs/master/License.txt https://github.com/winjs/angular-winjs diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..93980aa --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,198 @@ +// Copyright (c) Microsoft Corp. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. + +"use strict"; + +var exec = require('child_process').exec; +var execSync = require('child_process').execSync; + +module.exports = function(grunt) { + + var publishRoot = 'dist/'; + var npmPublishRoot = publishRoot + 'npm/'; + + // All version number information is derived from package.json. This includes the version + // info used with npm, bower, NuGet, and the GitHub release. + var pkg = grunt.file.readJSON('package.json'); + var fullWinjsVersion = pkg.devDependencies.winjs; + if (!fullWinjsVersion) { + grunt.fail.fatal('Unable to determine WinJS version required by angular-winjs'); + } + // package.json version contains ... We just want . + var winjsVersion = fullWinjsVersion.split(".").slice(0, 2).join("."); + + var currentGitCommitHash = execSync('git rev-parse HEAD').toString().trim(); + + var bomGlob = "**/*.+(js|css|htm|html)"; + + // Project configuration. + grunt.initConfig({ + pkg: pkg, + + clean: { + publish: [publishRoot] + }, + + copy: { + publish: { + files: [{ + expand: true, + src: [ + 'js/**', + 'License.txt', + 'package.json', + 'README.md' + ], + dest: npmPublishRoot + }] + } + }, + + compress: { + publish: { + options: { + archive: publishRoot + 'angular-winjs.zip' + }, + files: [{ + expand: true, + cwd: npmPublishRoot, + src: ["**"] + }] + } + }, + + "check-bom": { + publish: { + files: [{ + cwd: 'js', + src: bomGlob, + expand: true, + nocase: true + }, { + cwd: publishRoot, + src: bomGlob, + expand: true, + nocase: true + }] + } + }, + + nugetpack: { + publish: { + src: 'Angular.WinJS.nuspec', + dest: publishRoot, + options: { + version: '<%= pkg.version %>' + } + } + }, + + // Publishes nuget package + nugetpush: { + // Requires NuGet API key to be set. You can do this with: + // grunt nugetkey --key=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX + publish: { + src: publishRoot + '*.nupkg', + } + }, + + // Publishes GitHub release and bower package (bower consumes GitHub tags/releases) + 'github-release': { + // Requires this environment variable to be set: GITHUB_ACCESS_TOKEN + // GITHUB_ACCESS_TOKEN can be generated from https://help.github.com/articles/creating-an-access-token-for-command-line-use/ + publish: { + options: { + repository: 'winjs/angular-winjs', + auth: { + user: process.env.GITHUB_ACCESS_TOKEN + }, + release: { + tag_name: 'v<%= pkg.version %>', // Must follow semver syntax in order for bower to pick it up + target_commitish: currentGitCommitHash, + name: '<%= pkg.version %>', + body: + 'Release of angular-winjs <%= pkg.version %>.\n' + + '\n' + + 'Compatible with WinJS ' + winjsVersion + '.\n' + } + }, + files: { + src: [publishRoot + 'angular-winjs.zip'] + } + } + } + }); + + grunt.loadTasks('tasks/'); + + var plugins = [ + 'grunt-contrib-clean', + 'grunt-contrib-compress', + 'grunt-contrib-copy', + 'grunt-nuget', + 'grunt-github-releaser' + ]; + plugins.forEach(function (plugin) { + grunt.loadNpmTasks(plugin); + }); + + // Publishes npm package + grunt.registerTask('npm-release', function (mode) { + var done = this.async(); + var cmd = 'npm publish ' + npmPublishRoot; + + exec(cmd, function (err, stdout) { + if (err) { + grunt.fatal('npm publish failed using command: ' + cmd); + } + done(); + }); + }); + + // Sets up all of the state necessary to do a publish but doesn't actually publish + // to any of the package managers. + grunt.registerTask('prepare-publish', [ + 'clean:publish', + 'copy:publish', + 'compress:publish', + 'nugetpack:publish', + 'check-bom:publish', + ]); + + grunt.registerTask('finished-publish', function (mode) { + grunt.log.writeln(''); + grunt.log.writeln('Publish complete. Hand tweak the GitHub release description if necessary (https://github.com/winjs/angular-winjs/releases)'); + grunt.log.writeln(''); + }); + + // + // Public tasks designed to be run from the command line + // + + // Populates the 'dist' folder and then uses it to: + // - Create a GitHub release + // - Publish to npm + // - Publish to bower + // - Publish to NuGet + // When debugging publish, it's helpful to run just the 'prepare-publish' + // task which puts all of the publication data into the 'dist' folder but + // doesn't actually send the data to the package managers. + grunt.registerTask('publish', function (mode) { + if (!mode) { + grunt.log.writeln(''); + grunt.log.writeln('Will publish version ' + pkg.version + ' of angular-winjs to npm, NuGet, etc. Double check that:'); + grunt.log.writeln(' * You are on the branch you\'d like to publish'); + grunt.log.writeln(' * The branch has been pushed to GitHub'); + grunt.log.writeln(' * You don\'t have any local edits'); + grunt.log.writeln(''); + grunt.log.writeln('If everything is in order, run "grunt publish:force" to proceed'); + } else if (mode === 'force') { + grunt.task.run([ + 'prepare-publish', + 'nugetpush:publish', + 'github-release:publish', + 'npm-release', + 'finished-publish', + ]); + } + }); +}; diff --git a/README.md b/README.md index e4156bb..730b370 100644 --- a/README.md +++ b/README.md @@ -106,16 +106,6 @@ Examples of control usage -### NavBar and friends - - - - - - - - - ### Pivot and PivotItem @@ -155,20 +145,17 @@ Examples of control usage -### SplitView - - - SplitView Navigation Pane - SplitView Content Area - - -### SplitView +### SplitView and optional SplitViewPaneToggle angular.module("yourAngularApp", ["winjs"]).controller("yourController", function ($scope) { $scope.splitViewElement = document.getElementById("splitView"); }); - SplitView Navigation Pane + + SplitView Navigation Pane + + + SplitView Content Area @@ -203,12 +190,29 @@ Examples of control usage - This Pivot is showing how to access its winControl through Angular + This Pivot is showing how to access its winControl through Angular. + The winControl can now be accessed as a variable on the Angular scope, using the same name that was + specified in the directive. In this case, $scope.pivotWinControl +How to run unit tests +------------------------- + +### Install Node +In order run tests, ensure that you have [Node.js](http://nodejs.org/download/) installed. + +### Run the tests +From the local angular-winjs repository +``` +npm install +npm test +``` + Notes ----- -For all of the controls you can bind to all public properties and events and the camel cased property names conveniently map to attributes. +For all of the controls you can bind to: all public events, and camel cased property names, conveniently map to attributes. +- ```appBar.closedDisplayMode = "compact"``` maps to `````` +- ```flipView.onpageselected = pagesSelected()``` maps to `````` diff --git a/bower.json b/bower.json index 3ed77ce..76cd917 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,5 @@ { "name": "angular-winjs", - "version": "3.0.0", "homepage": "https://github.com/winjs/angular-winjs", "authors": [ "Microsoft Corporation and other contributors" @@ -21,6 +20,7 @@ "tests", "package.json", "karma.config.js", - "*.nuspec" + "*.nuspec", + "Gruntfile.js" ] } \ No newline at end of file diff --git a/js/angular-winjs.js b/js/angular-winjs.js index aa2a835..4ce52a4 100644 --- a/js/angular-winjs.js +++ b/js/angular-winjs.js @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corp. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. +// Copyright (c) Microsoft Corp. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. (function (global) { "use strict"; @@ -148,7 +148,7 @@ })); var deferUpdate = false; - function updateOriginalArray() { + var updateOriginalArray = function () { if (deferUpdate) { return; } @@ -634,7 +634,7 @@ } }; }); - + exists("ContentDialog") && module.directive("winContentDialog", function () { var api = { hidden: BINDING_property, @@ -669,16 +669,6 @@ }; }); - exists("NavBarContainer") && module.directive("winCommandTemplate", function () { - return { - require: ["^?winNavBarContainer"], - restrict: "E", - replace: true, - transclude: true, - compile: compileTemplate("template") - }; - }); - exists("DatePicker") && module.directive("winDatePicker", function () { var api = { calendar: BINDING_property, @@ -987,6 +977,8 @@ itemTemplate: BINDING_property, layout: BINDING_property, maxDeferredItemCleanup: BINDING_property, + maxLeadingPages: BINDING_property, + maxTrailingPages: BINDING_property, scrollPosition: BINDING_property, selection: BINDING_selection, selectionMode: BINDING_property, @@ -995,6 +987,7 @@ onFooterVisibilityChanged: BINDING_event, onGroupHeaderInvoked: BINDING_event, onHeaderVisibilityChanged: BINDING_event, + onAccessibilityAnnotationComplete: BINDING_event, onItemDragStart: BINDING_event, onItemDragEnter: BINDING_event, onItemDragBetween: BINDING_event, @@ -1100,88 +1093,6 @@ }; }); - exists("NavBar") && module.directive("winNavBar", ['$parse', function ($parse) { - var api = { - closedDisplayMode: BINDING_property, - opened: BINDING_property, - placement: BINDING_property, - onAfterClose: BINDING_event, - onAfterOpen: BINDING_event, - onBeforeClose: BINDING_event, - onBeforeOpen: BINDING_event, - onChildrenProcessed: BINDING_event - }; - - return { - restrict: "E", - replace: true, - scope: getScopeForAPI(api), - template: "
", - transclude: true, - link: function ($scope, elements, attrs) { - var control = initializeControl($scope, elements[0], WinJS.UI.NavBar, api); - - function onVisibilityChanged() { - apply($scope, function () { - $scope["opened"] = control["opened"]; - }); - } - - control.addEventListener("afteropen", onVisibilityChanged); - control.addEventListener("afterclose", onVisibilityChanged); - } - }; - - }]); - - exists("NavBarCommand") && module.directive("winNavBarCommand", function () { - var api = { - icon: BINDING_property, - label: BINDING_property, - location: BINDING_property, - splitButton: BINDING_property, - splitOpened: BINDING_property, - state: BINDING_property, - tooltip: BINDING_property - }; - return { - restrict: "E", - replace: true, - scope: getScopeForAPI(api), - template: "
", - transclude: true, - link: function ($scope, elements) { - initializeControl($scope, elements[0], WinJS.UI.NavBarCommand, api); - } - }; - }); - - exists("NavBarContainer") && module.directive("winNavBarContainer", function () { - var api = { - currentIndex: BINDING_property, - data: BINDING_property, - fixedSize: BINDING_property, - layout: BINDING_property, - template: BINDING_property, - maxRows: BINDING_property, - onInvoked: BINDING_event, - onSplitToggle: BINDING_event - }; - return { - restrict: "E", - replace: true, - scope: getScopeForAPI(api), - template: "
", - transclude: true, - controller: ['$scope', function ($scope) { - proxy($scope, this, "template"); - }], - link: function ($scope, elements) { - initializeControl($scope, elements[0], WinJS.UI.NavBarContainer, api); - } - }; - }); - var pivotHelperDirectives = [ { controlOptionName: "customLeftHeader", @@ -1429,6 +1340,16 @@ }; }); + exists("SplitView") && module.directive("winSplitViewContent", function () { + return { + require: "^winSplitView", + restrict: "E", + replace: true, + transclude: true, + template: "
" + }; + }); + exists("SplitViewPaneToggle") && module.directive("winSplitViewPaneToggle", function () { var api = { splitView: BINDING_property, @@ -1446,13 +1367,22 @@ }; }); - exists("SplitView") && module.directive("winSplitViewContent", function () { + exists("SplitViewCommand") && module.directive("winSplitViewCommand", function () { + var api = { + icon: BINDING_property, + label: BINDING_property, + tooltip: BINDING_property, + onInvoked: BINDING_event, + }; return { - require: "^winSplitView", restrict: "E", replace: true, + scope: getScopeForAPI(api), + template: "
", transclude: true, - template: "
" + link: function ($scope, elements) { + initializeControl($scope, elements[0], WinJS.UI.SplitViewCommand, api); + } }; }); diff --git a/package.json b/package.json index 6442045..0b585bc 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "url": "https://github.com/winjs/angular-winjs/graphs/contributors" }, "license": "MIT", - "version": "3.0.0", + "version": "4.0.0", "main": "js/angular-winjs.js", "scripts": { "test": "karma start karma.config.js" @@ -37,6 +37,12 @@ "devDependencies": { "angular-mocks": "~1.3.13", "karma": "~0.10", - "winjs": "4.0.x" + "winjs": "4.2.x", + "grunt": "^0.4.5", + "grunt-contrib-clean": "^0.6.0", + "grunt-contrib-compress": "^0.13.0", + "grunt-contrib-copy": "^0.8.0", + "grunt-github-releaser": "^0.1.17", + "grunt-nuget": "^0.1.4" } } diff --git a/tasks/check-bom.js b/tasks/check-bom.js new file mode 100644 index 0000000..a89face --- /dev/null +++ b/tasks/check-bom.js @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. +(function () { + "use strict"; + + module.exports = function (grunt) { + + // Verifies that files begin with a UTF8 BOM. Files without one will not be able to pass the + // Windows App Certification Kit test. + + grunt.registerMultiTask("check-bom", function () { + function checkBom(filePath) { + if (grunt.file.exists(filePath)) { + var content = grunt.file.read(filePath, { encoding: null }); + if (content.length < 3 || content[0] !== 0xef || content[1] !== 0xbb || content[2] !== 0xbf) { + grunt.fail.fatal("check-bom File is missing BOM: " + filePath); + } + } else { + grunt.log.warn("check-bom No such file: " + filePath); + } + } + + this.filesSrc.forEach(checkBom); + }); + + }; +})(); diff --git a/tests/AppBarCommand.js b/tests/AppBarCommand.js index 3161b78..2ce812d 100644 --- a/tests/AppBarCommand.js +++ b/tests/AppBarCommand.js @@ -91,8 +91,8 @@ describe("AppBarCommand control directive tests", function () { "
"); var commands = compiledControl.querySelectorAll(".win-command"); - expect(commands[0].style.display).toEqual("none"); - expect(commands[1].style.display).toNotEqual("none"); + expect(commands[0].winControl.hidden).toBeTruthy(); + expect(commands[1].winControl.hidden).toBeFalsy(); }); it("should use the icon attribute on AppBarCommands", function () { diff --git a/tests/ListView.js b/tests/ListView.js index cfbe2e4..94fa82e 100644 --- a/tests/ListView.js +++ b/tests/ListView.js @@ -164,6 +164,16 @@ describe("ListView control directive tests", function () { var compiledControl = initControl(""); expect(compiledControl.winControl.maxDeferredItemCleanup).toEqual(10); }); + + it("should use the maxLeadingPages attribute", function () { + var compiledControl = initControl(""); + expect(compiledControl.winControl.maxLeadingPages).toEqual(7); + }); + + it("should use the maxTrailingPages attribute", function () { + var compiledControl = initControl(""); + expect(compiledControl.winControl.maxTrailingPages).toEqual(7); + }); it("should use the currentItem attribute", function () { scope.testCurrentItem = { @@ -201,6 +211,19 @@ describe("ListView control directive tests", function () { expect(compiledControl.winControl.layout instanceof WinJS.UI.ListLayout).toBeTruthy(); }); }); + + it("should use the onAccessibilityAnnotationComplete event", function () { + var gotEvent = false; + scope.handler = function (e) { + gotEvent = true; + }; + var compiledControl = initControl("" + + "{{item.data.title}}" + + ""); + waitsFor(function () { + return gotEvent; + }, "the ListView's onAccessibilityAnnotationComplete event", testTimeout); + }); it("should use the onContentAnimating event", function () { var gotAnimatingEvent = false; diff --git a/tests/NavBar.js b/tests/NavBar.js deleted file mode 100644 index 8e927ce..0000000 --- a/tests/NavBar.js +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) Microsoft Corp. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. - -describe("NavBar control directive tests", function () { - var testTimeout = 5000; - - var scope, - compile; - - beforeEach(angular.mock.module("winjs")); - beforeEach(angular.mock.inject(function ($rootScope, $compile) { - scope = $rootScope.$new(); - compile = $compile; - })); - - function initControl(markup) { - var element = angular.element(markup)[0]; - document.body.appendChild(element); - var compiledControl = compile(element)(scope)[0]; - scope.$digest(); - return compiledControl; - } - - it("should initialize a simple NavBar", function () { - var compiledControl = initControl(""); - - expect(compiledControl.winControl).toBeDefined(); - expect(compiledControl.winControl instanceof WinJS.UI.NavBar); - expect(compiledControl.className).toContain("win-navbar"); - }); - - it("should use child NavBarCommands", function () { - var compiledControl = initControl("" + - "" + - "" + - "" + - "" + - ""); - - expect(compiledControl.winControl).toBeDefined(); - expect(compiledControl.winControl instanceof WinJS.UI.NavBar); - expect(compiledControl.className).toContain("win-navbar"); - expect(compiledControl.querySelectorAll(".win-navbarcommand").length).toEqual(2); - }); - - it("should use the closedDisplayMode attribute", function () { - var compiledControl = initControl(""); - expect(compiledControl.winControl.closedDisplayMode).toEqual("minimal"); - }); - - it("should use the placement attribute", function () { - var compiledControl = initControl(""); - expect(compiledControl.winControl.placement).toEqual("top"); - }); - - it("should use the onChildrenProcessed event handler", function () { - var gotProcessedEvent = false; - scope.processedEventHandler = function (e) { - gotProcessedEvent = true; - }; - var compiledControl = initControl("" + - "" + - "" + - "" + - ""); - waitsFor(function () { - return gotProcessedEvent; - }, "the NavBar's onChildrenProcessed event", testTimeout); - }); - - it("should use the onopen and onclose event handlers and opened attribute", function () { - var gotBeforeOpenEvent = false, - gotAfterOpenEvent = false, - gotBeforeCloseEvent = false, - gotAfterCloseEvent = false; - scope.beforeOpenEventHandler = function (e) { - gotBeforeOpenEvent = true; - }; - scope.afterOpenEventHandler = function (e) { - gotAfterOpenEvent = true; - }; - scope.beforeCloseEventHandler = function (e) { - gotBeforeCloseEvent = true; - }; - scope.afterCloseEventHandler = function (e) { - gotAfterCloseEvent = true; - }; - scope.navbarOpened = false; - var compiledControl = initControl(""); - runs(function () { - compiledControl.winControl.open(); - }); - - waitsFor(function () { - return (gotBeforeOpenEvent && gotAfterOpenEvent); - }, "the NavBar's before+aftershow events", testTimeout); - - runs(function () { - expect(scope.navbarOpened).toBeTruthy(); - scope.navbarOpened = false; - scope.$digest(); - }); - - waitsFor(function () { - return (gotBeforeCloseEvent && gotAfterCloseEvent); - }, "the NavBar's before+afterhide events", testTimeout); - - runs(function () { - expect(scope.navbarOpened).toBeFalsy(); - expect(compiledControl.winControl.opened).toBeFalsy(); - }); - }); - - afterEach(function () { - var controls = document.querySelectorAll(".win-navbar"); - for (var i = 0; i < controls.length; i++) { - controls[i].parentNode.removeChild(controls[i]); - } - }); -}); diff --git a/tests/NavBarCommand.js b/tests/NavBarCommand.js deleted file mode 100644 index 1892dba..0000000 --- a/tests/NavBarCommand.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corp. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. - -describe("NavBarCommand control directive tests", function () { - var scope, - compile; - - beforeEach(angular.mock.module("winjs")); - beforeEach(angular.mock.inject(function ($rootScope, $compile) { - scope = $rootScope.$new(); - compile = $compile; - })); - - function initControl(markup) { - var element = angular.element(markup)[0]; - document.body.appendChild(element); - var compiledControl = compile(element)(scope)[0]; - scope.$digest(); - return compiledControl; - } - - it("should use initialize a NavBar containing two child NavBarCommands", function () { - var compiledControl = initControl("" + - "" + - "" + - ""); - - expect(compiledControl.querySelectorAll(".win-navbarcommand").length).toEqual(2); - }); - - it("should use the label attribute on NavBarCommands", function () { - var compiledControl = initControl("" + - "" + - "" + - ""); - - var commands = compiledControl.querySelectorAll(".win-navbarcommand"); - expect(commands[0].querySelector(".win-navbarcommand-label").innerHTML).toEqual("command1"); - expect(commands[1].querySelector(".win-navbarcommand-label").innerHTML).toEqual("command2"); - }); - - it("should use the location attribute on NavBarCommands", function () { - var compiledControl = initControl("" + - "" + - ""); - - var commands = compiledControl.querySelectorAll(".win-navbarcommand"); - expect(commands[0].winControl.location).toEqual("someLocation"); - }); - - afterEach(function () { - var controls = document.querySelectorAll(".win-navbarcontainer"); - for (var i = 0; i < controls.length; i++) { - controls[i].parentNode.removeChild(controls[i]); - } - }); -}); diff --git a/tests/NavBarContainer.js b/tests/NavBarContainer.js deleted file mode 100644 index 3fcbddb..0000000 --- a/tests/NavBarContainer.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corp. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. - -describe("NavBarContainer control directive tests", function () { - var testTimeout = 5000; - - var scope, - compile; - - beforeEach(angular.mock.module("winjs")); - beforeEach(angular.mock.inject(function ($rootScope, $compile) { - scope = $rootScope.$new(); - compile = $compile; - })); - - function initControl(markup) { - var element = angular.element(markup)[0]; - document.body.appendChild(element); - var compiledControl = compile(element)(scope)[0]; - scope.$digest(); - return compiledControl; - } - - it("should use the fixedSize attribute", function () { - var compiledControl = initControl(""); - - expect(compiledControl.winControl.fixedSize).toBeTruthy(); - }); - - it("should use the maxRows attribute", function () { - var compiledControl = initControl(""); - - expect(compiledControl.winControl.maxRows).toEqual(3); - }); - - it("should use the layout attribute", function () { - var compiledControl = initControl(""); - - expect(compiledControl.winControl.layout).toEqual("vertical"); - }); - - it("should use the data and template attributes", function () { - scope.data = new WinJS.Binding.List([1, 2, 3]); - scope.template = new WinJS.Binding.Template(); - var control = initControl("").winControl; - - expect(control.data).toEqual(scope.data); - expect(control.template).toEqual(scope.template); - }); - - afterEach(function () { - var controls = document.querySelectorAll(".win-navbarcontainer"); - for (var i = 0; i < controls.length; i++) { - controls[i].parentNode.removeChild(controls[i]); - } - }); -}); diff --git a/tests/SplitViewCommand.js b/tests/SplitViewCommand.js new file mode 100644 index 0000000..09c07b5 --- /dev/null +++ b/tests/SplitViewCommand.js @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corp. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. + +describe("SplitViewCommand control directive tests", function () { + var scope, + compile; + + beforeEach(angular.mock.module("winjs")); + beforeEach(angular.mock.inject(function ($rootScope, $compile) { + scope = $rootScope.$new(); + compile = $compile; + })); + + function initControl(markup) { + var element = angular.element(markup)[0]; + document.body.appendChild(element); + var compiledControl = compile(element)(scope)[0]; + scope.$digest(); + return compiledControl; + } + + it("should initialize a simple SplitViewCommand", function () { + var compiledControl = initControl(""); + + expect(compiledControl.winControl).toBeDefined(); + expect(compiledControl.winControl instanceof WinJS.UI.SplitViewCommand); + expect(compiledControl.className).toContain("win-splitviewcommand"); + }); + + it("should use the label attribute", function () { + var compiledControl = initControl(""); + + expect(compiledControl.querySelector(".win-splitviewcommand-label").innerHTML).toEqual("add"); + }); + + it("should use the onInvoked attribute", function () { + var gotInvokedEvent = false; + scope.onInvoked = function () { + gotInvokedEvent = true; + }; + var compiledControl = initControl(""); + var button = compiledControl.querySelector(".win-splitviewcommand-button"); + expect(gotInvokedEvent).toBeFalsy(); + button.click(); + expect(gotInvokedEvent).toBeTruthy(); + }); + + afterEach(function () { + var controls = document.querySelectorAll(".win-splitviewcommand"); + for (var i = 0; i < controls.length; i++) { + controls[i].parentNode.removeChild(controls[i]); + } + }); +}); +