2022-01-21 13:43:27 +01:00
|
|
|
import filterTests from "../support/filterTests"
|
2021-03-05 14:52:26 +01:00
|
|
|
|
2022-01-21 13:43:27 +01:00
|
|
|
filterTests(['smoke', 'all'], () => {
|
2022-02-17 15:06:17 +01:00
|
|
|
context("Create Bindings", () => {
|
2022-01-21 13:43:27 +01:00
|
|
|
before(() => {
|
|
|
|
cy.login()
|
|
|
|
cy.createTestApp()
|
|
|
|
cy.navigateToFrontend()
|
2020-08-28 13:57:46 +02:00
|
|
|
})
|
|
|
|
|
2022-01-21 13:43:27 +01:00
|
|
|
it("should add a current user binding", () => {
|
2022-11-23 17:19:50 +01:00
|
|
|
cy.searchAndAddComponent("Paragraph").then(componentId => {
|
2022-08-30 11:16:15 +02:00
|
|
|
addSettingBinding("text", ["Current User", "_id"], "Current User._id")
|
2022-01-21 13:43:27 +01:00
|
|
|
})
|
2022-11-23 17:19:50 +01:00
|
|
|
cy.deleteComponentByName("New Paragraph")
|
2021-03-08 12:25:24 +01:00
|
|
|
})
|
|
|
|
|
2022-01-21 13:43:27 +01:00
|
|
|
it("should handle an invalid binding", () => {
|
2022-07-22 17:33:00 +02:00
|
|
|
cy.searchAndAddComponent("Paragraph").then(componentId => {
|
2022-01-21 13:43:27 +01:00
|
|
|
// Cypress needs to escape curly brackets
|
|
|
|
cy.get("[data-cy=setting-text] input")
|
|
|
|
.type("{{}{{}{{} Current User._id {}}{}}")
|
|
|
|
.blur()
|
|
|
|
cy.getComponent(componentId).should("have.text", "{{{ [user].[_id] }}")
|
2022-11-23 17:19:50 +01:00
|
|
|
cy.deleteComponentByName("New Paragraph")
|
2022-01-21 13:43:27 +01:00
|
|
|
})
|
2020-08-28 13:57:46 +02:00
|
|
|
})
|
2021-03-08 12:25:24 +01:00
|
|
|
|
2022-05-12 11:25:05 +02:00
|
|
|
xit("should add a URL param binding", () => {
|
2022-01-21 13:43:27 +01:00
|
|
|
const paramName = "foo"
|
2022-04-22 15:57:13 +02:00
|
|
|
cy.createScreen(`/test/:${paramName}`)
|
2022-07-22 17:33:00 +02:00
|
|
|
cy.searchAndAddComponent("Paragraph").then(componentId => {
|
2022-08-30 11:16:15 +02:00
|
|
|
addSettingBinding("text", ["URL", paramName], `URL.${paramName}`)
|
2022-01-21 13:43:27 +01:00
|
|
|
// 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
|
|
|
|
cy.getComponent(componentId).should("have.text", "New Paragraph")
|
|
|
|
})
|
2021-03-08 12:25:24 +01:00
|
|
|
})
|
2021-03-05 14:52:26 +01:00
|
|
|
|
2022-01-21 13:43:27 +01:00
|
|
|
it("should add a binding with a handlebars helper", () => {
|
2022-07-22 17:33:00 +02:00
|
|
|
cy.searchAndAddComponent("Paragraph").then(componentId => {
|
2022-01-21 13:43:27 +01:00
|
|
|
// Cypress needs to escape curly brackets
|
|
|
|
cy.get("[data-cy=setting-text] input")
|
|
|
|
.type("{{}{{} add 1 2 {}}{}}")
|
|
|
|
.blur()
|
|
|
|
cy.getComponent(componentId).should("have.text", "3")
|
|
|
|
})
|
|
|
|
})
|
2021-03-05 14:52:26 +01:00
|
|
|
})
|
2022-01-21 13:43:27 +01:00
|
|
|
|
2022-08-30 11:16:15 +02:00
|
|
|
const addSettingBinding = (setting, bindingCategories, bindingText, clickOption = true) => {
|
2022-01-21 13:43:27 +01:00
|
|
|
cy.get(`[data-cy="setting-${setting}"] [data-cy=text-binding-button]`).click()
|
2022-08-30 11:16:15 +02:00
|
|
|
cy.get(".category-list li").contains(bindingCategories[0])
|
2022-01-21 13:43:27 +01:00
|
|
|
cy.get(".drawer").within(() => {
|
|
|
|
if (clickOption) {
|
2022-08-30 11:16:15 +02:00
|
|
|
cy.get(".category-list li").contains(bindingCategories[0]).click()
|
|
|
|
cy.get("li.binding").contains(bindingCategories[1]).click()
|
2022-01-21 13:43:27 +01:00
|
|
|
cy.get("textarea").should("have.value", `{{ ${bindingText} }}`)
|
|
|
|
} else {
|
|
|
|
cy.get("textarea").type(bindingText)
|
|
|
|
}
|
|
|
|
cy.contains("Save").click()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|