From 2a49d4601f23077354a4e751b841821ff94e87c0 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 17 Aug 2020 12:25:07 -0400 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20new=20org=20functi?= =?UTF-8?q?onality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/core/app/components/form/org/index.hbs | 49 ++++++++++++ ui/core/app/routes/scopes/scope/orgs.js | 41 ++++++++++ .../app/templates/scopes/scope/orgs/new.hbs | 6 +- ui/core/tests/acceptance/orgs-test.js | 76 +++++++++++++++++++ .../integration/components/form/org-test.js | 23 ++++++ 5 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 ui/core/app/components/form/org/index.hbs create mode 100644 ui/core/tests/acceptance/orgs-test.js create mode 100644 ui/core/tests/integration/components/form/org-test.js diff --git a/ui/core/app/components/form/org/index.hbs b/ui/core/app/components/form/org/index.hbs new file mode 100644 index 000000000..45adc26d0 --- /dev/null +++ b/ui/core/app/components/form/org/index.hbs @@ -0,0 +1,49 @@ + + + + {{#if @model.errors.name}} + + {{#each @model.errors.name as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + + + {{#if @model.errors.description}} + + {{#each @model.errors.description as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + + + + diff --git a/ui/core/app/routes/scopes/scope/orgs.js b/ui/core/app/routes/scopes/scope/orgs.js index e8b0375b9..f25a91cf9 100644 --- a/ui/core/app/routes/scopes/scope/orgs.js +++ b/ui/core/app/routes/scopes/scope/orgs.js @@ -1,7 +1,14 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; export default class ScopesScopeOrgsRoute extends Route { + // =services + + @service intl; + @service notify; + // =methods /** @@ -12,4 +19,38 @@ export default class ScopesScopeOrgsRoute extends Route { return this.store.query('scope', { scope_id: 'global' }); } + // =actions + + /** + * Rollback changes on org. + * @param {ScopeModel} org + */ + @action + cancel(org) { + const { isNew } = org; + org.rollbackAttributes(); + if (isNew) this.transitionTo('scopes.scope.orgs'); + } + + /** + * Handle save org. + * @param {ScopeModel} org + * @param {Event} e + */ + @action + async save(org) { + const { isNew } = org; + try { + await org.save(); + this.refresh(); + this.notify.success( + this.intl.t(isNew ? 'notify.create-success' : 'notify.save-success') + ); + this.transitionTo('scopes.scope', org); + } catch (error) { + // TODO: replace with translated strings + this.notify.error(error.message, { closeAfter: null }); + } + } + } diff --git a/ui/core/app/templates/scopes/scope/orgs/new.hbs b/ui/core/app/templates/scopes/scope/orgs/new.hbs index 0e12b352e..d9fe8b361 100644 --- a/ui/core/app/templates/scopes/scope/orgs/new.hbs +++ b/ui/core/app/templates/scopes/scope/orgs/new.hbs @@ -11,7 +11,11 @@ - + diff --git a/ui/core/tests/acceptance/orgs-test.js b/ui/core/tests/acceptance/orgs-test.js new file mode 100644 index 000000000..5871fd404 --- /dev/null +++ b/ui/core/tests/acceptance/orgs-test.js @@ -0,0 +1,76 @@ +import { module, test } from 'qunit'; +//import { visit, currentURL, click, fillIn, find } 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 { + //authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | org', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + // let org; + // let orgID; + // let orgsURL; + // let newOrgURL; + // let existingOrg; + // let existingOrgURL; + // let getOrgScopesCount; + // let getFirstOrgScope; + // let initialOrgScopesCount; + // + // hooks.beforeEach(function () { + // authenticateSession({}); + // + // }); + + test('visiting orgs', async function (assert) { + assert.expect(0); + }); + + test('visiting orgs within a org scope redirects to the parent org scope', async function (assert) { + assert.expect(0); + }); + + test('can create new orgs', async function (assert) { + assert.expect(0); + }); + + test('can cancel create new orgs', async function (assert) { + assert.expect(0); + }); + + test('saving a new org with invalid fields displays error messages', async function (assert) { + assert.expect(0); + }); + + test('can save changes to existing org', async function (assert) { + assert.expect(0); + }); + + test('can cancel changes to existing org', async function (assert) { + assert.expect(0); + }); + + test('can delete org', async function (assert) { + assert.expect(0); + }); + + test('saving an existing org with invalid fields displays error messages', async function (assert) { + assert.expect(0); + }); + + test('errors are displayed when save org fails', async function (assert) { + assert.expect(0); + }); + + test('errors are displayed when delete org fails', async function (assert) { + assert.expect(0); + }); +}); diff --git a/ui/core/tests/integration/components/form/org-test.js b/ui/core/tests/integration/components/form/org-test.js new file mode 100644 index 000000000..76c3d9b8f --- /dev/null +++ b/ui/core/tests/integration/components/form/org-test.js @@ -0,0 +1,23 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render, find } from '@ember/test-helpers'; +import { hbs } from 'ember-cli-htmlbars'; + +module('Integration | Component | form/org', function(hooks) { + setupRenderingTest(hooks); + + test('it renders', async function (assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.set('myAction', function(val) { ... }); + this.submit = () => {}; + this.cancel = () => {}; + + await render(hbs` + `); + + assert.ok(find('form')); + }); +});