Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure createDocsAsUser in the front end #529

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions web/app/components/new/doc-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import cleanString from "hermes/utils/clean-string";
import { ProductArea } from "hermes/services/product-areas";
import { next } from "@ember/runloop";
import HermesFlashMessagesService from "hermes/services/flash-messages";
import { ModelFrom } from "hermes/types/route-models";
import AuthenticatedNewRoute from "hermes/routes/authenticated/new";
import DocumentTypesService from "hermes/services/document-types";

interface DocFormErrors {
Expand All @@ -25,7 +23,6 @@ interface DocFormErrors {
}

const AWAIT_DOC_DELAY = Ember.testing ? 0 : 2000;
const AWAIT_DOC_CREATED_MODAL_DELAY = Ember.testing ? 0 : 1500;

interface NewDocFormComponentSignature {
Args: {
Expand Down Expand Up @@ -224,15 +221,23 @@ export default class NewDocFormComponent extends Component<NewDocFormComponentSi
// Wait for document to be available.
await timeout(AWAIT_DOC_DELAY);

// Set modal on a delay so it appears after transition.
this.modalAlerts.setActive.perform(
"draftCreated",
AWAIT_DOC_CREATED_MODAL_DELAY,
);

this.router.transitionTo("authenticated.document", doc.id, {
queryParams: { draft: true },
});
this.router
.transitionTo("authenticated.document", doc.id, {
queryParams: { draft: true },
})
.then(() => {
if (this.configSvc.config.create_docs_as_user) {
this.flashMessages.success("", {
title: "Draft created!",
});
} else {
/**
* If `create_docs_as_user` is false, show a modal alert
* explaining the limitations on notifications.
*/
this.modalAlerts.setActive.perform("draftCreated");
}
});
} catch (e) {
this.docIsBeingCreated = false;

Expand Down
1 change: 1 addition & 0 deletions web/app/config/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface HermesConfig {
draftsIndexName: string;
internalIndexName: string;
};
createDocsAsUser: boolean;
featureFlags: Record<string, boolean>;
google: {
docFolders: string;
Expand Down
1 change: 1 addition & 0 deletions web/app/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class ConfigService extends Service {
algolia_drafts_index_name: config.algolia.draftsIndexName,
algolia_internal_index_name: config.algolia.internalIndexName,
api_version: "v1",
create_docs_as_user: config.createDocsAsUser,
feature_flags: config.featureFlags,
google_doc_folders: config.google.docFolders ?? "",
short_link_base_url: config.shortLinkBaseURL,
Expand Down
27 changes: 26 additions & 1 deletion web/tests/acceptance/authenticated/new/doc-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Response } from "miragejs";
import RouterService from "@ember/routing/router-service";
import window from "ember-window-mock";
import { DRAFT_CREATED_LOCAL_STORAGE_KEY } from "hermes/components/modals/draft-created";
import { TEST_WEB_CONFIG } from "hermes/utils/mirage-utils";

// Selectors
const DOC_FORM = "[data-test-new-doc-form]";
Expand Down Expand Up @@ -170,7 +171,31 @@ module("Acceptance | authenticated/new/doc", function (hooks) {
assert.dom(PRODUCT_SELECT_TOGGLE).includesText("Terraform");
});

test("it shows a confirmation modal when a draft is created", async function (this: AuthenticatedNewDocRouteTestContext, assert) {
test("it shows a confirmation flash message when a draft is created (when creating draft as the user)", async function (this: AuthenticatedNewDocRouteTestContext, assert) {
this.server.get("/web/config", () => {
return new Response(
200,
{},
JSON.stringify({ ...TEST_WEB_CONFIG, create_docs_as_user: true }),
);
});

this.server.createList("product", 1);

await visit("/new/doc?docType=RFC");

await fillIn(TITLE_INPUT, "Foo");
await click(PRODUCT_SELECT_TOGGLE);
await click(FIRST_PRODUCT_SELECT_ITEM_BUTTON);

await click(CREATE_BUTTON);

await waitFor(FLASH_NOTIFICATION);

assert.dom(FLASH_NOTIFICATION).hasText("Draft created!");
});

test("it shows a confirmation modal when a draft is created (not creating doc as user)", async function (this: AuthenticatedNewDocRouteTestContext, assert) {
// Reset the localStorage item
window.localStorage.removeItem(DRAFT_CREATED_LOCAL_STORAGE_KEY);

Expand Down