|
| 1 | +use crate::blocks::block_test_core::{BlockTestCore, generate_id}; |
| 2 | +use collab::document::block_parser::parsers::ai_meeting::AiMeetingParser; |
| 3 | +use collab::document::block_parser::{BlockParser, DocumentParser, OutputFormat, ParseContext}; |
| 4 | +use collab::document::blocks::{Block, BlockType}; |
| 5 | +use serde_json::json; |
| 6 | +use std::collections::HashMap; |
| 7 | + |
| 8 | +fn create_ai_meeting_block(test: &mut BlockTestCore, parent_id: &str) -> Block { |
| 9 | + create_block(test, BlockType::AiMeeting, parent_id) |
| 10 | +} |
| 11 | + |
| 12 | +fn create_ai_meeting_summary_block(test: &mut BlockTestCore, parent_id: &str) -> Block { |
| 13 | + create_block(test, BlockType::AiMeetingSummary, parent_id) |
| 14 | +} |
| 15 | + |
| 16 | +fn create_ai_meeting_notes_block(test: &mut BlockTestCore, parent_id: &str) -> Block { |
| 17 | + create_block(test, BlockType::AiMeetingNotes, parent_id) |
| 18 | +} |
| 19 | + |
| 20 | +fn create_ai_meeting_transcription_block(test: &mut BlockTestCore, parent_id: &str) -> Block { |
| 21 | + create_block(test, BlockType::AiMeetingTranscription, parent_id) |
| 22 | +} |
| 23 | + |
| 24 | +fn create_block(test: &mut BlockTestCore, ty: BlockType, parent_id: &str) -> Block { |
| 25 | + let data = HashMap::new(); |
| 26 | + let actual_parent_id = if parent_id.is_empty() { |
| 27 | + test.get_page().id |
| 28 | + } else { |
| 29 | + parent_id.to_string() |
| 30 | + }; |
| 31 | + |
| 32 | + let block = Block { |
| 33 | + id: generate_id(), |
| 34 | + ty: ty.as_str().to_string(), |
| 35 | + parent: actual_parent_id, |
| 36 | + children: generate_id(), |
| 37 | + external_id: None, |
| 38 | + external_type: None, |
| 39 | + data, |
| 40 | + }; |
| 41 | + |
| 42 | + test.document.insert_block(block, None).unwrap() |
| 43 | +} |
| 44 | + |
| 45 | +fn create_text_block(test: &mut BlockTestCore, text: &str, parent_id: &str) -> Block { |
| 46 | + let delta = json!([{ "insert": text }]).to_string(); |
| 47 | + let external_id = test.create_text(delta); |
| 48 | + let data = HashMap::new(); |
| 49 | + |
| 50 | + let block = Block { |
| 51 | + id: generate_id(), |
| 52 | + ty: BlockType::Paragraph.as_str().to_string(), |
| 53 | + parent: parent_id.to_string(), |
| 54 | + children: generate_id(), |
| 55 | + external_id: Some(external_id), |
| 56 | + external_type: Some("text".to_string()), |
| 57 | + data, |
| 58 | + }; |
| 59 | + test.document.insert_block(block, None).unwrap() |
| 60 | +} |
| 61 | + |
| 62 | +fn create_heading_block( |
| 63 | + test: &mut BlockTestCore, |
| 64 | + text: &str, |
| 65 | + level: u32, |
| 66 | + parent_id: &str, |
| 67 | +) -> Block { |
| 68 | + let delta = json!([{ "insert": text }]).to_string(); |
| 69 | + let external_id = test.create_text(delta); |
| 70 | + let mut data = HashMap::new(); |
| 71 | + data.insert("level".to_string(), json!(level)); |
| 72 | + |
| 73 | + let block = Block { |
| 74 | + id: generate_id(), |
| 75 | + ty: BlockType::Heading.as_str().to_string(), |
| 76 | + parent: parent_id.to_string(), |
| 77 | + children: generate_id(), |
| 78 | + external_id: Some(external_id), |
| 79 | + external_type: Some("text".to_string()), |
| 80 | + data, |
| 81 | + }; |
| 82 | + test.document.insert_block(block, None).unwrap() |
| 83 | +} |
| 84 | + |
| 85 | +#[test] |
| 86 | +fn test_ai_meeting_parser() { |
| 87 | + let mut test = BlockTestCore::new(); |
| 88 | + let document_parser = DocumentParser::with_default_parsers(); |
| 89 | + |
| 90 | + let ai_meeting = create_ai_meeting_block(&mut test, ""); |
| 91 | + |
| 92 | + let transcription = create_ai_meeting_transcription_block(&mut test, &ai_meeting.id); |
| 93 | + create_text_block(&mut test, "Transcription content.", &transcription.id); |
| 94 | + |
| 95 | + let notes = create_ai_meeting_notes_block(&mut test, &ai_meeting.id); |
| 96 | + create_text_block(&mut test, "Notes content.", ¬es.id); |
| 97 | + |
| 98 | + let summary = create_ai_meeting_summary_block(&mut test, &ai_meeting.id); |
| 99 | + create_text_block(&mut test, "Summary content.", &summary.id); |
| 100 | + create_heading_block(&mut test, "Overview", 4, &summary.id); |
| 101 | + |
| 102 | + let document_data = test.get_document_data(); |
| 103 | + let context = ParseContext::new(&document_data, &document_parser, OutputFormat::Markdown); |
| 104 | + |
| 105 | + let result = document_parser.parse_block(&ai_meeting, &context).unwrap(); |
| 106 | + |
| 107 | + let expected = r#"#### Overview |
| 108 | +Summary content. |
| 109 | +Notes content. |
| 110 | +Transcription content."#; |
| 111 | + |
| 112 | + assert_eq!(result, expected); |
| 113 | +} |
| 114 | + |
| 115 | +#[test] |
| 116 | +fn test_ai_meeting_parser_plain_text() { |
| 117 | + let mut test = BlockTestCore::new(); |
| 118 | + let document_parser = DocumentParser::with_default_parsers(); |
| 119 | + |
| 120 | + let ai_meeting = create_ai_meeting_block(&mut test, ""); |
| 121 | + |
| 122 | + let transcription = create_ai_meeting_transcription_block(&mut test, &ai_meeting.id); |
| 123 | + create_text_block(&mut test, "Transcription content.", &transcription.id); |
| 124 | + |
| 125 | + let notes = create_ai_meeting_notes_block(&mut test, &ai_meeting.id); |
| 126 | + create_text_block(&mut test, "Notes content.", ¬es.id); |
| 127 | + |
| 128 | + let summary = create_ai_meeting_summary_block(&mut test, &ai_meeting.id); |
| 129 | + create_text_block(&mut test, "Summary content.", &summary.id); |
| 130 | + create_heading_block(&mut test, "Overview", 4, &summary.id); |
| 131 | + |
| 132 | + let document_data = test.get_document_data(); |
| 133 | + let context = ParseContext::new(&document_data, &document_parser, OutputFormat::PlainText); |
| 134 | + |
| 135 | + let result = document_parser.parse_block(&ai_meeting, &context).unwrap(); |
| 136 | + |
| 137 | + let expected = r#"Overview |
| 138 | +Summary content. |
| 139 | +Notes content. |
| 140 | +Transcription content."#; |
| 141 | + |
| 142 | + assert_eq!(result, expected); |
| 143 | +} |
0 commit comments