|
| 1 | +import $ from "jquery"; |
| 2 | +import mockupParser from "./mockup-parser"; |
| 3 | + |
| 4 | +describe("The mockup-parser", function () { |
| 5 | + it("parses the data attribute of a single node", function () { |
| 6 | + const $el = $(` |
| 7 | + <span data-pat-testpattern="option1: value1; option2: value2"> |
| 8 | + mockup parser test |
| 9 | + </span>`); |
| 10 | + const options = mockupParser.getOptions($el, "testpattern"); |
| 11 | + expect(options.option1).toBe("value1"); |
| 12 | + expect(options.option2).toBe("value2"); |
| 13 | + }); |
| 14 | + it("parses the data attribute of nested nodes", function () { |
| 15 | + const $el = $(` |
| 16 | + <div data-pat-testpattern="parentOption1: value1; parentOption2: value2"> |
| 17 | + <span data-pat-testpattern="option1: subvalue1; option2: subvalue2"> |
| 18 | + nested mockup parser test |
| 19 | + </span> |
| 20 | + </div>`); |
| 21 | + const options = mockupParser.getOptions($el, "testpattern"); |
| 22 | + expect(options.parentOption1).toBe("value1"); |
| 23 | + expect(options.parentOption2).toBe("value2"); |
| 24 | + expect(options.option1).toBe(undefined); |
| 25 | + expect(options.option2).toBe(undefined); |
| 26 | + }); |
| 27 | + it("parses the data attribute of a single node and preserves injected options", function () { |
| 28 | + const $el = $(` |
| 29 | + <span data-pat-testpattern="option1: value1; option2: value2"> |
| 30 | + mockup parser test |
| 31 | + </span> |
| 32 | + `); |
| 33 | + const options = mockupParser.getOptions($el, "testpattern", { |
| 34 | + injectedOption: "injectedValue", |
| 35 | + }); |
| 36 | + expect(options.option1).toBe("value1"); |
| 37 | + expect(options.option2).toBe("value2"); |
| 38 | + expect(options.injectedOption).toBe("injectedValue"); |
| 39 | + }); |
| 40 | +}); |
0 commit comments