Tests target update create (#1594)

* test: 💍 add test cases for create and update target
This commit is contained in:
Dharini Jeeva authored and GitHub committed 2023-01-23 14:48:29 -08:00
1 parent b41b6ee3e3
commit 57fcab4c53
2 files changed
+146 -6

No files matched your search

@@ -84,7 +84,7 @@ module('Acceptance | targets | create', function (hooks) {
assert.strictEqual(find('[name="type"]:checked').value, TYPE_TARGET_SSH);
});
test('can create type `ssh`', async function (assert) {
test('can create type `ssh` when `target-worker-filters-v2` is disabled', async function (assert) {
featuresService.disable('target-worker-filters-v2');
assert.expect(4);
const targetCount = getTargetCount();
@@ -110,7 +110,33 @@ module('Acceptance | targets | create', function (hooks) {
);
});
test('can create type `tcp`', async function (assert) {
test('can create type `ssh` when `target-worker-filters-v2` is enabled', async function (assert) {
featuresService.enable('target-worker-filters-v2');
assert.expect(4);
const targetCount = getTargetCount();
const sshTargetCount = getSSHTargetCount();
await visit(urls.targets);
await click(`[href="${urls.newTarget}"]`);
await click('[value="ssh"]');
await fillIn('[name="name"]', 'random string');
await click('.hds-form-toggle__control', 'Egress worker filter');
await fillIn('[name="egress_worker_filter"]', 'random filter');
await click('[type="submit"]');
assert.strictEqual(getSSHTargetCount(), sshTargetCount + 1);
assert.strictEqual(getTargetCount(), targetCount + 1);
assert.strictEqual(
this.server.schema.targets.all().models[getTargetCount() - 1].name,
'random string'
);
assert.strictEqual(
this.server.schema.targets.all().models[getTargetCount() - 1]
.egressWorkerFilter,
'random filter'
);
});
test('can create type `tcp` when `target-worker-filters-v2` is disabled', async function (assert) {
featuresService.disable('target-worker-filters-v2');
assert.expect(4);
const targetCount = getTargetCount();
@@ -135,7 +161,33 @@ module('Acceptance | targets | create', function (hooks) {
'random filter'
);
});
test('can create type `tcp` when `target-worker-filters-v2` is enabled', async function (assert) {
featuresService.enable('target-worker-filters-v2');
assert.expect(4);
const targetCount = getTargetCount();
const tcpTargetCount = getTCPTargetCount();
await visit(urls.targets);
await click(`[href="${urls.newTarget}"]`);
await click('[value="tcp"]');
await fillIn('[name="name"]', 'random string');
await click('.hds-form-toggle__control', 'Egress worker filter');
await fillIn('[name="egress_worker_filter"]', 'random filter');
await click('[type="submit"]');
assert.strictEqual(getTargetCount(), targetCount + 1);
assert.strictEqual(getTCPTargetCount(), tcpTargetCount + 1);
assert.strictEqual(
this.server.schema.targets.all().models[getTargetCount() - 1].name,
'random string'
);
assert.strictEqual(
this.server.schema.targets.all().models[getTargetCount() - 1]
.egressWorkerFilter,
'random filter'
);
});
test('default port is not marked required for SSH targets', async function (assert) {
assert.expect(1);
await visit(urls.newTarget);
@@ -206,6 +258,8 @@ module('Acceptance | targets | create', function (hooks) {
await click(`[href="${urls.newTarget}"]`);
await fillIn('[name="name"]', 'random string');
await click('.hds-form-toggle__control', 'Egress worker filter');
await fillIn('[name="egress_worker_filter"]', 'random filter');
await click('.rose-form-actions [type="button"]');
assert.strictEqual(currentURL(), urls.targets);
@@ -218,10 +272,11 @@ module('Acceptance | targets | create', function (hooks) {
const targetCount = getTargetCount();
const sshTargetCount = getSSHTargetCount();
await visit(urls.targets);
await click(`[href="${urls.newTarget}"]`);
await fillIn('[name="name"]', 'random string');
await click('[value="ssh"]');
await click('.hds-form-toggle__control', 'Egress worker filter');
await fillIn('[name="egress_worker_filter"]', 'random filter');
await click('.rose-form-actions [type="button"]');
assert.strictEqual(currentURL(), urls.targets);
@@ -106,10 +106,76 @@ module('Acceptance | targets | update', function (hooks) {
assert.dom('[name=worker_filter]').isDisabled();
});
test('show update filter button when the old worker filter field is not empty', async function (assert) {
featuresService.enable('target-worker-filters-v2');
assert.expect(2);
await visit(urls.target);
assert.dom('[name=worker_filter]').isVisible();
await click('.rose-form-actions [type="button"]', 'Activate edit mode');
assert.dom('.hds-button').hasText('Update Filter');
});
test('onClick update filter should select the egress toggle and the worker_filter value is copied into egress_worker_filter', async function (assert) {
featuresService.enable('target-worker-filters-v2');
assert.expect(2);
await visit(urls.target);
assert.dom('[name=worker_filter]').isVisible();
const worker_filter_value = this.server.schema.targets.first().workerFilter;
await click('.rose-form-actions [type="button"]', 'Activate edit mode');
await click('.hds-button[type="button"]', 'Update Filter');
assert.strictEqual(
this.server.schema.targets.first().egressWorkerFilter,
worker_filter_value
);
});
test('show filter input field when the `egress_worker_filter` toggle is on', async function (assert) {
featuresService.enable('target-worker-filters-v2');
assert.expect(1);
await visit(urls.target);
await click('.rose-form-actions [type="button"]', 'Activate edit mode');
await click('.hds-button[type="button"]', 'Update Filter');
assert.dom('[name=egress_worker_filter]').isVisible();
});
test('hide filter input field when the `egress_worker_filter` toggled is off', async function (assert) {
featuresService.enable('target-worker-filters-v2');
assert.expect(1);
await visit(urls.target);
await click('.rose-form-actions [type="button"]', 'Activate edit mode');
await click('.hds-button[type="button"]', 'Update Filter');
await click('.hds-form-toggle__control', 'Egress worker filter');
assert.dom('[name=egress_worker_filter]').isNotVisible();
});
test('clear `egress_worker_field` value from a target when the toggle is off and form is saved', async function (assert) {
featuresService.enable('target-worker-filters-v2');
assert.expect(5);
await visit(urls.target);
await click('.rose-form-actions [type="button"]', 'Activate edit mode');
await click('.hds-button[type="button"]', 'Update Filter');
await fillIn('[name=egress_worker_filter]', 'random filter string');
await click('.rose-form-actions [type="submit"]');
assert.strictEqual(currentURL(), urls.target);
assert.strictEqual(
this.server.schema.targets.first().egressWorkerFilter,
'random filter string'
);
await click('.rose-form-actions [type="button"]', 'Activate edit mode');
await click('.hds-form-toggle__control', 'Egress worker filter');
await click('.rose-form-actions [type="submit"]');
//clear egress_worker_filter when the toggle is off
assert.strictEqual(currentURL(), urls.target);
assert.dom('[name=egress_worker_filter]').doesNotExist();
assert.strictEqual(
this.server.schema.targets.first().egressWorkerFilter,
null
);
});
test('can cancel changes to existing target', async function (assert) {
assert.expect(2);
await visit(urls.targets);
await click(`[href="${urls.target}"]`);
await click('.rose-form-actions [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
@@ -152,15 +218,22 @@ module('Acceptance | targets | update', function (hooks) {
});
test('can discard unsaved target changes via dialog', async function (assert) {
assert.expect(5);
featuresService.enable('target-worker-filters-v2');
assert.expect(7);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
assert.notEqual(instances.target.name, 'random string');
assert.notEqual(
instances.target.egressWorkerFilter,
'random worker string'
);
await visit(urls.targets);
await click(`[href="${urls.target}"]`);
await click('.rose-form-actions [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
await click('.hds-button[type="button"]', 'Update Filter');
await fillIn('[name="egress_worker_filter"]', 'random worker string');
assert.strictEqual(currentURL(), urls.target);
await click(`[href="${urls.targets}"]`);
assert.dom('.rose-dialog').exists();
@@ -168,10 +241,15 @@ module('Acceptance | targets | update', function (hooks) {
assert.strictEqual(currentURL(), urls.targets);
assert.notEqual(this.server.schema.targets.first().name, 'random string');
assert.notEqual(
this.server.schema.targets.first().egressWorkerFilter,
'random worker string'
);
});
test('can click cancel on discard dialog box for unsaved target changes', async function (assert) {
assert.expect(5);
featuresService.enable('target-worker-filters-v2');
assert.expect(6);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
assert.notEqual(instances.target.name, 'random string');
@@ -180,6 +258,9 @@ module('Acceptance | targets | update', function (hooks) {
await click(`[href="${urls.target}"]`);
await click('.rose-form-actions [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
await click('.hds-button[type="button"]', 'Update Filter');
await fillIn('[name="egress_worker_filter"]', 'random filter');
assert.strictEqual(currentURL(), urls.target);
await click(`[href="${urls.targets}"]`);
assert.dom('.rose-dialog').exists();
@@ -187,6 +268,10 @@ module('Acceptance | targets | update', function (hooks) {
assert.strictEqual(currentURL(), urls.target);
assert.notEqual(this.server.schema.targets.first().name, 'random string');
assert.notEqual(
this.server.schema.targets.first().egressWorkerFilter,
'random string'
);
});
test('cannot make changes to an existing target without proper authorization', async function (assert) {