-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core/tree): initializing tree (#319)
Co-authored-by: Daniel Leroux <daniel.leroux@siemens.com>
- Loading branch information
1 parent
f45ac44
commit 7d9b373
Showing
9 changed files
with
178 additions
and
14 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
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
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,75 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: 2022 Siemens AG | ||
SPDX-License-Identifier: MIT | ||
--> | ||
|
||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" | ||
/> | ||
<title>Stencil Component Starter</title> | ||
</head> | ||
<body> | ||
<div style="height: 12rem; width: 100%"> | ||
<ix-tree root="root" id="tree"></ix-tree> | ||
</div> | ||
|
||
<script> | ||
(async () => { | ||
await window.customElements.whenDefined('ix-tree'); | ||
const tree = document.getElementById('tree'); | ||
const context = { | ||
root: { | ||
isExpanded: true, | ||
isSelected: false, | ||
}, | ||
sample: { | ||
isExpanded: true, | ||
isSelected: false, | ||
}, | ||
}; | ||
|
||
const model = { | ||
root: { | ||
id: 'root', | ||
children: ['sample'], | ||
hasChildren: true, | ||
data: { name: '' }, | ||
}, | ||
sample: { | ||
id: 'sample', | ||
children: [], | ||
hasChildren: true, | ||
data: { name: 'Sample' }, | ||
}, | ||
}; | ||
|
||
for (let i = 0; i < 100; i++) { | ||
const id = `sample-child-${i}`; | ||
model[id] = { | ||
id, | ||
data: { | ||
name: `Sample Child ${i}`, | ||
}, | ||
hasChildren: false, | ||
children: [], | ||
}; | ||
model.sample.children.push(id); | ||
} | ||
|
||
context['sample-child-85'] = { | ||
isExpanded: false, | ||
isSelected: true, | ||
}; | ||
|
||
tree.model = { ...model }; | ||
tree.context = { ...context }; | ||
})(); | ||
</script> | ||
<script src="http://127.0.0.1:8080/scripts/e2e/load-e2e-runtime.js"></script> | ||
</body> | ||
</html> |
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,73 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { expect } from '@playwright/test'; | ||
import { regressionTest } from '@utils/test'; | ||
|
||
regressionTest.describe('tree', () => { | ||
regressionTest('should append item to tree', async ({ page }) => { | ||
await page.goto('tree/test/basic'); | ||
|
||
const treeViewportHandle = await page.waitForSelector('ix-tree'); | ||
|
||
await page.evaluate((tree) => { | ||
const model = tree.model; | ||
|
||
model['last-child'] = { | ||
id: 'last-child', | ||
children: [], | ||
hasChildren: false, | ||
data: { name: 'last-child' }, | ||
}; | ||
|
||
model['sample'].children.push('last-child'); | ||
|
||
tree.model = { ...model }; | ||
}, treeViewportHandle); | ||
|
||
await page.waitForTimeout(500); | ||
|
||
await page.evaluate((treeViewport) => { | ||
treeViewport.scrollTop = 32 * 999; | ||
}, treeViewportHandle); | ||
|
||
expect(await page.screenshot({ fullPage: true })).toMatchSnapshot(); | ||
}); | ||
|
||
regressionTest('should keep scroll state', async ({ page }) => { | ||
await page.goto('tree/test/basic'); | ||
|
||
const treeViewportHandle = await page.waitForSelector('ix-tree'); | ||
|
||
await page.evaluate((treeViewport) => { | ||
treeViewport.scrollTop = 32 * 50; | ||
}, treeViewportHandle); | ||
|
||
await page.evaluate((tree) => { | ||
const model = tree.model; | ||
|
||
model['insert-below-50'] = { | ||
id: 'insert-below-50', | ||
children: [], | ||
hasChildren: false, | ||
data: { name: 'insert-below-50' }, | ||
}; | ||
|
||
const indexOfItem50 = tree.model.sample.children.findIndex( | ||
(id) => id === 'sample-child-50' | ||
); | ||
|
||
model['sample'].children.splice(indexOfItem50 + 1, 0, 'insert-below-50'); | ||
|
||
tree.model = { ...model }; | ||
}, treeViewportHandle); | ||
|
||
expect(await page.screenshot({ fullPage: true })).toMatchSnapshot(); | ||
}); | ||
}); |
Binary file added
BIN
+17.3 KB
...shots/tree-should-append-item-to-tree-1-chromium---theme-classic-dark-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17 KB
...hots/tree-should-append-item-to-tree-1-chromium---theme-classic-light-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.7 KB
...apshots/tree-should-keep-scroll-state-1-chromium---theme-classic-dark-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.4 KB
...pshots/tree-should-keep-scroll-state-1-chromium---theme-classic-light-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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