2021-03-06 02:52:26 +13:00
|
|
|
context("Create Bindings", () => {
|
|
|
|
before(() => {
|
2021-04-16 05:29:11 +12:00
|
|
|
cy.login()
|
2021-03-06 03:36:38 +13:00
|
|
|
cy.createTestApp()
|
2021-03-06 02:52:26 +13:00
|
|
|
cy.navigateToFrontend()
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should add a current user binding", () => {
|
2021-04-21 22:33:12 +12:00
|
|
|
cy.addComponent("Elements", "Paragraph").then(() => {
|
2021-03-06 02:52:26 +13:00
|
|
|
addSettingBinding("text", "Current User._id")
|
2020-08-28 23:57:46 +12:00
|
|
|
})
|
2021-03-06 02:52:26 +13:00
|
|
|
})
|
2020-08-28 23:57:46 +12:00
|
|
|
|
2021-03-09 00:25:24 +13:00
|
|
|
it("should handle an invalid binding", () => {
|
|
|
|
cy.addComponent("Elements", "Paragraph").then(componentId => {
|
|
|
|
// Cypress needs to escape curly brackets
|
|
|
|
cy.get("[data-cy=setting-text] input")
|
|
|
|
.type("{{}{{}{{} Current User._id {}}{}}")
|
|
|
|
.blur()
|
2021-03-24 02:31:56 +13:00
|
|
|
cy.getComponent(componentId).should("have.text", "{{{ [user].[_id] }}")
|
2021-03-09 00:25:24 +13:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-03-06 02:52:26 +13:00
|
|
|
it("should add a URL param binding", () => {
|
|
|
|
const paramName = "foo"
|
|
|
|
cy.createScreen("Test Param", `/test/:${paramName}`)
|
|
|
|
cy.addComponent("Elements", "Paragraph").then(componentId => {
|
|
|
|
addSettingBinding("text", `URL.${paramName}`)
|
|
|
|
// The builder preview pages don't have a real URL, so all we can do
|
|
|
|
// is check that we were able to bind to the property, and that the
|
|
|
|
// component exists on the page
|
2021-06-12 00:11:17 +12:00
|
|
|
cy.getComponent(componentId).should("have.text", "Placeholder text")
|
2020-08-28 23:57:46 +12:00
|
|
|
})
|
2021-03-06 02:52:26 +13:00
|
|
|
})
|
2021-03-09 00:25:24 +13:00
|
|
|
|
|
|
|
it("should add a binding with a handlebars helper", () => {
|
|
|
|
cy.addComponent("Elements", "Paragraph").then(componentId => {
|
|
|
|
// Cypress needs to escape curly brackets
|
2021-05-26 03:52:35 +12:00
|
|
|
cy.get("[data-cy=setting-text] input")
|
|
|
|
.type("{{}{{} add 1 2 {}}{}}")
|
|
|
|
.blur()
|
2021-03-09 00:25:24 +13:00
|
|
|
cy.getComponent(componentId).should("have.text", "3")
|
|
|
|
})
|
|
|
|
})
|
2020-08-28 23:57:46 +12:00
|
|
|
})
|
2021-03-06 02:52:26 +13:00
|
|
|
|
2021-03-09 00:25:24 +13:00
|
|
|
const addSettingBinding = (setting, bindingText, clickOption = true) => {
|
2021-03-06 02:52:26 +13:00
|
|
|
cy.get(`[data-cy="setting-${setting}"] [data-cy=text-binding-button]`).click()
|
|
|
|
cy.get(".drawer").within(() => {
|
2021-03-09 00:25:24 +13:00
|
|
|
if (clickOption) {
|
|
|
|
cy.contains(bindingText).click()
|
|
|
|
cy.get("textarea").should("have.value", `{{ ${bindingText} }}`)
|
|
|
|
} else {
|
|
|
|
cy.get("textarea").type(bindingText)
|
|
|
|
}
|
2021-05-26 03:52:35 +12:00
|
|
|
cy.contains("Save").click()
|
2021-03-06 02:52:26 +13:00
|
|
|
})
|
|
|
|
}
|