Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ember-modal-dialog deprecation warning
- Loading branch information
Showing
17 changed files
with
367 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Controller from '@ember/controller'; | ||
import { get, set } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
export default Controller.extend({ | ||
flashMessages: service(), | ||
|
||
async approve(project) { | ||
set(project, 'approved', true); | ||
let title = get(project, 'title'); | ||
project.save().then(() => { | ||
get(this, 'flashMessages').clearMessages().success(`You approved ${title}.`); | ||
}).catch(() => { | ||
project.rollbackAttributes(); | ||
get(this, 'flashMessages').clearMessages().danger(`An error occurred while approving ${title}.`); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default Route.extend({ | ||
model() { | ||
return this.store.findAll('project'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div data-test-page-menu class="page-menu page-menu--horizontal"> | ||
<div class="container"> | ||
<ul> | ||
<li> | ||
{{link-to "Projects" "admin.projects.index" data-test-index-link}} | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
{{outlet}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<div class="log-rows"> | ||
<div data-test-log-row-header class="log-row log-row--header"> | ||
<span class="log-cell log-cell--shrink"></span> | ||
<span class="log-cell log-cell--shrink">Project</span> | ||
<span class="log-cell log-cell--shrink">Organization</span> | ||
<span class="log-cell">Status</span> | ||
<span class="log-cell log-cell--shrink">Approval</span> | ||
</div> | ||
|
||
{{#each model as |project|}} | ||
<div data-test-log-row class="log-row"> | ||
<span data-test-icon class="log-cell log-cell--shrink"> | ||
{{#if project.iconThumbUrl}} | ||
{{#link-to 'project' project.organization.slug project.slug}} | ||
<img class="icon icon--small" width="35" height="35" src="{{project.iconThumbUrl}}" /> | ||
{{/link-to}} | ||
{{else}} | ||
<div class="icon icon--small"></div> | ||
{{/if}} | ||
</span> | ||
<span data-test-title class="log-cell log-cell--shrink"> | ||
{{#link-to 'project' project.organization.slug project.slug}} | ||
{{project.title}} | ||
{{/link-to}} | ||
</span> | ||
<span data-test-organization class="log-cell log-cell--shrink"> | ||
{{#link-to 'slugged-route' project.organization.slug}} | ||
{{project.organization.name}} | ||
{{/link-to}} | ||
</span> | ||
<span data-test-approval-status class="log-cell"> | ||
{{#if project.isSaving}} | ||
{{fa-icon "ellipsis-h"}} Saving... | ||
{{else if project.approved}} | ||
<span class="log-data--success"> | ||
{{fa-icon "check-circle"}} Approved | ||
</span> | ||
{{else if project.approvalRequested}} | ||
{{fa-icon "question-circle"}} Pending approval | ||
{{else}} | ||
{{fa-icon "asterisk"}} Created | ||
{{/if}} | ||
</span> | ||
<span data-test-actions class="log-cell log-cell--shrink"> | ||
{{#if (and project.approvalRequested (not project.approved))}} | ||
<button {{action approve project}} class="default small">Approve</button> | ||
{{/if}} | ||
</span> | ||
</div> | ||
{{/each}} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { test } from 'qunit'; | ||
import moduleForAcceptance from 'code-corps-ember/tests/helpers/module-for-acceptance'; | ||
import { authenticateSession } from 'code-corps-ember/tests/helpers/ember-simple-auth'; | ||
import page from 'code-corps-ember/tests/pages/admin/projects/index'; | ||
import Mirage from 'ember-cli-mirage'; | ||
|
||
moduleForAcceptance('Acceptance | Admin | Projects'); | ||
|
||
test('The page requires logging in', function(assert) { | ||
assert.expect(1); | ||
|
||
page.visit(); | ||
|
||
andThen(() => { | ||
assert.equal(currentRouteName(), 'login', 'Got redirected to login'); | ||
}); | ||
}); | ||
|
||
test('The page requires user to be admin', function(assert) { | ||
assert.expect(2); | ||
|
||
let user = server.create('user', { admin: false, id: 1 }); | ||
authenticateSession(this.application, { user_id: user.id }); | ||
|
||
page.visit(); | ||
|
||
andThen(() => { | ||
assert.equal(page.flashErrors().count, 1, 'Flash error was rendered'); | ||
assert.equal(currentRouteName(), 'projects-list', 'Got redirected'); | ||
}); | ||
}); | ||
|
||
test('An admin can view a list of projects', function(assert) { | ||
assert.expect(15); | ||
|
||
let user = server.create('user', { admin: true, id: 1 }); | ||
|
||
let unapprovedProject = server.create('project', { approvalRequested: false, approved: false }); | ||
let projectPendingApproval = server.create('project', { approvalRequested: true, approved: false }); | ||
let approvedProject = server.create('project', { approvalRequested: true, approved: true }); | ||
|
||
[unapprovedProject, projectPendingApproval, approvedProject] | ||
.map(({ organization }) => organization) | ||
.forEach((organization) => server.create('slugged-route', { organization })); | ||
|
||
authenticateSession(this.application, { user_id: user.id }); | ||
|
||
page.visit(); | ||
|
||
andThen(() => { | ||
assert.equal(currentURL(), '/admin/projects'); | ||
assert.equal(currentRouteName(), 'admin.projects.index'); | ||
|
||
assert.equal(page.items().count, 3, 'There are 3 rows.'); | ||
|
||
[unapprovedProject, projectPendingApproval, approvedProject].forEach((project, index) => { | ||
assert.equal(page.items(index).title.text, project.title, 'Project title is rendered.'); | ||
assert.equal(page.items(index).icon.src, project.iconThumbUrl, 'Project icon is rendered.'); | ||
}); | ||
|
||
assert.equal(page.items(0).approvalStatus.text, 'Created', 'Correct status is rendered for newly created project.'); | ||
assert.notOk(page.items(0).actions.approve.isVisible, 'Approve button is not rendered for newly created project.'); | ||
|
||
assert.equal(page.items(1).approvalStatus.text, 'Pending approval', 'Correct status is rendered for project pending approval.'); | ||
assert.ok(page.items(1).actions.approve.isVisible, 'Approve button is rendered for project pending approval.'); | ||
|
||
assert.equal(page.items(2).approvalStatus.text, 'Approved', 'Correct status is rendered for approved project.'); | ||
assert.notOk(page.items(2).actions.approve.isVisible, 'Approve button is not rendered for approved project'); | ||
}); | ||
}); | ||
|
||
test('An admin can approve a project', function(assert) { | ||
assert.expect(2); | ||
|
||
let user = server.create('user', { admin: true, id: 1 }); | ||
let unapprovedProject = server.create('project', { approved: false, approvalRequested: true }); | ||
|
||
authenticateSession(this.application, { user_id: user.id }); | ||
|
||
page.visit(); | ||
|
||
andThen(() => { | ||
page.items(0).actions.approve.click(); | ||
}); | ||
|
||
andThen(() => { | ||
assert.ok(unapprovedProject.approved, 'Project is approved.'); | ||
assert.equal(page.items(0).approvalStatus.text, 'Approved', 'Project status is rendered correctly.'); | ||
}); | ||
}); | ||
|
||
test('A flash error renders when project approval fails', function(assert) { | ||
assert.expect(1); | ||
|
||
let user = server.create('user', { admin: true, id: 1 }); | ||
let project = server.create('project', { approved: false, approvalRequested: true }); | ||
|
||
authenticateSession(this.application, { user_id: user.id }); | ||
|
||
page.visit(); | ||
|
||
let done = assert.async(); | ||
|
||
server.patch(`/projects/${project.id}`, function() { | ||
done(); | ||
return new Mirage.Response(500, {}, { | ||
errors: [ | ||
{ | ||
title: '500 Internal Server Error', | ||
detail: '500 Internal Server Error', | ||
status: 500 | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
andThen(() => { | ||
page.items(0).actions.approve.click(); | ||
}); | ||
|
||
andThen(() => { | ||
assert.equal(page.flashErrors().count, 1, 'FLash error is rendered.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.