Skip to content

Commit

Permalink
test: add image test for md_importer
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Nov 2, 2024
1 parent be6bb90 commit d390d67
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions collab-document/tests/importer/md_importer_customer_test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use collab_document::importer::define::{BlockType, URL_FIELD};
use serde_json::json;

use crate::importer::util::{
Expand Down Expand Up @@ -373,3 +374,52 @@ fn test_customer_image_in_first_level() {
"https://example.com/image.png"
);
}

#[test]
fn test_customer_image_in_nested_level_1() {
// notes: there's a empty line between the first nested bulleted item and the image
let markdown = r#"
- 7/18 Consumption Spike issue
- 7/19 Contacted Enphase and they are going to clear spike with case #16518709 - they said the update on the 18th caused the snike
![Untitled](Untitled.png)
"#;

let result = markdown_to_document_data(markdown);

let page_block = get_page_block(&result);
let children_blocks = get_children_blocks(&result, &page_block.id);

// - First bulleted item
let delta = get_delta(&result, &children_blocks[0].id);
assert_eq!(children_blocks.len(), 1);
assert_eq!(children_blocks[0].ty, BlockType::BulletedList.to_string());
assert_eq!(delta, r#"[{"insert":"7/18 Consumption Spike issue"}]"#);

// - First nested bulleted item
let children_blocks_1 = get_children_blocks(&result, &children_blocks[0].id);
let delta = get_delta(&result, &children_blocks_1[0].id);
assert_eq!(children_blocks_1.len(), 1);
assert_eq!(children_blocks_1[0].ty, BlockType::BulletedList.to_string());
assert_eq!(
delta,
r#"[{"insert":"7/19 Contacted Enphase and they are going to clear spike with case #16518709 - they said the update on the 18th caused the snike"}]"#
);

// Image under the first nested bulleted item
let children_blocks_1_1 = get_children_blocks(&result, &children_blocks_1[0].id);
assert_eq!(children_blocks_1_1.len(), 1);
assert_eq!(children_blocks_1_1[0].ty, BlockType::Image.to_string());
assert_eq!(
children_blocks_1_1[0].data.get(URL_FIELD).unwrap(),
"Untitled.png"
);

let blocks = result.blocks;
for value in blocks.iter() {
let block = value.1;
if block.ty == BlockType::Image.to_string() {
assert_eq!(block.data.get(URL_FIELD).unwrap(), "Untitled.png");
}
}
}

0 comments on commit d390d67

Please sign in to comment.