Skip to content

Commit

Permalink
#60 Usando ng-if ao inves de ng-show na diretiva dynamicField
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Oliveira authored and rasoliveira committed Jan 30, 2015
1 parent 7a95b8b commit cd6999a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/scripts/directives/dynamic-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ angular.module('cmsApp')

var query = queries.join((need.equal) ? '||' : '&&');
element.attr('ng-required', query);
element.attr('ng-show', query);
element.attr('ng-if', query);
}else {
element.attr('ng-required', 'field.required');
}
Expand Down
20 changes: 10 additions & 10 deletions test/spec/directives/dynamic-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ describe('Directive: dynamicField', function () {
}));
});

describe('dynamic field to fill ng-show', function() {
describe('dynamic field to fill ng-if', function() {
it('should put nothing required when do not have "need" field', inject(function ($compile) {
scope.field = {

};
element = angular.element('<input dynamic-field="field"/>');
element = $compile(element)(scope);
expect(element.attr('ng-show')).toBeFalsy();
expect(element.attr('ng-if')).toBeFalsy();
}));


describe('when have a "need" field', function() {
it('should put ng-show with condition equal', inject(function ($compile) {
it('should put ng-if with condition equal', inject(function ($compile) {
scope.field = {
need: {
field: 'section',
Expand All @@ -55,10 +55,10 @@ describe('Directive: dynamicField', function () {
};
element = angular.element('<input dynamic-field="field"/>');
element = $compile(element)(scope);
expect(element.attr('ng-show')).toBe('entity.section===\'tv\'');
expect(element.attr('ng-if')).toBe('entity.section===\'tv\'');
}));

it('should put ng-show with condition not equal', inject(function ($compile) {
it('should put ng-if with condition not equal', inject(function ($compile) {
scope.field = {
need: {
field: 'section',
Expand All @@ -68,9 +68,9 @@ describe('Directive: dynamicField', function () {
};
element = angular.element('<input dynamic-field="field"/>');
element = $compile(element)(scope);
expect(element.attr('ng-show')).toBe('entity.section!==\'tv\'');
expect(element.attr('ng-if')).toBe('entity.section!==\'tv\'');
}));
it('should put ng-show with condition equal and using OR, when value is an array', inject(function($compile){
it('should put ng-if with condition equal and using OR, when value is an array', inject(function($compile){
scope.field = {
need: {
field: 'section',
Expand All @@ -80,9 +80,9 @@ describe('Directive: dynamicField', function () {
};
element = angular.element('<input dynamic-field="field"/>');
element = $compile(element)(scope);
expect(element.attr('ng-show')).toBe('entity.section===\'tv\'||entity.section===\'featured-news\'');
expect(element.attr('ng-if')).toBe('entity.section===\'tv\'||entity.section===\'featured-news\'');
}));
it('should put ng-show with condition equal and using AND, when value is an array', inject(function($compile){
it('should put ng-if with condition equal and using AND, when value is an array', inject(function($compile){
scope.field = {
need: {
field: 'section',
Expand All @@ -92,7 +92,7 @@ describe('Directive: dynamicField', function () {
};
element = angular.element('<input dynamic-field="field"/>');
element = $compile(element)(scope);
expect(element.attr('ng-show')).toBe('entity.section!==\'tv\'&&entity.section!==\'featured-news\'');
expect(element.attr('ng-if')).toBe('entity.section!==\'tv\'&&entity.section!==\'featured-news\'');
}));
});
});
Expand Down

0 comments on commit cd6999a

Please sign in to comment.