-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Fix cloning pages issue (#6291)
1 parent
ef26212
commit 8605e40
Showing
2 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/core/test/specs/dom_components/model/ComponentWrapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Component from '../../../../src/dom_components/model/Component'; | ||
import ComponentHead from '../../../../src/dom_components/model/ComponentHead'; | ||
import Editor from '../../../../src/editor'; | ||
|
||
describe('ComponentWrapper', () => { | ||
let em: Editor; | ||
|
||
beforeEach(() => { | ||
em = new Editor({ avoidDefaults: true }); | ||
em.Pages.onLoad(); | ||
}); | ||
|
||
describe('.clone', () => { | ||
test('clones the component and returns a new instance for head and document element', () => { | ||
const originalComponent = em.Pages.getSelected()?.getMainComponent(); | ||
const clonedComponent = originalComponent?.clone(); | ||
em.Pages.add( | ||
{ | ||
id: 'PAGE_ID', | ||
clonedComponent, | ||
}, | ||
{ | ||
select: true, | ||
}, | ||
); | ||
const newPageComponent = em.Pages.get('PAGE_ID')?.getMainComponent(); | ||
|
||
expect(clonedComponent?.head).toBeInstanceOf(ComponentHead); | ||
expect(clonedComponent?.head.cid).not.toEqual(originalComponent?.head.cid); | ||
|
||
expect(clonedComponent?.docEl).toBeInstanceOf(Component); | ||
expect(clonedComponent?.docEl.cid).not.toEqual(originalComponent?.docEl.cid); | ||
expect(newPageComponent?.head.cid).not.toEqual(originalComponent?.head.cid); | ||
}); | ||
}); | ||
}); |