Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdaley committed Oct 5, 2023
1 parent 2170798 commit 63a30ec
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 15 deletions.
2 changes: 1 addition & 1 deletion web/app/components/inputs/product-select/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</dd.ToggleAction>
</:anchor>
<:item as |dd|>
<dd.Action class="pr-5">
<dd.Action data-test-product-select-item-button class="pr-5">
<Inputs::ProductSelect::Item
@product={{dd.value}}
@isSelected={{dd.isSelected}}
Expand Down
7 changes: 7 additions & 0 deletions web/mirage/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,18 @@ export default function (mirageConfig) {
if (document) {
let attrs = JSON.parse(request.requestBody);

if ("customFields" in attrs) {
attrs.customFields.forEach((field) => {
document.attrs[field.name] = field.value;
});
}

if ("product" in attrs) {
attrs.docNumber = getTestDocNumber(attrs.product);
}

document.update(attrs);

return new Response(200, {}, document.attrs);
}
});
Expand Down
183 changes: 175 additions & 8 deletions web/tests/acceptance/authenticated/document-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]";
Expand All @@ -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");
Expand Down Expand Up @@ -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: ["[email protected]"],
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: ["[email protected]"],
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: ["[email protected]"],
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: ["[email protected]", "[email protected]"],
approvedBy: ["[email protected]"],
});

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");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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]";
Expand Down Expand Up @@ -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]");

Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -68,7 +68,7 @@ module("Integration | Component | editable-field/read-value", function (hooks) {

await render<EditableFieldReadValueComponentTestContext>(hbs`
<EditableField::ReadValue
@value="{{this.value}}"
@value={{this.value}}
/>
`);

Expand Down

0 comments on commit 63a30ec

Please sign in to comment.