|
1 | 1 | import $ from "jquery";
|
| 2 | +import dom from "../../core/dom"; |
2 | 3 | import pattern from "./depends";
|
3 | 4 | import utils from "../../core/utils";
|
4 | 5 |
|
@@ -187,4 +188,73 @@ describe("pat-depends", function () {
|
187 | 188 | expect(data.enabled).toBe(false);
|
188 | 189 | });
|
189 | 190 | });
|
| 191 | + |
| 192 | + describe("5 - Support pat-depends within a pat-depends controlled tree.", function () { |
| 193 | + |
| 194 | + it("Also updates pat-depends within a pat-depends controlled tree", async function () { |
| 195 | + |
| 196 | + document.body.innerHTML = ` |
| 197 | + <div data-pat-depends="action: both"> |
| 198 | + <label> |
| 199 | + <input |
| 200 | + name="show-tree" |
| 201 | + type="checkbox" |
| 202 | + /> |
| 203 | + show |
| 204 | + </label> |
| 205 | +
|
| 206 | + <fieldset |
| 207 | + class="dep1 pat-depends" |
| 208 | + data-pat-depends="condition: show-tree" |
| 209 | + > |
| 210 | + <label> |
| 211 | + <input |
| 212 | + name="extra" |
| 213 | + type="checkbox" |
| 214 | + /> |
| 215 | + Extra |
| 216 | + </label> |
| 217 | + </fieldset> |
| 218 | +
|
| 219 | + <!-- This pat-depends node controlled by a checkbox which is |
| 220 | + within another pat-depends controlled tree. |
| 221 | + --> |
| 222 | + <p |
| 223 | + class="dep2 pat-depends" |
| 224 | + data-pat-depends="condition: extra" |
| 225 | + > |
| 226 | + You shose extra! |
| 227 | + </p> |
| 228 | + </div> |
| 229 | + `; |
| 230 | + |
| 231 | + const dep1 = document.querySelector(".dep1"); |
| 232 | + new pattern(dep1); |
| 233 | + await utils.timeout(1); // wait a tick for async to settle. |
| 234 | + const dep2 = document.querySelector(".dep2"); |
| 235 | + new pattern(dep2); |
| 236 | + await utils.timeout(1); // wait a tick for async to settle. |
| 237 | + |
| 238 | + const button1 = document.querySelector("[name=show-tree]"); |
| 239 | + const button2 = document.querySelector("[name=extra]"); |
| 240 | + |
| 241 | + button1.checked = true; |
| 242 | + button1.dispatchEvent(new Event("change")); |
| 243 | + button2.checked = true; |
| 244 | + button2.dispatchEvent(new Event("change")); |
| 245 | + |
| 246 | + expect(dom.is_visible(dep1)).toBe(true); |
| 247 | + expect(dom.is_visible(dep2)).toBe(true); |
| 248 | + |
| 249 | + |
| 250 | + // Even though button2 is still checked, the visibility of dep2 is |
| 251 | + // hidden. |
| 252 | + button1.checked = false; |
| 253 | + button1.dispatchEvent(new Event("change")); |
| 254 | + |
| 255 | + expect(dom.is_visible(dep1)).toBe(false); |
| 256 | + expect(dom.is_visible(dep2)).toBe(false); |
| 257 | + }); |
| 258 | + |
| 259 | + }); |
190 | 260 | });
|
0 commit comments