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