From 90f69c3f2dfdca2f755c5bdfe423aca2ed154625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=B1=B9=E5=B3=B0?= <> Date: Thu, 4 Aug 2022 19:43:44 +0800 Subject: [PATCH] test: add grid URL unit tests --- .../type_options/url_type_option/url_tests.rs | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs index ba221853bb..3cf5d6f99b 100644 --- a/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs +++ b/frontend/rust-lib/flowy-grid/src/services/field/type_options/url_type_option/url_tests.rs @@ -14,6 +14,7 @@ mod tests { let field_type = FieldType::URL; let field_rev = FieldBuilder::from_field_type(&field_type).build(); assert_url(&type_option, "123", "123", "", &field_type, &field_rev); + assert_url(&type_option, "", "", "", &field_type, &field_rev); } /// The expected_str will equal to the input string, but the expected_url will not be empty @@ -42,6 +43,124 @@ mod tests { ); } + /// if there's a http url and some words following it in the input string. + #[test] + fn url_type_option_contains_url_with_string_after_test() { + let type_option = URLTypeOption::default(); + let field_type = FieldType::URL; + let field_rev = FieldBuilder::from_field_type(&field_type).build(); + assert_url( + &type_option, + "AppFlowy website - https://www.appflowy.io welcome!", + "AppFlowy website - https://www.appflowy.io welcome!", + "https://www.appflowy.io/", + &field_type, + &field_rev, + ); + + assert_url( + &type_option, + "AppFlowy website appflowy.io welcome!", + "AppFlowy website appflowy.io welcome!", + "https://appflowy.io", + &field_type, + &field_rev, + ); + } + + /// if there's a http url and special words following it in the input string. + #[test] + fn url_type_option_contains_url_with_special_string_after_test() { + let type_option = URLTypeOption::default(); + let field_type = FieldType::URL; + let field_rev = FieldBuilder::from_field_type(&field_type).build(); + assert_url( + &type_option, + "AppFlowy website - https://www.appflowy.io!", + "AppFlowy website - https://www.appflowy.io!", + "https://www.appflowy.io/", + &field_type, + &field_rev, + ); + + assert_url( + &type_option, + "AppFlowy website appflowy.io!", + "AppFlowy website appflowy.io!", + "https://appflowy.io", + &field_type, + &field_rev, + ); + } + + /// if there's a level4 url in the input string. + #[test] + fn level4_url_type_test() { + let type_option = URLTypeOption::default(); + let field_type = FieldType::URL; + let field_rev = FieldBuilder::from_field_type(&field_type).build(); + assert_url( + &type_option, + "test - https://tester.testgroup.appflowy.io", + "test - https://tester.testgroup.appflowy.io", + "https://tester.testgroup.appflowy.io/", + &field_type, + &field_rev, + ); + + assert_url( + &type_option, + "test tester.testgroup.appflowy.io", + "test tester.testgroup.appflowy.io", + "https://tester.testgroup.appflowy.io", + &field_type, + &field_rev, + ); + } + + /// urls with different top level domains. + #[test] + fn different_top_level_domains_test() { + let type_option = URLTypeOption::default(); + let field_type = FieldType::URL; + let field_rev = FieldBuilder::from_field_type(&field_type).build(); + assert_url( + &type_option, + "appflowy - https://appflowy.com", + "appflowy - https://appflowy.com", + "https://appflowy.com/", + &field_type, + &field_rev, + ); + + assert_url( + &type_option, + "appflowy - https://appflowy.top", + "appflowy - https://appflowy.top", + "https://appflowy.top/", + &field_type, + &field_rev, + ); + + assert_url( + &type_option, + "appflowy - https://appflowy.net", + "appflowy - https://appflowy.net", + "https://appflowy.net/", + &field_type, + &field_rev, + ); + + assert_url( + &type_option, + "appflowy - https://appflowy.edu", + "appflowy - https://appflowy.edu", + "https://appflowy.edu/", + &field_type, + &field_rev, + ); + } + fn assert_url( type_option: &URLTypeOption, input_str: &str,