diff --git a/web/app/components/inputs/product-select/index.hbs b/web/app/components/inputs/product-select/index.hbs index ab8a4c17c..1e33787ca 100644 --- a/web/app/components/inputs/product-select/index.hbs +++ b/web/app/components/inputs/product-select/index.hbs @@ -60,7 +60,7 @@ <:item as |dd|> - + { + document.attrs[field.name] = field.value; + }); + } + if ("product" in attrs) { attrs.docNumber = getTestDocNumber(attrs.product); } document.update(attrs); + return new Response(200, {}, document.attrs); } }); diff --git a/web/tests/acceptance/authenticated/document-test.ts b/web/tests/acceptance/authenticated/document-test.ts index d60364ff4..2bf493186 100644 --- a/web/tests/acceptance/authenticated/document-test.ts +++ b/web/tests/acceptance/authenticated/document-test.ts @@ -36,10 +36,13 @@ const DRAFT_VISIBILITY_TOGGLE_SELECTOR = "[data-test-draft-visibility-toggle]"; const COPY_URL_BUTTON_SELECTOR = "[data-test-sidebar-copy-url-button]"; const DRAFT_VISIBILITY_OPTION_SELECTOR = "[data-test-draft-visibility-option]"; const SECOND_DRAFT_VISIBILITY_LIST_ITEM_SELECTOR = `${DRAFT_VISIBILITY_DROPDOWN_SELECTOR} li:nth-child(2)`; + const TITLE_SELECTOR = "[data-test-document-title]"; const SUMMARY_SELECTOR = "[data-test-document-summary]"; const CONTRIBUTORS_SELECTOR = "[data-test-document-contributors]"; const APPROVERS_SELECTOR = "[data-test-document-approvers]"; +const APPROVED_BADGE_SELECTOR = "[data-test-person-approved-badge]"; +const PRODUCT_SELECT_SELECTOR = "[data-test-product-select]"; const EDITABLE_PRODUCT_AREA_SELECTOR = "[data-test-document-product-area-editable]"; @@ -61,7 +64,12 @@ const CONTINUE_TO_DOCUMENT_BUTTON_SELECTOR = const DOC_PUBLISHED_COPY_URL_BUTTON_SELECTOR = "[data-test-doc-published-copy-url-button]"; -const CUSTOM_PEOPLE_FIELD_SELECTOR = "[data-test-custom-people-field]"; +const CUSTOM_STRING_FIELD_SELECTOR = "[data-test-custom-field-type='string']"; +const CUSTOM_PEOPLE_FIELD_SELECTOR = "[data-test-custom-field-type='people']"; +const EDITABLE_FIELD_SAVE_BUTTON_SELECTOR = + ".editable-field [data-test-save-button]"; +const PEOPLE_SELECT_REMOVE_BUTTON_SELECTOR = + ".ember-power-select-multiple-remove-btn"; const assertEditingIsDisabled = (assert: Assert) => { assert.dom(TITLE_SELECTOR).doesNotHaveAttribute("data-test-editable"); @@ -571,17 +579,176 @@ module("Acceptance | authenticated/document", function (hooks) { assert.dom(ADD_RELATED_RESOURCE_MODAL_SELECTOR).exists(); }); - test("the title attribute saves", async function (this: AuthenticatedDocumentRouteTestContext, assert) {}); + test("the title attribute saves", async function (this: AuthenticatedDocumentRouteTestContext, assert) { + this.server.create("document", { + objectID: 1, + title: "Test Document", + isDraft: true, + }); + + await visit("/document/1?draft=true"); - test("the summary attribute saves", async function (this: AuthenticatedDocumentRouteTestContext, assert) {}); + await click(`${TITLE_SELECTOR} button`); - test("the contributors attribute saves", async function (this: AuthenticatedDocumentRouteTestContext, assert) {}); + await fillIn(`${TITLE_SELECTOR} textarea`, "New Title"); - test("the approvers attribute saves", async function (this: AuthenticatedDocumentRouteTestContext, assert) {}); + await triggerKeyEvent(`${TITLE_SELECTOR} textarea`, "keydown", "Enter"); - test("the product area attribute saves", async function (this: AuthenticatedDocumentRouteTestContext, assert) {}); + assert.dom(TITLE_SELECTOR).hasText("New Title"); + }); - test("text customEditableFields save", async function (this: AuthenticatedDocumentRouteTestContext, assert) {}); + test("the summary attribute saves", async function (this: AuthenticatedDocumentRouteTestContext, assert) { + this.server.create("document", { + objectID: 1, + summary: "foo bar baz", + isDraft: true, + }); - test("people customEditableFields save", async function (this: AuthenticatedDocumentRouteTestContext, assert) {}); + await visit("/document/1?draft=true"); + + await click(`${SUMMARY_SELECTOR} button`); + + await fillIn(`${SUMMARY_SELECTOR} textarea`, "New Summary"); + + await triggerKeyEvent(`${SUMMARY_SELECTOR} textarea`, "keydown", "Enter"); + + assert.dom(SUMMARY_SELECTOR).hasText("New Summary"); + }); + + test("the contributors attribute saves", async function (this: AuthenticatedDocumentRouteTestContext, assert) { + this.server.create("document", { + objectID: 1, + contributors: ["foo@example.com"], + isDraft: true, + }); + + await visit("/document/1?draft=true"); + + await click(`${CONTRIBUTORS_SELECTOR} button`); + + // Delete the existing contributor and save + await click(PEOPLE_SELECT_REMOVE_BUTTON_SELECTOR); + await click(EDITABLE_FIELD_SAVE_BUTTON_SELECTOR); + + assert.dom(CONTRIBUTORS_SELECTOR).hasText("None"); + }); + + test("the approvers attribute saves", async function (this: AuthenticatedDocumentRouteTestContext, assert) { + this.server.create("document", { + objectID: 1, + approvers: ["foo@example.com"], + isDraft: true, + }); + + await visit("/document/1?draft=true"); + + await click(`${APPROVERS_SELECTOR} button`); + + // Delete the existing approver and save + await click(PEOPLE_SELECT_REMOVE_BUTTON_SELECTOR); + await click(EDITABLE_FIELD_SAVE_BUTTON_SELECTOR); + + assert.dom(APPROVERS_SELECTOR).hasText("None"); + }); + + test("the product area attribute saves", async function (this: AuthenticatedDocumentRouteTestContext, assert) { + this.server.create("product", { + name: "Foo", + }); + + this.server.create("product", { + name: "Bar", + }); + + this.server.create("document", { + objectID: 1, + product: "Bar", + isDraft: true, + }); + + await visit("/document/1?draft=true"); + + assert.dom(PRODUCT_SELECT_SELECTOR).hasText("Bar"); + + await click(`${PRODUCT_SELECT_SELECTOR} button`); + + await click(`[data-test-product-select-badge-dropdown-item]`); + + assert.dom(PRODUCT_SELECT_SELECTOR).hasText("Foo"); + + // confirm with the back end + + assert.equal( + this.server.schema.document.first().attrs.product, + "Foo", + "the product is updated in the back end", + ); + }); + + test("customEditableFields save (STRING)", async function (this: AuthenticatedDocumentRouteTestContext, assert) { + this.server.create("document", { + objectID: 1, + customEditableFields: { + foo: { + displayName: "Foo", + type: "STRING", + }, + }, + isDraft: true, + }); + + await visit("/document/1?draft=true"); + + await click(`${CUSTOM_STRING_FIELD_SELECTOR} button`); + + await fillIn("textarea", "Bar"); + + await click(EDITABLE_FIELD_SAVE_BUTTON_SELECTOR); + + assert.dom(CUSTOM_STRING_FIELD_SELECTOR).hasText("Bar"); + }); + + test("customEditableFields save (PEOPLE)", async function (this: AuthenticatedDocumentRouteTestContext, assert) { + this.server.create("document", { + objectID: 1, + customEditableFields: { + foo: { + displayName: "Foo", + type: "PEOPLE", + }, + }, + foo: ["foo@example.com"], + isDraft: true, + }); + + await visit("/document/1?draft=true"); + + await click(`${CUSTOM_PEOPLE_FIELD_SELECTOR} button`); + + // Delete the existing contributor and save + await click(PEOPLE_SELECT_REMOVE_BUTTON_SELECTOR); + await click(EDITABLE_FIELD_SAVE_BUTTON_SELECTOR); + + assert.dom(CUSTOM_PEOPLE_FIELD_SELECTOR).hasText("None"); + }); + + test("approvers who have approved a document are badged with a checkmark", async function (this: AuthenticatedDocumentRouteTestContext, assert) { + this.server.create("document", { + objectID: 1, + approvers: ["foo@example.com", "bar@example.com"], + approvedBy: ["foo@example.com"], + }); + + await visit("/document/1"); + + assert.dom(`${APPROVERS_SELECTOR} li`).exists({ count: 2 }); + + assert + .dom(`${APPROVERS_SELECTOR} li:nth-child(1) ${APPROVED_BADGE_SELECTOR}`) + .exists("the first approver is badged with a check"); + + assert + .dom(`${APPROVERS_SELECTOR} li:nth-child(2) ${APPROVED_BADGE_SELECTOR}`) + .doesNotExist("the second approver is not badged"); + }); }); diff --git a/web/tests/integration/components/document/sidebar/related-resources-test.ts b/web/tests/integration/components/document/sidebar/related-resources-test.ts index fa29d0d49..eb724c0e6 100644 --- a/web/tests/integration/components/document/sidebar/related-resources-test.ts +++ b/web/tests/integration/components/document/sidebar/related-resources-test.ts @@ -19,7 +19,6 @@ const LIST_SELECTOR = "[data-test-related-resources-list]"; const LIST_ITEM_SELECTOR = ".related-resource"; const HERMES_DOCUMENT_SELECTOR = ".hermes-document"; const EXTERNAL_RESOURCE_SELECTOR = ".external-resource"; -const BADGE_SELECTOR = "[data-test-sidebar-section-header-badge]"; const HEADER_SELECTOR = ".sidebar-section-header"; const ERROR_MESSAGE_SELECTOR = ".failed-to-load-text"; const ERROR_BUTTON_SELECTOR = "[data-test-related-resources-error-button]"; @@ -95,7 +94,7 @@ module( const emptyStateSelector = "[data-test-related-resources-list-empty-state]"; - assert.dom(emptyStateSelector).hasText("---"); + assert.dom(emptyStateSelector).hasText("None"); await click("[data-test-related-resources-list-empty-state]"); @@ -147,8 +146,6 @@ module( .dom(".hermes-tooltip") .hasText("Documents and links that are relevant to this work."); - assert.dom(BADGE_SELECTOR).hasText("New", "the 'new' badge is rendered'"); - assert .dom(HERMES_DOCUMENT_SELECTOR) .exists({ count: 2 }, "there are 2 hermes documents"); diff --git a/web/tests/integration/components/editable-field/read-value-test.ts b/web/tests/integration/components/editable-field/read-value-test.ts index 896309eb9..7ae1a9968 100644 --- a/web/tests/integration/components/editable-field/read-value-test.ts +++ b/web/tests/integration/components/editable-field/read-value-test.ts @@ -28,7 +28,7 @@ module("Integration | Component | editable-field/read-value", function (hooks) { this.set("tag", undefined); assert.dom("h1").doesNotExist(); - assert.dom("p").hasText("Hello World"); + assert.dom("div").hasText("Hello World"); }); test("it shows a customizable empty state", async function (this: EditableFieldReadValueComponentTestContext, assert) { @@ -68,7 +68,7 @@ module("Integration | Component | editable-field/read-value", function (hooks) { await render(hbs` `);