You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. QUnit.module('complex-repeater', {
  2. setup: function () {
  3. this.$fixture = $('#qunit-fixture');
  4. this.$fixture.html($('#template').html());
  5. this.$repeater = this.$fixture.find('.complex-repeater');
  6. this.$addButton = this.$repeater.find('[data-repeater-create]');
  7. this.$fixture.append($('#template').html());
  8. }
  9. });
  10. QUnit.test('add item', function (assert) {
  11. this.$repeater.repeater();
  12. this.$addButton.click();
  13. var $items = this.$repeater.find('[data-repeater-item]');
  14. assert.strictEqual($items.length, 2, 'adds a second item to list');
  15. assert.deepEqual(
  16. getNamedInputValues($items.last()),
  17. { 'complex-repeater[1][text-input]': '' },
  18. 'added items inputs are clear'
  19. );
  20. assert.deepEqual(
  21. getNamedInputValues($items.first()),
  22. { 'complex-repeater[0][text-input]': 'A' },
  23. 'does not clear other inputs'
  24. );
  25. });
  26. QUnit.test('delete item', function (assert) {
  27. this.$repeater.repeater();
  28. this.$repeater.find('[data-repeater-delete]').first().click();
  29. assert.strictEqual(
  30. this.$repeater.find('[data-repeater-item]').length, 0,
  31. 'deletes item'
  32. );
  33. });
  34. QUnit.test('delete item that has been added', function (assert) {
  35. this.$repeater.repeater();
  36. this.$addButton.click();
  37. assert.strictEqual(
  38. this.$repeater.find('[data-repeater-item]').length, 2,
  39. 'item added'
  40. );
  41. this.$repeater.find('[data-repeater-delete]').last().click();
  42. assert.strictEqual(
  43. this.$repeater.find('[data-repeater-item]').length, 1,
  44. 'item deleted'
  45. );
  46. });