in components/places/src/storage/bookmarks.rs [1405:1551]
fn test_update() -> Result<()> {
let conn = new_mem_connection();
let unfiled = &BookmarkRootGuid::Unfiled.as_guid();
insert_json_tree(
&conn,
json!({
"guid": unfiled,
"children": [
{
"guid": "bookmark1___",
"title": "the bookmark",
"url": "https://www.example.com/"
},
{
"guid": "bookmark2___",
"title": "another bookmark",
"url": "https://www.example2.com/"
},
{
"guid": "folder1_____",
"title": "A folder",
"children": [
{
"guid": "bookmark3___",
"title": "bookmark in A folder",
"url": "https://www.example3.com/"
},
{
"guid": "bookmark4___",
"title": "next bookmark in A folder",
"url": "https://www.example4.com/"
},
{
"guid": "bookmark5___",
"title": "next next bookmark in A folder",
"url": "https://www.example5.com/"
}
]
},
{
"guid": "bookmark6___",
"title": "yet another bookmark",
"url": "https://www.example6.com/"
},
]
}),
);
update_bookmark(
&conn,
&"folder1_____".into(),
&UpdatableFolder {
title: Some("new name".to_string()),
..Default::default()
}
.into(),
)?;
update_bookmark(
&conn,
&"bookmark1___".into(),
&UpdatableBookmark {
url: Some(Url::parse("https://www.example3.com/")?),
title: None,
..Default::default()
}
.into(),
)?;
// A move in the same folder.
update_bookmark(
&conn,
&"bookmark6___".into(),
&UpdatableBookmark {
location: UpdateTreeLocation::Position {
pos: BookmarkPosition::Specific { pos: 2 },
},
..Default::default()
}
.into(),
)?;
// A move across folders.
update_bookmark(
&conn,
&"bookmark2___".into(),
&UpdatableBookmark {
location: UpdateTreeLocation::Parent {
guid: "folder1_____".into(),
pos: BookmarkPosition::Specific { pos: 1 },
},
..Default::default()
}
.into(),
)?;
assert_json_tree(
&conn,
unfiled,
json!({
"guid": unfiled,
"children": [
{
// We updated the url and title of this.
"guid": "bookmark1___",
"title": null,
"url": "https://www.example3.com/"
},
// We moved bookmark6 to position=2 (ie, 3rd) of the same
// parent, but then moved the existing 2nd item to the
// folder, so this ends up second.
{
"guid": "bookmark6___",
"url": "https://www.example6.com/"
},
{
// We changed the name of the folder.
"guid": "folder1_____",
"title": "new name",
"children": [
{
"guid": "bookmark3___",
"url": "https://www.example3.com/"
},
{
// This was moved from the parent to position 1
"guid": "bookmark2___",
"url": "https://www.example2.com/"
},
{
"guid": "bookmark4___",
"url": "https://www.example4.com/"
},
{
"guid": "bookmark5___",
"url": "https://www.example5.com/"
}
]
},
]
}),
);
Ok(())
}