feat: 🎸 reintroduce targets
This commit is contained in:
23 files changed
+773
-10
No files matched your search
@@ -0,0 +1,115 @@
|
||||
<Rose::Form
|
||||
@onSubmit={{@submit}}
|
||||
@cancel={{@cancel}}
|
||||
@disabled={{@model.isSaving}}
|
||||
@error={{@model.errors.base}}
|
||||
@showEditToggle={{if @model.isNew false true}}
|
||||
as |form|
|
||||
>
|
||||
|
||||
<form.input
|
||||
@value={{@model.type}}
|
||||
@label={{t "form.type.label"}}
|
||||
readonly={{true}}
|
||||
@disabled={{true}} />
|
||||
|
||||
<form.input
|
||||
@name="name"
|
||||
@type="text"
|
||||
@value={{@model.name}}
|
||||
@label={{t "form.name.label"}}
|
||||
@helperText={{t "form.name.help"}}
|
||||
@error={{@model.errors.name}}
|
||||
as |field|>
|
||||
{{#if @model.errors.name}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.name as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.input>
|
||||
|
||||
<form.textarea
|
||||
@name="description"
|
||||
@type="text"
|
||||
@value={{@model.description}}
|
||||
@label={{t "form.description.label"}}
|
||||
@helperText={{t "form.description.help"}}
|
||||
@error={{@model.errors.description}}
|
||||
as |field|>
|
||||
{{#if @model.errors.description}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.description as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.textarea>
|
||||
|
||||
<form.input
|
||||
@name="session_max_seconds"
|
||||
@type="number"
|
||||
@value={{@model.session_max_seconds}}
|
||||
@label={{t "form.session_max_seconds.label"}}
|
||||
@error={{@model.errors.session_max_seconds}}
|
||||
@helperText={{t "form.session_max_seconds.help"}}
|
||||
min="0"
|
||||
step="1"
|
||||
as |field|>
|
||||
{{#if @model.errors.session_max_seconds}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.session_max_seconds as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.input>
|
||||
|
||||
<form.input
|
||||
@name="session_connection_limit"
|
||||
@type="number"
|
||||
@value={{@model.session_connection_limit}}
|
||||
@label={{t "form.session_connection_limit.label"}}
|
||||
@error={{@model.errors.session_connection_limit}}
|
||||
@helperText={{t "form.session_connection_limit.help"}}
|
||||
min="-1"
|
||||
step="1"
|
||||
as |field|>
|
||||
{{#if @model.errors.session_connection_limit}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.session_connection_limit as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.input>
|
||||
|
||||
{{!-- TODO this is a type-specific field --}}
|
||||
<form.input
|
||||
@name="default_port"
|
||||
@type="number"
|
||||
@value={{@model.attributes.default_port}}
|
||||
@label={{t "form.default_port.label"}}
|
||||
@error={{@model.errors.default_port}}
|
||||
@helperText={{t "form.default_port.help"}}
|
||||
min="0"
|
||||
step="1"
|
||||
as |field|>
|
||||
{{!-- TODO need to figure out how to reference `attributes.errors` here --}}
|
||||
{{#if @model.errors.default_port}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.default_port as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.input>
|
||||
|
||||
<form.actions
|
||||
@disabled={{if @model.cannotSave @model.cannotSave}}
|
||||
@enableEditText={{t "actions.edit-form"}}
|
||||
@submitText={{t "actions.save"}}
|
||||
@cancelText={{t "actions.cancel"}} />
|
||||
|
||||
</Rose::Form>
|
||||
+11
-6
@@ -9,13 +9,14 @@ export default class Router extends EmberRouter {
|
||||
Router.map(function () {
|
||||
this.route('scopes', function () {
|
||||
this.route('scope', { path: ':scope_id' }, function () {
|
||||
|
||||
this.route('authenticate', function () {
|
||||
this.route('method', { path: ':auth_method_id' });
|
||||
});
|
||||
|
||||
this.route('orgs', function () {
|
||||
this.route('new');
|
||||
});
|
||||
this.route('scopes', function() {});
|
||||
this.route('edit');
|
||||
this.route('new');
|
||||
|
||||
this.route('users', function () {
|
||||
this.route('user', { path: ':user_id' }, function () {
|
||||
@@ -53,10 +54,14 @@ Router.map(function () {
|
||||
});
|
||||
this.route('new');
|
||||
});
|
||||
this.route('scopes', function() {});
|
||||
this.route('edit');
|
||||
this.route('new');
|
||||
|
||||
this.route('sessions', function() {});
|
||||
|
||||
this.route('targets', function() {
|
||||
this.route('target', { path: ':target_id' }, function() {});
|
||||
this.route('new');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import loading from 'ember-loading/decorator';
|
||||
import { confirm } from '../../../decorators/confirm';
|
||||
import { notifySuccess, notifyError } from '../../../decorators/notify';
|
||||
|
||||
export default class ScopesScopeTargetsRoute extends Route {
|
||||
// =services
|
||||
|
||||
@service intl;
|
||||
@service notify;
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Loads all targets under current scope.
|
||||
* @return {Promise{[TargetModel]}}
|
||||
*/
|
||||
async model() {
|
||||
const { id: scope_id } = this.modelFor('scopes.scope');
|
||||
return this.store.query('target', { scope_id });
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Rollback changes on a target.
|
||||
* @param {TargetModel} target
|
||||
*/
|
||||
@action
|
||||
cancel(target) {
|
||||
const { isNew } = target;
|
||||
target.rollbackAttributes();
|
||||
if (isNew) this.transitionTo('scopes.scope.targets');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle save.
|
||||
* @param {TargetModel} target
|
||||
* @param {Event} e
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess(({ isNew }) => isNew ? 'notifications.create-success' : 'notifications.save-success')
|
||||
async save(target) {
|
||||
await target.save();
|
||||
await this.transitionTo('scopes.scope.targets.target', target);
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a target and redirects to targets index.
|
||||
* @param {TargetModel} target
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('questions.delete-confirm')
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.delete-success')
|
||||
async delete(target) {
|
||||
await target.destroyRecord();
|
||||
await this.replaceWith('scopes.scope.targets');
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeTargetsIndexRoute extends Route {
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeTargetsNewRoute extends Route {
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Creates a new unsaved target in current scope.
|
||||
* @return {TargetModel}
|
||||
*/
|
||||
model() {
|
||||
const scopeModel = this.modelFor('scopes.scope');
|
||||
return this.store.createRecord('target', {
|
||||
type: 'tcp',
|
||||
scopeModel,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeTargetsTargetRoute extends Route {
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Load a target.
|
||||
* @param {object} params
|
||||
* @param {string} params.target_id
|
||||
* @return {TargetModel}
|
||||
*/
|
||||
async model({ target_id }) {
|
||||
return this.store.findRecord('target', target_id, { reload: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the target-specific templates for header, navigation,
|
||||
* and actions page sections.
|
||||
* @override
|
||||
*/
|
||||
renderTemplate() {
|
||||
super.renderTemplate(...arguments);
|
||||
|
||||
this.render('scopes/scope/targets/target/-header', {
|
||||
into: 'scopes/scope/targets/target',
|
||||
outlet: 'header',
|
||||
});
|
||||
|
||||
this.render('scopes/scope/targets/target/-navigation', {
|
||||
into: 'scopes/scope/targets/target',
|
||||
outlet: 'navigation',
|
||||
});
|
||||
|
||||
this.render('scopes/scope/targets/target/-actions', {
|
||||
into: 'scopes/scope/targets/target',
|
||||
outlet: 'actions',
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeTargetsTargetIndexRoute extends Route {
|
||||
}
|
||||
@@ -75,14 +75,14 @@
|
||||
@size="medium" />
|
||||
{{t "resources.session.title_plural"}}
|
||||
</nav.link>
|
||||
{{!--
|
||||
<nav.link @route="scopes.scope.projects.project.targets">
|
||||
<nav.link @route="scopes.scope.targets">
|
||||
<Rose::Icon
|
||||
@name="app-icons/target"
|
||||
@size="medium" />
|
||||
{{t "resources.target.title_plural"}}
|
||||
</nav.link>
|
||||
<nav.link @route="scopes.scope.projects.project.host-catalogs">
|
||||
{{!--
|
||||
<nav.link @route="scopes.scope.host-catalogs">
|
||||
<Rose::Icon
|
||||
@name="app-icons/host-catalogs"
|
||||
@size="medium" />
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{{title (t "resources.target.title_plural")}}
|
||||
|
||||
{{outlet}}
|
||||
@@ -0,0 +1,88 @@
|
||||
<Rose::Layout::Page as |page|>
|
||||
|
||||
<page.breadcrumbs>
|
||||
<BreadCrumbs />
|
||||
</page.breadcrumbs>
|
||||
|
||||
<page.header>
|
||||
<h2>
|
||||
{{t "resources.target.title_plural"}}
|
||||
<DocLink @doc="target" @iconSize="large" />
|
||||
</h2>
|
||||
{{#if @model}}
|
||||
<p>{{t "resources.target.description"}}</p>
|
||||
{{/if}}
|
||||
</page.header>
|
||||
|
||||
<page.actions>
|
||||
{{#if @model}}
|
||||
<Rose::LinkButton @route="scopes.scope.targets.new" @style="primary">
|
||||
{{t "titles.new"}}
|
||||
</Rose::LinkButton>
|
||||
{{/if}}
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
|
||||
{{#if @model}}
|
||||
|
||||
<Rose::Table as |table|>
|
||||
<table.header as |header|>
|
||||
<header.row as |row|>
|
||||
<row.headerCell>{{t "form.name.label"}}</row.headerCell>
|
||||
<row.headerCell>{{t "form.type.label"}}</row.headerCell>
|
||||
<row.headerCell>{{t "form.id.label"}}</row.headerCell>
|
||||
</header.row>
|
||||
</table.header>
|
||||
<table.body as |body|>
|
||||
{{#each @model as |target|}}
|
||||
<body.row as |row|>
|
||||
<row.headerCell>
|
||||
<LinkTo
|
||||
@route="scopes.scope.targets.target"
|
||||
@model={{target.id}}
|
||||
>
|
||||
{{target.displayName}}
|
||||
</LinkTo>
|
||||
<p>{{target.description}}</p>
|
||||
</row.headerCell>
|
||||
<row.cell>
|
||||
{{#if target.type}}
|
||||
<Rose::Badge>
|
||||
{{t (concat "resources.target.types." target.type)}}
|
||||
</Rose::Badge>
|
||||
{{/if}}
|
||||
</row.cell>
|
||||
<row.cell>
|
||||
<Copyable
|
||||
@text={{target.id}}
|
||||
@buttonText={{t "actions.copy-to-clipboard"}}
|
||||
@acknowledgeText={{t "states.copied"}}
|
||||
>
|
||||
<code>{{target.id}}</code>
|
||||
</Copyable>
|
||||
</row.cell>
|
||||
</body.row>
|
||||
{{/each}}
|
||||
</table.body>
|
||||
</Rose::Table>
|
||||
|
||||
{{else}}
|
||||
|
||||
<Rose::Layout::Centered>
|
||||
<Rose::Message @title={{t "resources.target.messages.welcome.title"}} as |message|>
|
||||
<message.description>
|
||||
{{t "resources.target.description"}}
|
||||
</message.description>
|
||||
<message.link @route="scopes.scope.targets.new">
|
||||
<Rose::Icon @name="plus-circle-outline" />
|
||||
{{t "titles.new"}}
|
||||
</message.link>
|
||||
</Rose::Message>
|
||||
</Rose::Layout::Centered>
|
||||
|
||||
{{/if}}
|
||||
|
||||
</page.body>
|
||||
|
||||
</Rose::Layout::Page>
|
||||
@@ -0,0 +1,24 @@
|
||||
{{title (t 'titles.new')}}
|
||||
|
||||
<Rose::Layout::Page as |page|>
|
||||
|
||||
<page.breadcrumbs>
|
||||
<BreadCrumbs />
|
||||
</page.breadcrumbs>
|
||||
|
||||
<page.header>
|
||||
<h2>
|
||||
{{t "titles.new"}}
|
||||
<DocLink @doc="target.new" @iconSize="large" />
|
||||
</h2>
|
||||
</page.header>
|
||||
|
||||
<page.body>
|
||||
<Form::Target
|
||||
@model={{@model}}
|
||||
@submit={{route-action "save" @model}}
|
||||
@cancel={{route-action "cancel" @model}}
|
||||
/>
|
||||
</page.body>
|
||||
|
||||
</Rose::Layout::Page>
|
||||
@@ -0,0 +1,25 @@
|
||||
{{title @model.displayName}}
|
||||
|
||||
<Rose::Layout::Page as |page|>
|
||||
|
||||
<page.breadcrumbs>
|
||||
<BreadCrumbs />
|
||||
</page.breadcrumbs>
|
||||
|
||||
<page.header>
|
||||
{{outlet "header"}}
|
||||
</page.header>
|
||||
|
||||
<page.navigation>
|
||||
{{outlet "navigation"}}
|
||||
</page.navigation>
|
||||
|
||||
<page.actions>
|
||||
{{outlet "actions"}}
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
{{outlet}}
|
||||
</page.body>
|
||||
|
||||
</Rose::Layout::Page>
|
||||
@@ -0,0 +1,15 @@
|
||||
<Rose::Dropdown @text="{{t 'actions.manage'}}" @dropdownRight={{true}} as |dropdown|>
|
||||
{{!--
|
||||
<dropdown.link @route="scopes.scope.targets.target.add-host-sets">
|
||||
{{t 'resources.target.actions.add-host-sets'}}
|
||||
</dropdown.link>
|
||||
--}}
|
||||
<dropdown.separator />
|
||||
<dropdown.button
|
||||
@style="danger"
|
||||
@disabled={{@model.canSave}}
|
||||
{{on "click" (route-action "delete" @model)}}
|
||||
>
|
||||
{{t 'resources.target.actions.delete'}}
|
||||
</dropdown.button>
|
||||
</Rose::Dropdown>
|
||||
@@ -0,0 +1,12 @@
|
||||
<h2>
|
||||
{{t "resources.target.title"}}
|
||||
<DocLink @doc="target" @iconSize="large" />
|
||||
</h2>
|
||||
<p>{{t "resources.target.description"}}</p>
|
||||
<Copyable
|
||||
@text={{@model.id}}
|
||||
@buttonText={{t "actions.copy-to-clipboard"}}
|
||||
@acknowledgeText={{t "states.copied"}}
|
||||
>
|
||||
<code>{{@model.id}}</code>
|
||||
</Copyable>
|
||||
@@ -0,0 +1,10 @@
|
||||
<Rose::Nav::Tabs as |nav|>
|
||||
<nav.link @route='scopes.scope.targets.target.index'>
|
||||
{{t 'titles.details'}}
|
||||
</nav.link>
|
||||
{{!--
|
||||
<nav.link @route='scopes.scope.targets.target.host-sets'>
|
||||
{{t 'resources.host-set.title_plural'}}
|
||||
</nav.link>
|
||||
--}}
|
||||
</Rose::Nav::Tabs>
|
||||
@@ -0,0 +1,5 @@
|
||||
<Form::Target
|
||||
@model={{@model}}
|
||||
@submit={{route-action "save" @model}}
|
||||
@cancel={{route-action "cancel" @model}}
|
||||
/>
|
||||
@@ -41,6 +41,7 @@ module('Acceptance | scopes', function (hooks) {
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
// Generate resources
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
@@ -70,7 +71,7 @@ module('Acceptance | scopes', function (hooks) {
|
||||
urls.project2Scope = `/scopes/${instances.scopes.project2.id}`;
|
||||
urls.projectScopeEdit = `/scopes/${instances.scopes.project.id}/edit`;
|
||||
urls.project2ScopeEdit = `/scopes/${instances.scopes.project2.id}/edit`;
|
||||
// Generate scope couners
|
||||
// Generate resource couner
|
||||
getScopeCount = (type) => this.server.schema.scopes.where({ type }).length;
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,274 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, currentURL, find, click, fillIn } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { Response } from 'miragejs';
|
||||
import { resolve, reject } from 'rsvp';
|
||||
import sinon from 'sinon';
|
||||
import {
|
||||
authenticateSession,
|
||||
// These are left here intentionally for future reference.
|
||||
//currentSession,
|
||||
//invalidateSession,
|
||||
} from 'ember-simple-auth/test-support';
|
||||
|
||||
module('Acceptance | targets', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
let getTargetCount;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
org2: null,
|
||||
project: null,
|
||||
project2: null,
|
||||
}
|
||||
};
|
||||
const urls = {
|
||||
globalScope: null,
|
||||
orgScope: null,
|
||||
projectScope: null,
|
||||
targets: null,
|
||||
target: null,
|
||||
newTarget: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
// Generate resources
|
||||
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
});
|
||||
instances.scopes.project = this.server.create('scope', {
|
||||
type: 'project',
|
||||
scope: { id: instances.scopes.org.id, type: 'org' },
|
||||
});
|
||||
instances.target = this.server.create('target', {
|
||||
scope: instances.scopes.project,
|
||||
});
|
||||
// Generate route URLs for resources
|
||||
urls.globalScope = `/scopes/global/scopes`;
|
||||
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
|
||||
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
|
||||
urls.targets = `/scopes/${instances.scopes.project.id}/targets`;
|
||||
urls.target = `/scopes/${instances.scopes.project.id}/targets/${instances.target.id}`;
|
||||
urls.unknownTarget = `/scopes/${instances.scopes.project.id}/targets/foo`;
|
||||
urls.newTarget = `/scopes/${instances.scopes.project.id}/targets/new`;
|
||||
// Generate resource couner
|
||||
getTargetCount = () => this.server.schema.targets.all().models.length;
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('visiting targets', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(urls.targets);
|
||||
await a11yAudit();
|
||||
assert.equal(currentURL(), urls.targets);
|
||||
await visit(urls.target);
|
||||
await a11yAudit();
|
||||
assert.equal(currentURL(), urls.target);
|
||||
});
|
||||
|
||||
test('visiting an unknown target displays 404 message', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.unknownTarget);
|
||||
await a11yAudit();
|
||||
assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404');
|
||||
});
|
||||
|
||||
test('can create new targets', async function (assert) {
|
||||
assert.expect(1);
|
||||
const count = getTargetCount();
|
||||
await visit(urls.newTarget);
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('[type="submit"]');
|
||||
assert.equal(getTargetCount(), count + 1);
|
||||
});
|
||||
|
||||
test('can cancel create new targets', async function (assert) {
|
||||
assert.expect(2);
|
||||
const count = getTargetCount();
|
||||
await visit(urls.newTarget);
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('.rose-form-actions [type="button"]');
|
||||
assert.equal(currentURL(), urls.targets);
|
||||
assert.equal(getTargetCount(), count);
|
||||
});
|
||||
|
||||
test('saving a new target with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/targets', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
{
|
||||
status: 400,
|
||||
code: 'invalid_argument',
|
||||
message: 'The request was invalid.',
|
||||
details: {
|
||||
request_fields: [
|
||||
{
|
||||
name: 'name',
|
||||
description: 'Name is required.',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(urls.newTarget);
|
||||
await click('[type="submit"]');
|
||||
assert.ok(find('[role="alert"]').textContent.trim(), 'The request was invalid.');
|
||||
assert.ok(
|
||||
find('.rose-form-error-message').textContent.trim(),
|
||||
'Name is required.'
|
||||
);
|
||||
});
|
||||
|
||||
test('can save changes to existing target', async function (assert) {
|
||||
assert.expect(3);
|
||||
assert.notEqual(instances.target.name, 'random string');
|
||||
await visit(urls.target);
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('.rose-form-actions [type="submit"]');
|
||||
assert.equal(currentURL(), urls.target);
|
||||
assert.equal(this.server.schema.targets.all().models[0].name, 'random string');
|
||||
});
|
||||
|
||||
test('can cancel changes to existing target', async function (assert) {
|
||||
assert.expect(2);
|
||||
await visit(urls.target);
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('.rose-form-actions [type="button"]');
|
||||
assert.notEqual(instances.target.name, 'random string');
|
||||
assert.equal(find('[name="name"]').value, instances.target.name);
|
||||
});
|
||||
|
||||
test('saving an existing target with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.patch('/targets/:id', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
{
|
||||
status: 400,
|
||||
code: 'invalid_argument',
|
||||
message: 'The request was invalid.',
|
||||
details: {
|
||||
request_fields: [
|
||||
{
|
||||
name: 'name',
|
||||
description: 'Name is required.',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(urls.target);
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('[type="submit"]');
|
||||
assert.ok(find('[role="alert"]').textContent.trim(), 'The request was invalid.');
|
||||
assert.ok(
|
||||
find('.rose-form-error-message').textContent.trim(),
|
||||
'Name is required.'
|
||||
);
|
||||
});
|
||||
|
||||
test('can discard unsaved target changes via dialog', async function (assert) {
|
||||
assert.expect(5);
|
||||
const confirmService = this.owner.lookup('service:confirm');
|
||||
confirmService.enabled = true;
|
||||
assert.notEqual(instances.target.name, 'random string');
|
||||
await visit(urls.target);
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
assert.equal(currentURL(), urls.target);
|
||||
try {
|
||||
await visit(urls.targets);
|
||||
} catch (e) {
|
||||
assert.ok(find('.rose-dialog'));
|
||||
await click('.rose-dialog-footer button:first-child');
|
||||
assert.equal(currentURL(), urls.targets);
|
||||
assert.notEqual(this.server.schema.targets.all().models[0].name, 'random string');
|
||||
}
|
||||
});
|
||||
|
||||
test('can cancel discard unsaved target changes via dialog', async function (assert) {
|
||||
assert.expect(5);
|
||||
const confirmService = this.owner.lookup('service:confirm');
|
||||
confirmService.enabled = true;
|
||||
assert.notEqual(instances.target.name, 'random string');
|
||||
await visit(urls.target);
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
assert.equal(currentURL(), urls.target);
|
||||
try {
|
||||
await visit(urls.targets);
|
||||
} catch (e) {
|
||||
assert.ok(find('.rose-dialog'));
|
||||
await click('.rose-dialog-footer button:last-child');
|
||||
assert.equal(currentURL(), urls.target);
|
||||
assert.notEqual(this.server.schema.targets.all().models[0].name, 'random string');
|
||||
}
|
||||
});
|
||||
|
||||
test('can delete target', async function (assert) {
|
||||
assert.expect(1);
|
||||
const count = getTargetCount();
|
||||
await visit(urls.target);
|
||||
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
|
||||
assert.equal(getTargetCount(), count - 1);
|
||||
});
|
||||
|
||||
test('can accept delete target via dialog', async function (assert) {
|
||||
assert.expect(2);
|
||||
const confirmService = this.owner.lookup('service:confirm');
|
||||
confirmService.enabled = true;
|
||||
confirmService.confirm = sinon.fake.returns(resolve());
|
||||
const count = getTargetCount();
|
||||
await visit(urls.target);
|
||||
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
|
||||
assert.equal(getTargetCount(), count - 1);
|
||||
assert.ok(confirmService.confirm.calledOnce);
|
||||
});
|
||||
|
||||
test('cannot cancel delete target via dialog', async function (assert) {
|
||||
assert.expect(2);
|
||||
const confirmService = this.owner.lookup('service:confirm');
|
||||
confirmService.enabled = true;
|
||||
confirmService.confirm = sinon.fake.returns(reject());
|
||||
const count = getTargetCount();
|
||||
await visit(urls.target);
|
||||
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
|
||||
assert.equal(getTargetCount(), count);
|
||||
assert.ok(confirmService.confirm.calledOnce);
|
||||
});
|
||||
|
||||
test('deleting a target which errors displays error messages', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.del('/targets/:id', () => {
|
||||
return new Response(
|
||||
490,
|
||||
{},
|
||||
{
|
||||
status: 490,
|
||||
code: 'error',
|
||||
message: 'Oops.',
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(urls.target);
|
||||
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
|
||||
assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.');
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | scopes/scope/targets', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:scopes/scope/targets');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | scopes/scope/targets/index', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:scopes/scope/targets/index');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | scopes/scope/targets/new', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:scopes/scope/targets/new');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | scopes/scope/targets/target', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:scopes/scope/targets/target');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | scopes/scope/targets/target/index', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:scopes/scope/targets/target/index');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user