|
| 1 | +import $$ from '../TestHelpers'; |
| 2 | + |
| 3 | +describe('Replicate issue', () => { |
| 4 | + // https://github.com/oozcitak/xmlbuilder2/issues/90 |
| 5 | + describe(`#178 - Namespace is removed when importing fragments.`, () => { |
| 6 | + const expectedOutput = $$.t`<?xml version="1.0"?><Root xmlns="ns1"><Parent xmlns="ns2"><Child xmlns="ns3"><GrandChild xmlns="ns4">txt</GrandChild></Child></Parent></Root>`; |
| 7 | + describe(`with defined namespaces on each element`, () => { |
| 8 | + test(`using .ele()`, () => { |
| 9 | + const doc = $$.create(); |
| 10 | + const root = doc.ele('ns1', 'Root'); |
| 11 | + const parent = root.ele('ns2', 'Parent'); |
| 12 | + const child = parent.ele('ns3', 'Child'); |
| 13 | + child.ele('ns4', 'GrandChild').txt('txt'); |
| 14 | + |
| 15 | + expect(doc.end()).toBe(expectedOutput); |
| 16 | + }); |
| 17 | + test(`using .import()`, () => { |
| 18 | + const doc = $$.create(); |
| 19 | + const root = doc.ele('ns1', 'Root'); |
| 20 | + const parent = $$.fragment().ele('ns2', 'Parent'); |
| 21 | + const child = $$.fragment().ele('ns3', 'Child'); |
| 22 | + const grandChild = $$.fragment().ele('ns4', 'GrandChild').txt('txt'); |
| 23 | + |
| 24 | + child.import(grandChild); |
| 25 | + parent.import(child); |
| 26 | + root.import(parent); |
| 27 | + |
| 28 | + expect(doc.end()).toBe(expectedOutput); |
| 29 | + }); |
| 30 | + }); |
| 31 | + describe(`with undefined namespaces on parent element`, () => { |
| 32 | + const expectedOutput = $$.t`<?xml version="1.0"?><Root xmlns="ns1"><Parent><Child xmlns="ns3"><GrandChild xmlns="ns4">txt</GrandChild></Child></Parent></Root>`; |
| 33 | + test(`using .ele()`, () => { |
| 34 | + const doc = $$.create(); |
| 35 | + const root = doc.ele('ns1', 'Root'); |
| 36 | + const parent = root.ele('Parent'); |
| 37 | + const child = parent.ele('ns3', 'Child'); |
| 38 | + child.ele('ns4', 'GrandChild').txt('txt'); |
| 39 | + |
| 40 | + expect(doc.end()).toBe(expectedOutput); |
| 41 | + }); |
| 42 | + test(`using .import()`, () => { |
| 43 | + const doc = $$.create(); |
| 44 | + const root = doc.ele('ns1', 'Root'); |
| 45 | + const parent = $$.fragment().ele('Parent'); |
| 46 | + const child = $$.fragment().ele('ns3', 'Child'); |
| 47 | + const grandChild = $$.fragment().ele('ns4', 'GrandChild').txt('txt'); |
| 48 | + |
| 49 | + child.import(grandChild); |
| 50 | + parent.import(child); |
| 51 | + root.import(parent); |
| 52 | + |
| 53 | + expect(doc.end()).toBe(expectedOutput); |
| 54 | + }); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments