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

[composer] Made the value prop reactive. #93

Merged
merged 3 commits into from
Oct 4, 2021
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
7 changes: 4 additions & 3 deletions components/composer/src/Composer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@
JSON.stringify({ component_id: id, access_token })
]) || {};

if (value) {
mergeMessage(value);
}
if (manifest && id) {
const account: Account = await fetchAccount({
component_id: id,
Expand Down Expand Up @@ -165,6 +162,10 @@
}
}

$: if (value) {
mergeMessage(value);
}

Comment on lines +165 to +168
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the type of value?

Copy link
Collaborator Author

@AaronDDM AaronDDM Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message | void but I suppose it could be undefined as well...

$: {
show_to = getPropertyValue(internalProps.show_to, show_to, true);
show_from = getPropertyValue(internalProps.show_from, show_from, true);
Expand Down
27 changes: 22 additions & 5 deletions components/composer/src/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe("Composer html", () => {
});

it("shows template", () => {
element.value.body = "";
element.value = { body: "" };
element.template = `Hey what up!<br />
<br />
<br />
Expand Down Expand Up @@ -275,6 +275,19 @@ describe("Composer html", () => {
cy.wait(75);
cy.contains("async@test.com");
});

it("Has a reactive value prop", () => {
cy.get("nylas-composer").should("exist").as("composer");
cy.get("header"); // wait for component to render

cy.get("@composer").then((el) => {
const component = el[0];
component.value = { body: "Test reactive prop" };
cy.get(".html-editor[contenteditable=true]")
.invoke("prop", "innerHTML")
.should("include", "Test reactive prop");
});
});
});

describe("Composer actions", () => {
Expand Down Expand Up @@ -420,11 +433,13 @@ describe("Composer html", () => {
});

it("Replaces merge fields as defined in replace_fields when passed as a strinigfied version", () => {
element.value.body = `[hi] what up!<br />
element.value = {
body: `[hi] what up!<br />
<br />
<br />
Thanks,
-Phil`;
-Phil`,
};
cy.get("nylas-composer")
.as("composer")
.then((el) => {
Expand All @@ -446,11 +461,13 @@ describe("Composer html", () => {
});

it("Replaces merge fields as defined in replace_fields when passed a prop", () => {
element.value.body = `[hi] what up!<br />
element.value = {
body: `[hi] what up!<br />
<br />
<br />
Thanks,
-Phil`;
-Phil`,
};
cy.get("nylas-composer")
.as("composer")
.then((el) => {
Expand Down