|
5 | 5 |
|
6 | 6 | import { module, test } from 'qunit'; |
7 | 7 | import { setupRenderingTest } from 'ember-qunit'; |
8 | | -import { render } from '@ember/test-helpers'; |
| 8 | +import { click, fillIn, render } from '@ember/test-helpers'; |
9 | 9 | import { hbs } from 'ember-cli-htmlbars'; |
10 | 10 | import { v4 as uuidv4 } from 'uuid'; |
11 | 11 | import { setupIntl } from 'ember-intl/test-support'; |
@@ -85,5 +85,39 @@ module( |
85 | 85 |
|
86 | 86 | assert.dom('[name="cluster_id"]').hasNoValue(); |
87 | 87 | }); |
| 88 | + |
| 89 | + test('it adds and removes worker tags', async function (assert) { |
| 90 | + this.model = {}; |
| 91 | + this.submit = () => {}; |
| 92 | + this.cancel = () => {}; |
| 93 | + |
| 94 | + const KEY_VALUE_INPUT_SELECTOR = (row, column) => |
| 95 | + `[name="worker_tags"] tbody :nth-child(${row}) td:nth-child(${column}) input`; |
| 96 | + const KEY_VALUE_BUTTON_SELECTOR = (row) => |
| 97 | + `[name="worker_tags"] tbody :nth-child(${row}) button`; |
| 98 | + const KEY_VALUE_ROW = '[name="worker_tags"] tbody tr'; |
| 99 | + |
| 100 | + await render( |
| 101 | + hbs`<Form::Worker::CreateWorkerLed @model={{this.model}} @submit={{this.submit}} @cancel={{this.cancel}} />`, |
| 102 | + ); |
| 103 | + |
| 104 | + assert.dom(KEY_VALUE_ROW).exists({ count: 1 }); |
| 105 | + |
| 106 | + // Test adding a worker tag |
| 107 | + await fillIn(KEY_VALUE_INPUT_SELECTOR(1, 1), 'environment'); |
| 108 | + await fillIn(KEY_VALUE_INPUT_SELECTOR(1, 2), 'dev'); |
| 109 | + await click(KEY_VALUE_BUTTON_SELECTOR(1)); |
| 110 | + |
| 111 | + await fillIn(KEY_VALUE_INPUT_SELECTOR(2, 1), 'environment'); |
| 112 | + await fillIn(KEY_VALUE_INPUT_SELECTOR(2, 2), 'test'); |
| 113 | + await click(KEY_VALUE_BUTTON_SELECTOR(2)); |
| 114 | + |
| 115 | + assert.dom(KEY_VALUE_ROW).exists({ count: 3 }); |
| 116 | + |
| 117 | + // Remove the worker tag |
| 118 | + await click(KEY_VALUE_BUTTON_SELECTOR(1)); |
| 119 | + |
| 120 | + assert.dom(KEY_VALUE_ROW).exists({ count: 2 }); |
| 121 | + }); |
88 | 122 | }, |
89 | 123 | ); |
0 commit comments