az-promise-show
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -0,3 +1,9 @@ | ||
# 1.0.1 | ||
## Other Changes | ||
- Updating README.md | ||
# 1.0.0 | ||
- Initial Release |
{ | ||
"name": "az-promise-show", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "angular directives to show or hide an element based on the state of a promise", | ||
@@ -18,2 +18,3 @@ "main": "dist/az-promise-show.js", | ||
"chai": "3.0.0", | ||
"codecov.io": "0.1.2", | ||
"eslint": "0.23.0", | ||
@@ -23,2 +24,3 @@ "eslint-loader": "0.14.0", | ||
"isparta-loader": "0.2.0", | ||
"istanbul": "0.3.15", | ||
"karma": "0.12.36", | ||
@@ -29,3 +31,3 @@ "karma-coverage": "0.4.2", | ||
"karma-webpack": "1.5.1", | ||
"kcd-common-tools": "1.0.0-beta.5", | ||
"kcd-common-tools": "1.0.0-beta.9", | ||
"mocha": "2.2.5", | ||
@@ -44,2 +46,7 @@ "ng-annotate": "1.0.0", | ||
"test": "better-npm-run test", | ||
"test:ci": "npm run test:single && npm run check-coverage", | ||
"test:single": "better-npm-run test:single", | ||
"check-coverage": "istanbul check-coverage --statements 96 --branches 94 --functions 100 --lines 95", | ||
"report-coverage": "echo 'Reporting coverage stats' && cat ./coverage/lcov.info | codecov", | ||
"deploy": "surge -p demo -d az-promise-show.surge.sh", | ||
"release": "with-package git commit -am pkg.version && with-package git tag pkg.version && git push && npm publish && git push --tags" | ||
@@ -55,2 +62,9 @@ }, | ||
}, | ||
"test:single": { | ||
"env": { | ||
"NODE_ENV": "test", | ||
"COVERAGE": "true" | ||
}, | ||
"command": "karma start --single-run" | ||
}, | ||
"build:dist": { | ||
@@ -90,4 +104,11 @@ "env": { | ||
"webpack": { | ||
"externals": { | ||
"angular": "angular" | ||
"development": { | ||
"externals": { | ||
"angular": "angular" | ||
} | ||
}, | ||
"production": { | ||
"externals": { | ||
"angular": "angular" | ||
} | ||
} | ||
@@ -94,0 +115,0 @@ } |
# az-promise-show | ||
[![npm version](https://img.shields.io/npm/v/az-promise-show.svg?style=flat-square)](https://www.npmjs.org/package/az-promise-show) | ||
[![npm downloads](https://img.shields.io/npm/dm/az-promise-show.svg?style=flat-square)](http://npm-stat.com/charts.html?package=az-promise-show&from=2015-01-01) | ||
[![Build Status](https://img.shields.io/codeship/65e705f0-f603-0132-fc07-764c17a205db.svg?style=flat-square)](https://codeship.com/projects/85923) | ||
[![Code Coverage](https://img.shields.io/codecov/c/github/alianza-dev/az-promise-show.svg?style=flat-square)](https://codecov.io/github/alianza-dev/az-promise-show) | ||
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/alianza-dev/az-promise-show?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
Directives to show or hide an element based on the resolved state of an angular promise. | ||
See [the example](http://alianza-dev.github.io/az-promise-show/demo) and | ||
[the example code](https://rawgit.com/alianza-dev/az-promise-show/master/demo/index.html) | ||
See [the example](http://az-promise-show.surge.sh/) and | ||
[the example code](https://github.com/alianza-dev/az-promise-show/blob/master/demo/index.html) | ||
## Docs | ||
### Usage | ||
#### Install the module | ||
`$ npm install az-promise-show --save` | ||
Or just download it from the dist directory. | ||
#### Depend on the module | ||
```javascript | ||
angular.module('yourModule', ['azPromiseShow']); | ||
``` | ||
#### az-promise-show | ||
```html | ||
<div az-promise-show="aPromise"> | ||
I'm only shown when the promise is in flight | ||
</div> | ||
``` | ||
#### az-promise-hide | ||
```html | ||
<div az-promise-hide="anotherPromise"> | ||
I'm only show when the promise is not in flight | ||
</div> | ||
``` | ||
#### az-promise-show-hide-class | ||
```html | ||
<div az-promise-show="aPromise" az-promise-show-hide-class="display-none"> | ||
By default, azPromiseShow uses 'ng-hide', but you can specify your own if you want. | ||
</div> | ||
``` |
@@ -15,3 +15,3 @@ // some versions of angular don't export the angular module properly, | ||
.directive('azPromiseHide', azPromise(false)) | ||
.name; // <-- exported poprerty | ||
.name; // <-- exported property | ||
@@ -18,0 +18,0 @@ function azPromise(show) { |
@@ -1,2 +0,2 @@ | ||
import angular from 'angular'; | ||
import 'angular'; | ||
import 'angular-mocks'; | ||
@@ -9,30 +9,57 @@ import ngModuleName from './index'; | ||
var scope, el; | ||
var displayNone = 'ng-hide'; | ||
beforeEach(inject(($compile, $rootScope) => { | ||
const basicTemplate = '<div az-promise-show="aPromise"></div>'; | ||
let scope, el, $timeout, $compile; | ||
beforeEach(inject((_$compile_, $rootScope, _$timeout_) => { | ||
$timeout = _$timeout_; | ||
$compile = _$compile_; | ||
scope = $rootScope.$new(); | ||
el = $compile('<div az-promise-show="aPromise"></div>')(scope); | ||
scope.$digest(); | ||
})); | ||
it('should initialize as display none', () => { | ||
expect(el.hasClass(displayNone)).to.be.true; | ||
compileAndDigest(); | ||
expectHidden(); | ||
}); | ||
it('should display when promise is in flight', inject(($timeout) => { | ||
it('should display when promise is in flight', () => { | ||
compileAndDigest(); | ||
scope.aPromise = $timeout(() => {}); | ||
scope.$digest(); | ||
expect(el.hasClass(displayNone)).to.be.false; | ||
expectShowing(); | ||
$timeout.flush(); | ||
scope.$digest(); | ||
expect(el.hasClass(displayNone)).to.be.true; | ||
})); | ||
expectHidden(); | ||
}); | ||
it('should log an error when the given value is not a promise and not show the element', inject(($log) => { | ||
scope.$digest(); | ||
compileAndDigest(); | ||
scope.aPromise = 'ಠ_ಠ'; | ||
expect(() => scope.$digest()).to.throw('must pass a promise to az-promise-show'); | ||
expect($log.error.logs).have.length(1); | ||
expect(el.hasClass(displayNone)).to.be.true; | ||
expectHidden(); | ||
})); | ||
it(`should allow you to specify a custom class`, () => { | ||
const customClassName = 'display-none'; | ||
compileAndDigest(`<div az-promise-hide="aPromise" az-promise-show-hide-class="${customClassName}"></div>`); | ||
scope.aPromise = $timeout(() => {}); | ||
scope.$digest(); | ||
expectHidden(customClassName); | ||
$timeout.flush(); | ||
scope.$digest(); | ||
expectShowing(customClassName); | ||
}); | ||
function compileAndDigest(template = basicTemplate) { | ||
el = $compile(template)(scope); | ||
scope.$digest(); | ||
} | ||
function expectShowing(className = 'ng-hide') { | ||
expect(el.hasClass(className)).to.be.false; | ||
} | ||
function expectHidden(className = 'ng-hide') { | ||
expect(el.hasClass(className)).to.be.true; | ||
} | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23589
198
53
27
9