|
| 1 | +import { Actions, Assertions, createComponent, createPage } from "@duplojs/playwright"; |
1 | 2 | import { testClient } from "@testClient"; |
2 | 3 |
|
3 | 4 | testClient.describe("form one", () => { |
4 | | - testClient("go on form page and submit form", ({ website }) => { |
| 5 | + const HumanForm = createComponent("humanForm", { |
| 6 | + getMainElement: ({ body }) => body.locator(".DFV-deep_FRM_UNI-human_MUL"), |
| 7 | + getElements: ({ mainElement }) => ({ |
| 8 | + nameField: mainElement.locator("#FRM_UNI-human_MUL-name_INP"), |
| 9 | + errorNameField: mainElement.locator(".DFV-deep_FRM_UNI-human_MUL-name_INP > .DFV-grid-error"), |
5 | 10 |
|
| 11 | + priceField: mainElement.locator("#FRM_UNI-human_MUL-price_INP"), |
| 12 | + errorPriceField: mainElement.locator(".DFV-deep_FRM_UNI-human_MUL-price_INP > .DFV-grid-error"), |
| 13 | + |
| 14 | + errorFields: mainElement.locator(".DFV-deep_FRM_UNI-human_MUL-fields_SEC_CHK > .DFV-grid-error"), |
| 15 | + |
| 16 | + nameOfFirstField: mainElement.locator(".DFV-deep_FRM_UNI-human_MUL-fields_SEC_CHK_REP-0_MUL-fieldName_INP > input"), |
| 17 | + errorNameOfFirstField: mainElement.locator(".DFV-deep_FRM_UNI-human_MUL-fields_SEC_CHK_REP-0_MUL-fieldName_INP > .DFV-grid-error"), |
| 18 | + maxCharOfFirstField: mainElement.locator("#FRM_UNI-human_MUL-fields_SEC_CHK_REP-0_MUL-fieldType_UNI-text_CHK_MUL-max_INP"), |
| 19 | + |
| 20 | + nameOfSecondField: mainElement.locator(".DFV-deep_FRM_UNI-human_MUL-fields_SEC_CHK_REP-1_MUL-fieldName_INP > input"), |
| 21 | + selectTypeOnSecondField: mainElement.locator("#select-FRM_UNI-human_MUL-fields_SEC_CHK_REP-1_MUL-fieldType_UNI"), |
| 22 | + firstLabelOnSecondField: mainElement.locator("#FRM_UNI-human_MUL-fields_SEC_CHK_REP-1_MUL-fieldType_UNI-select_SEC_REP-0_MUL-label_INP"), |
| 23 | + firstValueOnSecondField: mainElement.locator("#FRM_UNI-human_MUL-fields_SEC_CHK_REP-1_MUL-fieldType_UNI-select_SEC_REP-0_MUL-value_INP"), |
| 24 | + secondLabelOnSecondField: mainElement.locator("#FRM_UNI-human_MUL-fields_SEC_CHK_REP-1_MUL-fieldType_UNI-select_SEC_REP-1_MUL-label_INP"), |
| 25 | + secondValueOnSecondField: mainElement.locator("#FRM_UNI-human_MUL-fields_SEC_CHK_REP-1_MUL-fieldType_UNI-select_SEC_REP-1_MUL-value_INP"), |
| 26 | + |
| 27 | + addFieldButton: mainElement.locator(".DFV-deep_FRM_UNI-human_MUL-fields_SEC_CHK_REP > .DFV-grid-repeat-add > button"), |
| 28 | + }), |
| 29 | + }); |
| 30 | + |
| 31 | + const AIAgentForm = createComponent("aIAgentForm", { |
| 32 | + getMainElement: ({ body }) => body.locator(".DFV-deep_FRM_UNI-AIAgent_STP"), |
| 33 | + getElements: ({ mainElement }) => ({ |
| 34 | + nameField: mainElement.locator("#FRM_UNI-AIAgent_STP-0_MUL-name_INP"), |
| 35 | + }), |
| 36 | + }); |
| 37 | + |
| 38 | + const FormOnePage = createPage("formOne", { |
| 39 | + makePath: () => "form-one", |
| 40 | + getMainElement: ({ body }) => body.getByTestId("form-one"), |
| 41 | + getElements: ({ mainElement }) => ({ |
| 42 | + submitButton: mainElement.getByTestId("submit-button"), |
| 43 | + selectInputTypeForm: mainElement.locator("#select-FRM_UNI"), |
| 44 | + currentValue: mainElement.locator("#current-value"), |
| 45 | + checkedValue: mainElement.locator("#checked-value"), |
| 46 | + }), |
| 47 | + components: [HumanForm, AIAgentForm], |
| 48 | + }); |
| 49 | + |
| 50 | + testClient("define name on human form and switch form and return on human form and see defined value on name", async({ website }) => { |
| 51 | + const page = await website.iNavigateTo(FormOnePage); |
| 52 | + |
| 53 | + await Assertions.toBeVisible(page, "submitButton"); |
| 54 | + await Assertions.toBeVisible(page, "selectInputTypeForm"); |
| 55 | + |
| 56 | + const humanForm = await page.iWantToSeeComponent("humanForm"); |
| 57 | + |
| 58 | + await Assertions.toContainText(page, "currentValue", JSON.stringify({ |
| 59 | + kind: "human", |
| 60 | + value: { |
| 61 | + name: "", |
| 62 | + price: 0, |
| 63 | + fields: [ |
| 64 | + { |
| 65 | + fieldName: "", |
| 66 | + fieldType: { |
| 67 | + kind: "text", |
| 68 | + value: { |
| 69 | + min: 5, |
| 70 | + max: 30, |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, |
| 74 | + ], |
| 75 | + }, |
| 76 | + })); |
| 77 | + |
| 78 | + await Actions.fill(humanForm, "nameField", "superName"); |
| 79 | + |
| 80 | + await Actions.selectOption(page, "selectInputTypeForm", "AIAgent"); |
| 81 | + |
| 82 | + await Assertions.toContainText(page, "currentValue", JSON.stringify({ |
| 83 | + kind: "AIAgent", |
| 84 | + value: { |
| 85 | + currentStep: 0, |
| 86 | + steps: [ |
| 87 | + { |
| 88 | + name: "", |
| 89 | + price: 0, |
| 90 | + fields: [ |
| 91 | + { |
| 92 | + fieldName: "", |
| 93 | + fieldType: { |
| 94 | + kind: "text", |
| 95 | + value: { |
| 96 | + min: 5, |
| 97 | + max: 30, |
| 98 | + }, |
| 99 | + }, |
| 100 | + }, |
| 101 | + ], |
| 102 | + }, |
| 103 | + { |
| 104 | + route: "", |
| 105 | + routePing: "", |
| 106 | + key: "", |
| 107 | + }, |
| 108 | + ], |
| 109 | + }, |
| 110 | + })); |
| 111 | + |
| 112 | + await page.iWantToSeeComponent("aIAgentForm"); |
| 113 | + |
| 114 | + await Actions.selectOption(page, "selectInputTypeForm", "human"); |
| 115 | + |
| 116 | + await page.iWantToSeeComponent("humanForm"); |
| 117 | + |
| 118 | + await Assertions.toHaveValue(humanForm, "nameField", "superName"); |
| 119 | + |
| 120 | + await Assertions.toContainText(page, "currentValue", JSON.stringify({ |
| 121 | + kind: "human", |
| 122 | + value: { |
| 123 | + name: "superName", |
| 124 | + price: 0, |
| 125 | + fields: [ |
| 126 | + { |
| 127 | + fieldName: "", |
| 128 | + fieldType: { |
| 129 | + kind: "text", |
| 130 | + value: { |
| 131 | + min: 5, |
| 132 | + max: 30, |
| 133 | + }, |
| 134 | + }, |
| 135 | + }, |
| 136 | + ], |
| 137 | + }, |
| 138 | + })); |
| 139 | + }); |
| 140 | + |
| 141 | + testClient("submit human form and see error field", async({ website }) => { |
| 142 | + const page = await website.iNavigateTo(FormOnePage); |
| 143 | + await Assertions.toContainText(page, "checkedValue", ""); |
| 144 | + |
| 145 | + const humanForm = await page.iWantToSeeComponent("humanForm"); |
| 146 | + |
| 147 | + await Actions.click(page, "submitButton"); |
| 148 | + |
| 149 | + await Assertions.toContainText(humanForm, "errorNameField", "Nom trop cours"); |
| 150 | + await Assertions.toContainText(humanForm, "errorPriceField", "Prix invalide"); |
| 151 | + await Assertions.toContainText(humanForm, "errorNameOfFirstField", "Nom de champ trop cours"); |
| 152 | + await Assertions.toContainText(page, "checkedValue", ""); |
| 153 | + }); |
| 154 | + |
| 155 | + testClient("submit human form with a text field and a select field", async({ website }) => { |
| 156 | + const page = await website.iNavigateTo(FormOnePage); |
| 157 | + |
| 158 | + const humanForm = await page.iWantToSeeComponent("humanForm"); |
| 159 | + |
| 160 | + await Actions.fill(humanForm, "nameField", "test"); |
| 161 | + await Actions.fill(humanForm, "priceField", "12"); |
| 162 | + await Actions.fill(humanForm, "nameOfFirstField", "field1"); |
| 163 | + await Actions.fill(humanForm, "maxCharOfFirstField", "20"); |
| 164 | + |
| 165 | + await Actions.click(humanForm, "addFieldButton"); |
| 166 | + |
| 167 | + await Actions.fill(humanForm, "nameOfSecondField", "field1"); |
| 168 | + await Actions.selectOption(humanForm, "selectTypeOnSecondField", "select"); |
| 169 | + await Actions.fill(humanForm, "firstLabelOnSecondField", "toto"); |
| 170 | + await Actions.fill(humanForm, "firstValueOnSecondField", "yoyo"); |
| 171 | + await Actions.fill(humanForm, "secondLabelOnSecondField", "tata"); |
| 172 | + await Actions.fill(humanForm, "secondValueOnSecondField", "ploplo"); |
| 173 | + |
| 174 | + await Actions.click(page, "submitButton"); |
| 175 | + |
| 176 | + await Assertions.toContainText(humanForm, "errorFields", "Les noms de champ suivant sont utilisais en double : field1."); |
| 177 | + |
| 178 | + await Actions.fill(humanForm, "nameOfSecondField", "field2"); |
| 179 | + |
| 180 | + await Actions.click(page, "submitButton"); |
| 181 | + |
| 182 | + await Assertions.toContainText(page, "checkedValue", JSON.stringify({ |
| 183 | + kind: "human", |
| 184 | + value: { |
| 185 | + name: "test", |
| 186 | + price: 12, |
| 187 | + fields: [ |
| 188 | + { |
| 189 | + fieldName: "field1", |
| 190 | + fieldType: { |
| 191 | + kind: "text", |
| 192 | + value: { |
| 193 | + min: 5, |
| 194 | + max: 20, |
| 195 | + }, |
| 196 | + }, |
| 197 | + }, |
| 198 | + { |
| 199 | + fieldName: "field2", |
| 200 | + fieldType: { |
| 201 | + kind: "select", |
| 202 | + value: [ |
| 203 | + { |
| 204 | + label: "toto", |
| 205 | + value: "yoyo", |
| 206 | + }, |
| 207 | + { |
| 208 | + label: "tata", |
| 209 | + value: "ploplo", |
| 210 | + }, |
| 211 | + ], |
| 212 | + }, |
| 213 | + }, |
| 214 | + ], |
| 215 | + }, |
| 216 | + })); |
6 | 217 | }); |
7 | 218 | }); |
0 commit comments