Skip to content

Commit

Permalink
Test for adding input or textarea child fields
Browse files Browse the repository at this point in the history
  • Loading branch information
awead committed Sep 19, 2016
1 parent fc20b8d commit ac4b0bb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Rakefile
Expand Up @@ -33,6 +33,8 @@ require 'engine_cart/rake_task'
require 'jasmine'
load 'jasmine/tasks/jasmine.rake'

import "#{Gem.loaded_specs['jasmine'].full_gem_path}/lib/jasmine/tasks/jasmine.rake"

# Set up the test application prior to running jasmine tasks.
task 'jasmine:require' => :setup_test_server
task :setup_test_server do
Expand Down
13 changes: 9 additions & 4 deletions app/assets/javascripts/hydra-editor/field_manager.es6
Expand Up @@ -82,10 +82,8 @@ export class FieldManager {

createNewField($activeField) {
let $newField = $activeField.clone();
let $newChildren = $newField.children('.multi_value');
$newChildren.val('').removeProp('required');
$newChildren.first().focus();
this.element.trigger("managed_field:add", $newChildren.first());
let $newChildren = this.createNewChildren($newField);
this.element.trigger("managed_field:add", $newChildren);
return $newField;
}

Expand Down Expand Up @@ -146,4 +144,11 @@ export class FieldManager {
$removeHtml.find('.controls-field-name-text').html(options.label);
return $removeHtml;
}

createNewChildren(clone) {
let $newChildren = $(clone).children('.multi_value');
$newChildren.val('').removeProp('required');
$newChildren.first().focus();
return $newChildren.first();
}
}
20 changes: 20 additions & 0 deletions spec/javascripts/manage_fields_spec.js
Expand Up @@ -20,4 +20,24 @@ describe("FieldManager", function() {
expect(element.find('button.remove')).toExist()
});
});

describe("#createNewChildren", function() {
it("removes values and properties from an input tag", function() {
var field = '<li class="field-wrapper"><input class="string multi_value optional text_title form-control multi-text-field" name="text[title][]" value="sample value" required id="text_title" aria-labelledby="text_title_label" type="text" /></li>'
expect($(field).find('input').val()).toEqual('sample value')
expect($(field).find('input').attr('required')).toEqual('required');
var child = target.createNewChildren($(field))
expect(child.val()).toEqual('')
expect(child.attr('required')).toBeUndefined();
})

it("removes values and properties from a textarea tag", function() {
var field = '<li class="field-wrapper"><textarea class="string multi_value optional text_title form-control multi-text-field" name="text[title][]" required id="text_title" aria-labelledby="text_title_label">sample value</textarea></li>'
expect($(field).find('textarea').val()).toEqual('sample value')
expect($(field).find('textarea').attr('required')).toEqual('required');
var child = target.createNewChildren($(field))
expect(child.val()).toEqual('')
expect(child.attr('required')).toBeUndefined();
})
})
});

0 comments on commit ac4b0bb

Please sign in to comment.