Skip to content

Commit

Permalink
Add isReadOnly argument to project resources (#522)
Browse files Browse the repository at this point in the history
* Set `isReadOnly` conditions

* Add isReadOnly conditions to project resources

* Add tests
  • Loading branch information
jeffdaley authored Dec 21, 2023
1 parent ded85ed commit b6d0702
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions web/app/components/project/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
{{#each this.hermesDocuments as |document|}}
<li class="group relative" data-test-document-list-item>
<Project::Resource
@isReadOnly={{not this.projectIsActive}}
@overflowMenuItems={{hash
delete=(hash
label="Remove"
Expand Down Expand Up @@ -189,6 +190,7 @@
{{#each this.externalLinks as |link i|}}
<li class="group" data-test-document-list-item>
<Project::Resource
@isReadOnly={{not this.projectIsActive}}
@overflowMenuItems={{hash
edit=(hash
label="Edit"
Expand Down
4 changes: 3 additions & 1 deletion web/app/components/project/resource.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

{{yield}}

<OverflowMenu @items={{@overflowMenuItems}} />
{{#unless @isReadOnly}}
<OverflowMenu @items={{@overflowMenuItems}} />
{{/unless}}
</div>
1 change: 1 addition & 0 deletions web/app/components/project/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface ProjectResourceComponentSignature {
Element: HTMLDivElement;
Args: {
overflowMenuItems: Record<string, OverflowItem>;
isReadOnly?: boolean;
};
Blocks: {
default: [];
Expand Down
42 changes: 42 additions & 0 deletions web/tests/acceptance/authenticated/projects/project-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,25 @@ module("Acceptance | authenticated/projects/project", function (hooks) {
assert.equal(projectDocuments.length, 0);
});

test("documents can only be removed if the project is active", async function (this: AuthenticatedProjectsProjectRouteTestContext, assert) {
await visit("/projects/1");

assert.dom(DOCUMENT_LIST_ITEM).exists();
assert.dom(OVERFLOW_MENU_BUTTON).exists();

await click(STATUS_TOGGLE);
await click(COMPLETED_STATUS_ACTION);

assert.dom(DOCUMENT_LIST_ITEM).exists();
assert.dom(OVERFLOW_MENU_BUTTON).doesNotExist();

await click(STATUS_TOGGLE);
await click(ARCHIVED_STATUS_ACTION);

assert.dom(DOCUMENT_LIST_ITEM).exists();
assert.dom(OVERFLOW_MENU_BUTTON).doesNotExist();
});

test("you can add external links to a project", async function (this: AuthenticatedProjectsProjectRouteTestContext, assert) {
const project = this.server.schema.projects.first();

Expand Down Expand Up @@ -537,6 +556,29 @@ module("Acceptance | authenticated/projects/project", function (hooks) {
assert.equal(projectLinks.length, 0);
});

test("external links can only be edited if the project is active", async function (this: AuthenticatedProjectsProjectRouteTestContext, assert) {
this.server.schema.projects.first().update({
externalLinks: [this.server.create("related-external-link").attrs],
});

await visit("/projects/1");

assert.dom(EXTERNAL_LINK).exists();
assert.dom(OVERFLOW_MENU_BUTTON).exists();

await click(STATUS_TOGGLE);
await click(COMPLETED_STATUS_ACTION);

assert.dom(EXTERNAL_LINK).exists();
assert.dom(OVERFLOW_MENU_BUTTON).doesNotExist();

await click(STATUS_TOGGLE);
await click(ARCHIVED_STATUS_ACTION);

assert.dom(EXTERNAL_LINK).exists();
assert.dom(OVERFLOW_MENU_BUTTON).doesNotExist();
});

test("you can't save an empty project title", async function (this: AuthenticatedProjectsProjectRouteTestContext, assert) {
await visit("/projects/1");

Expand Down

0 comments on commit b6d0702

Please sign in to comment.