-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix "replace" when moving children in the collection (#711)
- Loading branch information
1 parent
249952c
commit cc48859
Showing
2 changed files
with
59 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import random | ||
|
||
import flet as ft | ||
|
||
|
||
def test_moving_children(): | ||
c = ft.Stack() | ||
c._Control__uid = "0" | ||
for i in range(0, 10): | ||
c.controls.append(ft.Container()) | ||
c.controls[i]._Control__uid = f"_{i}" | ||
|
||
index = [] | ||
added_controls = [] | ||
commands = [] | ||
c.build_update_commands(index, added_controls, commands, False) | ||
|
||
def replace_controls(c): | ||
random.shuffle(c.controls) | ||
commands.clear() | ||
|
||
# print("=======") | ||
r = set() | ||
for ctrl in c.controls: | ||
# print(ctrl._Control__uid) | ||
r.add(ctrl._Control__uid) | ||
c.build_update_commands(index, added_controls, commands, False) | ||
for cmd in commands: | ||
if cmd.name == "add": | ||
for sub_cmd in cmd.commands: | ||
# print("add", sub_cmd.attrs["id"], "at", cmd.attrs["at"]) | ||
r.add(sub_cmd.attrs["id"]) | ||
elif cmd.name == "remove": | ||
for v in cmd.values: | ||
# print("remove", v) | ||
r.remove(v) | ||
# print(r) | ||
assert len(r) == len(c.controls) | ||
|
||
for i in range(0, 20): | ||
replace_controls(c) |