Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Finished custom form editor tests
Browse files Browse the repository at this point in the history
Closes #788
  • Loading branch information
jkleinsc committed Nov 14, 2016
1 parent 5b7a97e commit 7df23d6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/admin/custom-forms/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{#each model as |customForm|}}
{{#unless customForm.archived}}
<tr {{action 'editItem' customForm}} class="clickable">
<td>{{customForm.name}}</td>
<td class="custom-form-name">{{customForm.name}}</td>
<td>
{{t (concat 'admin.customForms.labels.' customForm.formType 'FormType')}}
</td>
Expand Down
87 changes: 58 additions & 29 deletions tests/acceptance/custom-forms-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ module('Acceptance | custom forms', {
});

test('crud operations on custom-forms', function(assert) {
let crusts = ['Thin', 'Deep Dish', 'Flatbread'];
let desserts = ['Ice Cream', 'Cookies', 'Cake'];
let toppings = ['Cheese', 'Pepperoni', 'Mushrooms'];

function addField(fieldType, label, values) {
click('button:contains(Add Field)');
waitToAppear('.modal-dialog');
andThen(function() {
console.log('about to fillin for:'+label);
assert.equal(find('.modal-title').text(), 'Add Value', 'Add Value modal displays.');
select('.custom-field-select', fieldType);
fillIn('.custom-field-label input', label);
Expand All @@ -36,7 +39,6 @@ test('crud operations on custom-forms', function(assert) {
})
andThen(function() {
assert.equal(find('.custom-field-value:contains(Delete Me)').length, 0, 'Field value successfully deleted');
console.log('about to set values for:'+label);
values.forEach(function(value) {
click('button:contains(Add Value)');
andThen(function() {
Expand All @@ -46,41 +48,59 @@ test('crud operations on custom-forms', function(assert) {
});
}
andThen(function() {
console.log('about to call add for:'+label);
click('.modal-footer button:contains(Add)');
});
}

function verifyPreview() {
click('button:contains(Preview)');
waitToAppear('.form-preview');
andThen(function() {
assert.equal(find('.form-preview label:contains(Pizza Toppings)').length, 1, 'Found Pizza Toppings Label');
toppings.forEach((topping) => {
assert.equal(find(`.form-preview label:contains(${topping}):has(input[type=checkbox])`).length, 1, `Found ${topping} checkbox`);
});
assert.equal(find('.form-preview label:contains(Pizza Crust)').length, 1, 'Found Pizza Toppings Label');
crusts.forEach((crust) => {
assert.equal(find(`.form-preview option:contains(${crust})`).length, 1, `Found ${crust} option`);
});
assert.equal(find('.form-preview label:contains(Dessert)').length, 1, 'Found Pizza Toppings Label');
desserts.forEach((dessert) => {
assert.equal(find(`.form-preview label:contains(${dessert}):has(input[type=radio])`).length, 1, `Found ${dessert} radio option`);
});
assert.equal(find('.form-preview label:contains(Beverage)').length, 1, 'Found Beverage Label');
assert.equal(find('.form-preview input[id*=beverage]').length, 1, 'Found Beverage input');
assert.equal(find('.form-preview label:contains(Special Instructions)').length, 1, 'Found Special Instructions Label');
assert.equal(find('.form-preview textarea[id*=specialInstructions]').length, 1, 'Found special instructions textarea');
click('button:contains(Preview)'); //Hide preview to reset it back to being closed.
});
}

runWithPouchDump('default', function() {
authenticateUser();
visit('/admin/custom-forms');
andThen(function() {
assert.equal(currentURL(), '/admin/custom-forms', 'Navigated to custom forms index page');
assert.equal(find('.custom-form-name').length, 0, 'No custom forms appears in the listing.');
click('button:contains(new form)');
waitToAppear('.view-current-title:contains(New Custom Form)');
});
andThen(function() {
assert.equal(find('.view-current-title').text(), 'New Custom Form', 'New custom form edit page displays');
assert.equal(currentURL(), '/admin/custom-forms/edit/new', 'Navigated to create new custom form');
fillIn('.custom-form-name input', 'Test Custom Form')
fillIn('.custom-form-columns input', '2');
select('.custom-form-type', 'Visit');
click('.panel-footer button:contains(Add)');
waitToAppear('.modal-dialog');
});
let toppings = ['Cheese', 'Pepperoni', 'Mushrooms'];
let crusts = ['Thin', 'Deep Dish', 'Flatbread'];
let desserts = ['Ice Cream', 'Cookies', 'Cake'];
andThen(function() {
assert.equal(find('.modal-title').text(), 'Form Saved', 'Form is saved');
console.log('about to add checkbox');
addField('Checkbox','Pizza Toppings', toppings);
});
andThen(function() {
console.log('about to add dropdown');
addField('Dropdown','Pizza Crust', crusts);
});
andThen(function() {
console.log('about to add radio');
addField('Radio','Dessert', desserts);
});
andThen(function() {
Expand All @@ -95,27 +115,36 @@ test('crud operations on custom-forms', function(assert) {
});
andThen(function() {
assert.equal(find('.modal-title').text(), 'Form Saved', 'Form is updated');
click('button:contains(Preview)');
waitToAppear('.form-preview');
verifyPreview(1);
});
andThen(function() {
assert.equal(find('.form-preview label:contains(Pizza Toppings)').length, 1, 'Found Pizza Toppings Label');
toppings.forEach((topping) => {
assert.equal(find(`.form-preview label:contains(${topping}):has(input[type=checkbox])`).length, 1, `Found ${topping} checkbox`);
});
assert.equal(find('.form-preview label:contains(Pizza Crust)').length, 1, 'Found Pizza Toppings Label');
crusts.forEach((crust) => {
assert.equal(find(`.form-preview option:contains(${crust})`).length, 1, `Found ${crust} option`);
});
assert.equal(find('.form-preview label:contains(Dessert)').length, 1, 'Found Pizza Toppings Label');
desserts.forEach((dessert) => {
assert.equal(find(`.form-preview label:contains(${dessert}):has(input[type=radio])`).length, 1, `Found ${dessert} radio option`);
});
waitToAppear('sdfdfsf');
assert.equal(find('.form-preview label:contains(Beverage)').length, 1, 'Found Beverage Label');
assert.equal(find('.form-preview input[id*=beverage]').length, 1, 'Found Beverage input');
assert.equal(find('.form-preview label:contains(Special Instructions)').length, 1, 'Found Special Instructions Label');
assert.equal(find('.form-preview textarea[id*=specialInstructions]').length, 1, 'Found special instructions textarea');
click('button:contains(Return)');
waitToAppear('.view-current-title:contains(Custom Forms)');
});
andThen(function() {
assert.equal(find('.custom-form-name:contains(Test Custom Form)').length, 1, 'Custom form appears in listing.');
click('button:contains(Edit)');
waitToAppear('button:contains(Preview)');
});
andThen(function() {
assert.equal(find('.view-current-title').text(), 'Edit Custom Form', 'Custom form edit page displays');
verifyPreview(2);
});
andThen(function() {
click('button:contains(Return)');
waitToAppear('.view-current-title:contains(Custom Forms)');
});
andThen(function() {
click('button:contains(Delete)');
waitToAppear('.modal-dialog');
});
andThen(function() {
assert.equal(find('.modal-title').text(), 'Delete Custom Form', 'Delete confirmation displays');
click('.modal-footer button:contains(Ok)');
});
andThen(function() {
assert.equal(find('.custom-form-name').length, 0, 'Deleted custom form disappears from custom form listing.');
});

});
});

0 comments on commit 7df23d6

Please sign in to comment.