Refactor: Onboarding tests selectors refactor (#2715)
* refactor: 💡 Onboarding tests Refactor test selectors for onboarding acceptance tests ✅ Closes: #ICU-16398, #ICU-16399 * fix: 🐛 failing test * chore: 🤖 add copyright header * fix: 🐛 use AAA pattern and server.schema * fix: 🐛 moved done button to selectors * fix: 🐛 renamed copy text btn selector
This commit is contained in:
1 parent
6a46e2dd57
commit
34a670f8d7
3 files changed
+53
-20
No files matched your search
@@ -8,6 +8,8 @@ import { setupApplicationTest } from 'admin/tests/helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { visit, fillIn, click, currentURL } from '@ember/test-helpers';
|
||||
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
||||
import * as selectors from './selectors';
|
||||
|
||||
module('Acceptance | onboarding', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
@@ -25,21 +27,32 @@ module('Acceptance | onboarding', function (hooks) {
|
||||
|
||||
test('show targetAddress and targetPort fields', async function (assert) {
|
||||
await visit(urls.onboarding);
|
||||
assert.dom('[name="targetAddress"]').isVisible();
|
||||
assert.dom('[name="targetPort"]').isVisible();
|
||||
|
||||
assert.dom(selectors.FIELD_TARGET_ADDRESS).isVisible();
|
||||
assert.dom(selectors.FIELD_TARGET_PORT).isVisible();
|
||||
});
|
||||
|
||||
test('redirect user to success when fill targetAddress, targetPort and click Save', async function (assert) {
|
||||
await visit(urls.onboarding);
|
||||
await fillIn('[name="targetAddress"]', '192.168.1.0');
|
||||
await fillIn('[name="targetPort"]', '22');
|
||||
await click('[type="submit"]');
|
||||
|
||||
await fillIn(
|
||||
selectors.FIELD_TARGET_ADDRESS,
|
||||
selectors.FIELD_TARGET_ADDRESS_VALUE,
|
||||
);
|
||||
await fillIn(
|
||||
selectors.FIELD_TARGET_PORT,
|
||||
selectors.FIELD_TARGET_PORT_VALUE,
|
||||
);
|
||||
await click(commonSelectors.SAVE_BTN);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.success);
|
||||
});
|
||||
|
||||
test('redirect user to orgs screen when click do this later', async function (assert) {
|
||||
await visit(urls.onboarding);
|
||||
await click('.rose-form-actions [type="button"]');
|
||||
|
||||
await click(selectors.DO_THIS_LATER_BTN);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.orgs);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
export const DO_THIS_LATER_BTN = '.rose-form-actions [type="button"]';
|
||||
export const COPY_TEXT_BTN = '.hds-copy-snippet__text';
|
||||
export const FIELD_TARGET_ADDRESS = '[name="targetAddress"]';
|
||||
export const FIELD_TARGET_ADDRESS_VALUE = '192.168.1.0';
|
||||
export const FIELD_TARGET_PORT = '[name="targetPort"]';
|
||||
export const FIELD_TARGET_PORT_VALUE = '22';
|
||||
export const DONE_BTN = '[data-test-onboarding-done-button]';
|
||||
@@ -4,10 +4,12 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, find, click, fillIn } from '@ember/test-helpers';
|
||||
import { visit, currentURL, click, fillIn } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'admin/tests/helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import * as selectors from './selectors';
|
||||
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
||||
|
||||
module('Acceptance | onboarding | success', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
@@ -22,32 +24,38 @@ module('Acceptance | onboarding | success', function (hooks) {
|
||||
success: '/onboarding/success',
|
||||
target: null,
|
||||
};
|
||||
const doneButtonSelector = '[data-test-onboarding-done-button]';
|
||||
|
||||
test('check if the done button is present', async function (assert) {
|
||||
await visit(urls.success);
|
||||
assert.dom(doneButtonSelector).isVisible();
|
||||
|
||||
assert.dom(selectors.DONE_BTN).isVisible();
|
||||
});
|
||||
|
||||
test('check the controller url is copyable', async function (assert) {
|
||||
const origin = window.location.origin;
|
||||
await visit(urls.success);
|
||||
assert.dom('.hds-copy-snippet__text').isVisible();
|
||||
assert.strictEqual(
|
||||
find('.hds-copy-snippet__text').textContent.trim(),
|
||||
origin,
|
||||
);
|
||||
|
||||
assert.dom(selectors.COPY_TEXT_BTN).isVisible().hasText(origin);
|
||||
});
|
||||
|
||||
test('fill the onboarding form and redirect user to target detail when done is clicked', async function (assert) {
|
||||
await visit(urls.onboarding);
|
||||
await fillIn('[name="targetAddress"]', '0.0.0.0');
|
||||
await fillIn('[name="targetPort"]', '22');
|
||||
await click('[type="submit"]');
|
||||
await click(doneButtonSelector);
|
||||
const projectId = this.server.db.scopes.where({ type: 'project' })[0].id;
|
||||
const targetId = this.server.db.targets[0].id;
|
||||
await fillIn(
|
||||
selectors.FIELD_TARGET_ADDRESS,
|
||||
selectors.FIELD_TARGET_ADDRESS_VALUE,
|
||||
);
|
||||
await fillIn(
|
||||
selectors.FIELD_TARGET_PORT,
|
||||
selectors.FIELD_TARGET_PORT_VALUE,
|
||||
);
|
||||
await click(commonSelectors.SAVE_BTN);
|
||||
|
||||
await click(selectors.DONE_BTN);
|
||||
const projectId = this.server.schema.scopes.where({ type: 'project' })
|
||||
.models[0].id;
|
||||
const targetId = this.server.schema.targets.all().models[0].id;
|
||||
urls.target = `/scopes/${projectId}/targets/${targetId}`;
|
||||
|
||||
assert.strictEqual(currentURL(), urls.target);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user