decide.nolog.cz/tests/helpers/poll-participate.js

22 lines
750 B
JavaScript
Raw Normal View History

2018-12-29 01:27:37 +01:00
import { isEmpty } from '@ember/utils';
2018-12-29 20:35:04 +01:00
import { findAll, fillIn, click } from '@ember/test-helpers';
2018-12-29 20:35:04 +01:00
export default async function(name, selections) {
2018-12-29 01:27:37 +01:00
if (!isEmpty(name)) {
2018-12-29 20:35:04 +01:00
await fillIn('.participation .name input', name);
}
2018-12-29 20:35:04 +01:00
const isFreeText = findAll('.participation .selections .radio').length > 0 ? false : true;
for (let [index, selection] of selections.entries()) {
2018-12-29 01:27:37 +01:00
if (!isEmpty(selection)) {
if (isFreeText) {
2018-12-29 20:35:04 +01:00
await fillIn(`.participation .selections .form-group:nth-child(${index + 1}) input`, selection);
} else {
2018-12-29 20:35:04 +01:00
await click(`.participation .selections .form-group:nth-child(${index + 1}) .${selection}.radio input`);
}
}
2018-12-29 20:35:04 +01:00
}
2018-12-29 20:35:04 +01:00
await click('.participation button[type="submit"]');
}