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

Added a test for defining replace_fields as prop & attribute to Composer #6

Merged
merged 2 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion components/composer/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<script>
document.addEventListener("DOMContentLoaded", function () {
const composer = document.querySelector("nylas-composer");
composer.replace_fields = [{ from: "[hi]", to: "hello" }];
// This is same as setting below, attribute with strigified value
// composer.setAttribute("replace_fields", JSON.stringify([{ "from": "[hi]", "to": "hello" }]));
composer.addEventListener("composerMinimized", function (event) {
console.log("Composer Minimized", event.detail);
});
Expand Down Expand Up @@ -49,7 +52,6 @@
<nylas-composer
id="demo-composer"
theme="dark"
replace_fields='[{"from": "[hi]", "to": "hello"}]'
template="Hey what up!<br/>
<br/>
<br/>
Expand Down
49 changes: 49 additions & 0 deletions components/composer/src/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,55 @@ describe("Composer html", () => {
cy.get(".nylas-composer").should("not.exist");
});
});

it("Replaces merge fields as defined in replace_fields when passed as a strinigfied version", () => {
element.value.body = `[hi] what up!<br />
<br />
<br />
Thanks,
-Phil`;
cy.get("nylas-composer")
.as("composer")
.then((el) => {
const component = el[0];
component.setAttribute(
"replace_fields",
'[{"from": "[hi]", "to": "Hello"}]',
);
console.log(component);
cy.get(".html-editor[contenteditable=true]")
.invoke("prop", "innerHTML")
.then((html) => {
console.log(html);
expect(html).to.include(
"Hello what up!<br>\n <br>\n <br>\n Thanks,\n -Phil",
pooja169usp marked this conversation as resolved.
Show resolved Hide resolved
);
});
});
});

it("Replaces merge fields as defined in replace_fields when passed a prop", () => {
element.value.body = `[hi] what up!<br />
<br />
<br />
Thanks,
-Phil`;
cy.get("nylas-composer")
.as("composer")
.then((el) => {
const component = el[0];
component.replace_fields = [{ from: "[hi]", to: "Hello" }];
console.log(component);
cy.get(".html-editor[contenteditable=true]")
.invoke("prop", "innerHTML")
.then((html) => {
console.log(html);
expect(html).to.include(
"Hello what up!<br>\n <br>\n <br>\n Thanks,\n -Phil",
);
});
});
});
});

describe("File upload", () => {
Expand Down