fix: 🐛 Fix removing worker tag (#2928)

This commit is contained in:
Zhihe Li authored and GitHub committed 2025-07-16 13:27:13 -04:00
1 parent fbd613084d
commit 0a2d743ea2
2 files changed
+36 -2

No files matched your search

@@ -184,7 +184,7 @@ unzip *.zip ;\\
@action
removeWorkerTagByIndex(index) {
this.workerTags.removeAt(index);
this.workerTags.splice(index, 1);
}
@action
@@ -5,7 +5,7 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { click, fillIn, render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { v4 as uuidv4 } from 'uuid';
import { setupIntl } from 'ember-intl/test-support';
@@ -85,5 +85,39 @@ module(
assert.dom('[name="cluster_id"]').hasNoValue();
});
test('it adds and removes worker tags', async function (assert) {
this.model = {};
this.submit = () => {};
this.cancel = () => {};
const KEY_VALUE_INPUT_SELECTOR = (row, column) =>
`[name="worker_tags"] tbody :nth-child(${row}) td:nth-child(${column}) input`;
const KEY_VALUE_BUTTON_SELECTOR = (row) =>
`[name="worker_tags"] tbody :nth-child(${row}) button`;
const KEY_VALUE_ROW = '[name="worker_tags"] tbody tr';
await render(
hbs`<Form::Worker::CreateWorkerLed @model={{this.model}} @submit={{this.submit}} @cancel={{this.cancel}} />`,
);
assert.dom(KEY_VALUE_ROW).exists({ count: 1 });
// Test adding a worker tag
await fillIn(KEY_VALUE_INPUT_SELECTOR(1, 1), 'environment');
await fillIn(KEY_VALUE_INPUT_SELECTOR(1, 2), 'dev');
await click(KEY_VALUE_BUTTON_SELECTOR(1));
await fillIn(KEY_VALUE_INPUT_SELECTOR(2, 1), 'environment');
await fillIn(KEY_VALUE_INPUT_SELECTOR(2, 2), 'test');
await click(KEY_VALUE_BUTTON_SELECTOR(2));
assert.dom(KEY_VALUE_ROW).exists({ count: 3 });
// Remove the worker tag
await click(KEY_VALUE_BUTTON_SELECTOR(1));
assert.dom(KEY_VALUE_ROW).exists({ count: 2 });
});
},
);