test: update projects acceptance tests to work with scopes

This commit is contained in:
Randall Morey committed 2020-07-23 14:50:48 -04:00
1 parent b4e8b1be8b
commit 279d552eca
2 files changed
+50 -38

No files matched your search

+50 -38
View File
@@ -9,41 +9,57 @@ module('Acceptance | projects', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
hooks.beforeEach(function () {
this.server.create('org');
});
let org;
let orgID;
let projectsURL;
let newProjectURL;
let existingProject;
let existingProjectURL;
let getProjectScopesCount;
let getFirstProjectScope;
let initialProjectScopesCount;
hooks.beforeEach(function () {
org = this.server.create('scope', {type: 'org'}, 'withChildren');
getProjectScopesCount = () => this.server.schema.scopes.where({type: 'project'}).length;
getFirstProjectScope = () => this.server.schema.scopes.where({type: 'project'}).models[0];
initialProjectScopesCount = getProjectScopesCount();
orgID = org.id;
projectsURL = `/scopes/${orgID}/projects`;
newProjectURL = `/scopes/${orgID}/projects/new`;
existingProject = getFirstProjectScope();
existingProjectURL = `/scopes/${orgID}/projects/${existingProject.id}`;
});
test('visiting projects', async function (assert) {
assert.expect(1);
this.server.createList('project', 1);
await visit('/orgs/1/projects');
await visit(projectsURL);
await a11yAudit();
assert.equal(currentURL(), '/orgs/1/projects');
assert.equal(currentURL(), projectsURL);
});
test('can create new projects', async function (assert) {
assert.expect(3);
assert.equal(this.server.db.projects.length, 0);
await visit('/orgs/1/projects/new');
assert.expect(1);
await visit(newProjectURL);
await a11yAudit();
await fillIn('[name="name"]', 'random string');
await click('[type="submit"]');
assert.equal(currentURL(), '/orgs/1/projects/1');
assert.equal(this.server.db.projects.length, 1);
assert.equal(getProjectScopesCount(), initialProjectScopesCount + 1);
});
test('can cancel create new projects', async function (assert) {
assert.expect(3);
assert.equal(this.server.db.projects.length, 0);
await visit('/orgs/1/projects/new');
assert.equal(getProjectScopesCount(), initialProjectScopesCount);
await visit(newProjectURL);
await fillIn('[name="name"]', 'random string');
await click('.rose-form-actions [type="button"]');
assert.equal(currentURL(), '/orgs/1/projects');
assert.equal(this.server.db.projects.length, 0);
assert.equal(currentURL(), projectsURL);
assert.equal(getProjectScopesCount(), initialProjectScopesCount);
});
test('saving a new project with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.post('/orgs/:org_id/projects', () => {
this.server.post('/scopes', () => {
return new Response(
400,
{},
@@ -62,8 +78,7 @@ module('Acceptance | projects', function (hooks) {
}
);
});
await visit('/orgs/1/projects/new');
await fillIn('[name="name"]', 'random string');
await visit(newProjectURL);
await click('[type="submit"]');
assert.ok(
find('[role="alert"]').textContent.trim(),
@@ -78,37 +93,35 @@ module('Acceptance | projects', function (hooks) {
});
test('can save changes to existing project', async function (assert) {
assert.expect(2);
this.server.createList('project', 1, {name: 'MyProject'});
await visit('/orgs/1/projects/1');
assert.expect(3);
assert.notEqual(existingProject.name, 'random string');
await visit(existingProjectURL);
await fillIn('[name="name"]', 'random string');
await click('.rose-form-actions [type="submit"]');
assert.equal(currentURL(), '/orgs/1/projects/1');
assert.equal(this.server.db.projects[0].name, 'random string');
assert.equal(currentURL(), existingProjectURL);
assert.equal(getFirstProjectScope().name, 'random string');
});
test('can cancel changes to existing project', async function (assert) {
assert.expect(1);
this.server.createList('project', 1, {name: 'MyProject'});
await visit('/orgs/1/projects/1');
assert.expect(2);
await visit(existingProjectURL);
await fillIn('[name="name"]', 'random string');
await click('.rose-form-actions [type="button"]');
assert.equal(find('[name="name"]').value, 'MyProject');
assert.notEqual(existingProject.name, 'random string');
assert.equal(find('[name="name"]').value, existingProject.name);
});
test('can delete project', async function(assert) {
assert.expect(2);
this.server.createList('project', 1);
assert.equal(this.server.db.projects.length, 1);
await visit('/orgs/1/projects/1');
assert.expect(1);
await visit(existingProjectURL);
await click('.rose-button-warning');
assert.equal(this.server.db.projects.length, 0);
assert.equal(getProjectScopesCount(), initialProjectScopesCount - 1);
});
test('saving an existing project with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.createList('project', 1);
this.server.patch('/orgs/:org_id/projects/:id', () => {
this.server.patch('/scopes/:id', () => {
return new Response(
400,
{},
@@ -127,7 +140,7 @@ module('Acceptance | projects', function (hooks) {
}
);
});
await visit('/orgs/1/projects/1');
await visit(existingProjectURL);
await fillIn('[name="name"]', 'random string');
await click('[type="submit"]');
assert.ok(
@@ -144,8 +157,7 @@ module('Acceptance | projects', function (hooks) {
test('errors are displayed when save project fails', async function (assert) {
assert.expect(1);
this.server.createList('project', 1);
this.server.patch('/orgs/:org_id/projects/:id', () => {
this.server.patch('/scopes/:id', () => {
return new Response(
490,
{},
@@ -156,7 +168,7 @@ module('Acceptance | projects', function (hooks) {
}
);
});
await visit('/orgs/1/projects/1');
await visit(existingProjectURL);
await fillIn('[name="name"]', 'random string');
await click('[type="submit"]');
assert.ok(
@@ -169,7 +181,7 @@ module('Acceptance | projects', function (hooks) {
test('errors are displayed when delete project fails', async function (assert) {
assert.expect(1);
this.server.createList('project', 1);
this.server.del('/orgs/:org_id/projects/:id', () => {
this.server.del('/scopes/:id', () => {
return new Response(
490,
{},
@@ -180,7 +192,7 @@ module('Acceptance | projects', function (hooks) {
}
);
});
await visit('/orgs/1/projects/1');
await visit(existingProjectURL);
await click('.rose-button-warning');
assert.ok(
find('[role="alert"]').textContent.trim(),
View File
Whitespace-only changes.