|
1 | 1 | import { E2EElement, E2EPage, newE2EPage } from "@stencil/core/testing"; |
2 | | -import { simpleModelComboBox1 } from "../../../showcase/assets/components/combo-box/models"; |
| 2 | +import { |
| 3 | + dataTypeInGeneXus, |
| 4 | + simpleModelComboBox1 |
| 5 | +} from "../../../showcase/assets/components/combo-box/models"; |
| 6 | + |
| 7 | +const EMPTY_VALUE_PART = "ch-combo-box-render--placeholder"; |
| 8 | +const DUMMY_VALUE = "Hello world"; |
| 9 | +const VALID_VALUE = "_Audio"; |
3 | 10 |
|
4 | 11 | describe("[ch-combo-box-render][parts]", () => { |
5 | 12 | let page: E2EPage; |
@@ -54,4 +61,132 @@ describe("[ch-combo-box-render][parts]", () => { |
54 | 61 | expect(collapsedButtonRef.getAttribute("part")).not.toContain("expanded"); |
55 | 62 | expect(collapsedButtonRef.getAttribute("part")).toContain("collapsed"); |
56 | 63 | }); |
| 64 | + |
| 65 | + it(`[default] should set the "${EMPTY_VALUE_PART}" part in the Host by default`, async () => { |
| 66 | + expect(comboBoxRef.getAttribute("part")).toContain(EMPTY_VALUE_PART); |
| 67 | + }); |
| 68 | + |
| 69 | + it(`[default] should set the "${EMPTY_VALUE_PART}" part in the Host, even if the model has items`, async () => { |
| 70 | + comboBoxRef.setProperty("model", dataTypeInGeneXus); |
| 71 | + await page.waitForChanges(); |
| 72 | + |
| 73 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 74 | + expect(comboBoxRef.getAttribute("part")).toContain(EMPTY_VALUE_PART); |
| 75 | + }); |
| 76 | + |
| 77 | + it(`[default] should set the "${EMPTY_VALUE_PART}" part in the Host, even if the model has items but the value does not match a valid item`, async () => { |
| 78 | + comboBoxRef.setProperty("model", dataTypeInGeneXus); |
| 79 | + comboBoxRef.setProperty("value", DUMMY_VALUE); |
| 80 | + await page.waitForChanges(); |
| 81 | + |
| 82 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 83 | + expect(comboBoxRef.getAttribute("part")).toContain(EMPTY_VALUE_PART); |
| 84 | + }); |
| 85 | + |
| 86 | + it(`[default] should set the "${EMPTY_VALUE_PART}" part in the Host, when the value is set but the model is undefined`, async () => { |
| 87 | + comboBoxRef.setProperty("value", DUMMY_VALUE); |
| 88 | + await page.waitForChanges(); |
| 89 | + |
| 90 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 91 | + expect(comboBoxRef.getAttribute("part")).toContain(EMPTY_VALUE_PART); |
| 92 | + }); |
| 93 | + |
| 94 | + it(`[default] should not set the "${EMPTY_VALUE_PART}" part in the Host, when the value matches a valid item`, async () => { |
| 95 | + comboBoxRef.setProperty("model", dataTypeInGeneXus); |
| 96 | + comboBoxRef.setProperty("value", VALID_VALUE); |
| 97 | + await page.waitForChanges(); |
| 98 | + |
| 99 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 100 | + expect(comboBoxRef.getAttribute("part")).not.toContain(EMPTY_VALUE_PART); |
| 101 | + }); |
| 102 | + |
| 103 | + it(`[default] should set again the "${EMPTY_VALUE_PART}" part in the Host, when the value is matches a valid item and then is updated to undefined`, async () => { |
| 104 | + comboBoxRef.setProperty("model", dataTypeInGeneXus); |
| 105 | + comboBoxRef.setProperty("value", VALID_VALUE); |
| 106 | + await page.waitForChanges(); |
| 107 | + |
| 108 | + comboBoxRef.setProperty("value", undefined); |
| 109 | + await page.waitForChanges(); |
| 110 | + |
| 111 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 112 | + expect(comboBoxRef.getAttribute("part")).toContain(EMPTY_VALUE_PART); |
| 113 | + }); |
| 114 | + |
| 115 | + it(`[suggest] should set the "${EMPTY_VALUE_PART}" part in the Host by default`, async () => { |
| 116 | + comboBoxRef.setProperty("suggest", true); |
| 117 | + await page.waitForChanges(); |
| 118 | + |
| 119 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 120 | + expect(comboBoxRef.getAttribute("part")).toContain(EMPTY_VALUE_PART); |
| 121 | + }); |
| 122 | + |
| 123 | + it(`[suggest] should set the "${EMPTY_VALUE_PART}" part in the Host, even if the model has items`, async () => { |
| 124 | + comboBoxRef.setProperty("suggest", true); |
| 125 | + comboBoxRef.setProperty("model", dataTypeInGeneXus); |
| 126 | + await page.waitForChanges(); |
| 127 | + |
| 128 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 129 | + expect(comboBoxRef.getAttribute("part")).toContain(EMPTY_VALUE_PART); |
| 130 | + }); |
| 131 | + |
| 132 | + it(`[suggest] should not set the "${EMPTY_VALUE_PART}" part in the Host, when the value is set with an invalid item and the model is undefined`, async () => { |
| 133 | + comboBoxRef.setProperty("suggest", true); |
| 134 | + comboBoxRef.setProperty("value", DUMMY_VALUE); |
| 135 | + await page.waitForChanges(); |
| 136 | + |
| 137 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 138 | + expect(comboBoxRef.getAttribute("part")).not.toContain(EMPTY_VALUE_PART); |
| 139 | + }); |
| 140 | + |
| 141 | + it(`[suggest] should not set the "${EMPTY_VALUE_PART}" part in the Host, when the value is set with a valid item and the model is undefined`, async () => { |
| 142 | + comboBoxRef.setProperty("suggest", true); |
| 143 | + comboBoxRef.setProperty("value", VALID_VALUE); |
| 144 | + await page.waitForChanges(); |
| 145 | + |
| 146 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 147 | + expect(comboBoxRef.getAttribute("part")).not.toContain(EMPTY_VALUE_PART); |
| 148 | + }); |
| 149 | + |
| 150 | + it(`[suggest] should not set the "${EMPTY_VALUE_PART}" part in the Host, when the value is set with an invalid item and the model is defined`, async () => { |
| 151 | + comboBoxRef.setProperty("suggest", true); |
| 152 | + comboBoxRef.setProperty("model", dataTypeInGeneXus); |
| 153 | + comboBoxRef.setProperty("value", DUMMY_VALUE); |
| 154 | + await page.waitForChanges(); |
| 155 | + |
| 156 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 157 | + expect(comboBoxRef.getAttribute("part")).not.toContain(EMPTY_VALUE_PART); |
| 158 | + }); |
| 159 | + |
| 160 | + it(`[suggest] should not set the "${EMPTY_VALUE_PART}" part in the Host, when the value is set with a valid item and the model is defined`, async () => { |
| 161 | + comboBoxRef.setProperty("suggest", true); |
| 162 | + comboBoxRef.setProperty("model", dataTypeInGeneXus); |
| 163 | + comboBoxRef.setProperty("value", VALID_VALUE); |
| 164 | + await page.waitForChanges(); |
| 165 | + |
| 166 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 167 | + expect(comboBoxRef.getAttribute("part")).not.toContain(EMPTY_VALUE_PART); |
| 168 | + }); |
| 169 | + |
| 170 | + it(`[suggest] should set again the "${EMPTY_VALUE_PART}" part in the Host, when the value is defined and then is updated to undefined`, async () => { |
| 171 | + comboBoxRef.setProperty("suggest", true); |
| 172 | + comboBoxRef.setProperty("value", VALID_VALUE); |
| 173 | + await page.waitForChanges(); |
| 174 | + |
| 175 | + comboBoxRef.setProperty("value", undefined); |
| 176 | + await page.waitForChanges(); |
| 177 | + |
| 178 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 179 | + expect(comboBoxRef.getAttribute("part")).toContain(EMPTY_VALUE_PART); |
| 180 | + }); |
| 181 | + |
| 182 | + // TODO: This should work even with the suggestDebounce |
| 183 | + it.skip(`[suggest] should remove the "${EMPTY_VALUE_PART}" part in the Host, when the user types a character`, async () => { |
| 184 | + comboBoxRef.setProperty("suggest", true); |
| 185 | + await page.waitForChanges(); |
| 186 | + await comboBoxRef.press("A"); |
| 187 | + await page.waitForChanges(); |
| 188 | + |
| 189 | + comboBoxRef = await page.find("ch-combo-box-render"); // Refresh the reference |
| 190 | + expect(comboBoxRef.getAttribute("part")).not.toContain(EMPTY_VALUE_PART); |
| 191 | + }); |
57 | 192 | }); |
0 commit comments