diff --git a/src/notification.rs b/src/notification.rs index 8569d4d..b84535f 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -101,37 +101,13 @@ mod tests { use insta::assert_snapshot; use ratatui::{Terminal, backend::TestBackend}; use rstest::rstest; + use std::hash::{DefaultHasher, Hash, Hasher}; #[rstest] fn render_good( - #[values("short", "with\nnewline")] message_str: &'static str, - #[values( - NotificationLevel::Info, - NotificationLevel::Warning, - NotificationLevel::Error - )] - level: NotificationLevel, - ) { - let mut terminal = Terminal::new(TestBackend::new(80, 24)).unwrap(); - terminal - .draw(|frame| { - let notification = Notification { - message: message_str.into(), - level: level.clone(), - ttl: 1, - }; - notification.render(0, frame, frame.area()); - }) - .unwrap(); - - let snapshot_name = format!("{}-{:?}", message_str, level); - assert_snapshot!(snapshot_name, terminal.backend()); - } - - #[rstest] - #[should_panic(expected = "File name too long")] - fn render_bad( #[values( + "short", + "with\nnewline", "extremely long WITHOUT newline Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id mauris sit amet libero convallis fringilla quis non augue. In sollicitudin quam sed magna finibus, vitae malesuada magna porttitor. Pellentesque in dictum dui. Nullam nec mi venenatis, faucibus odio eget, molestie nisi. Fusce velit nibh, euismod vel lectus id, placerat.", r"extremely long WITH newline Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id mauris sit amet libero convallis fringilla quis non @@ -159,7 +135,11 @@ nisi. Fusce velit nibh, euismod vel lectus id, placerat." }) .unwrap(); - let snapshot_name = format!("{}-{:?}", message_str, level); + let mut hasher = DefaultHasher::new(); + message_str.hash(&mut hasher); + let hash = hasher.finish(); + + let snapshot_name = format!("{}-{:?}", hash, level); assert_snapshot!(snapshot_name, terminal.backend()); } } diff --git a/src/snapshots/bluetui__notification__tests__10048321478723220837-Error.snap b/src/snapshots/bluetui__notification__tests__10048321478723220837-Error.snap new file mode 100644 index 0000000..b81a348 --- /dev/null +++ b/src/snapshots/bluetui__notification__tests__10048321478723220837-Error.snap @@ -0,0 +1,28 @@ +--- +source: src/notification.rs +expression: terminal.backend() +--- +" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ " +" ┃ Error ┃ " +" ┃ extremely long WITH newline Lorem ipsum dolor sit amet, consectetur ┃ " +" ┃adipiscing elit. Sed id mauris sit amet libero convallis fringilla quis non┃ " +" ┃ augue. In sollicitudin quam sed magna finibus, vitae malesuada magna ┃ " +" ┃ porttitor. ┃ " +" ┃ Pellentesque in dictum dui. Nullam nec mi venenatis, faucibus odio eget, ┃ " +" ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " diff --git a/src/snapshots/bluetui__notification__tests__10048321478723220837-Info.snap b/src/snapshots/bluetui__notification__tests__10048321478723220837-Info.snap new file mode 100644 index 0000000..2b2de5f --- /dev/null +++ b/src/snapshots/bluetui__notification__tests__10048321478723220837-Info.snap @@ -0,0 +1,28 @@ +--- +source: src/notification.rs +expression: terminal.backend() +--- +" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ " +" ┃ Info ┃ " +" ┃ extremely long WITH newline Lorem ipsum dolor sit amet, consectetur ┃ " +" ┃adipiscing elit. Sed id mauris sit amet libero convallis fringilla quis non┃ " +" ┃ augue. In sollicitudin quam sed magna finibus, vitae malesuada magna ┃ " +" ┃ porttitor. ┃ " +" ┃ Pellentesque in dictum dui. Nullam nec mi venenatis, faucibus odio eget, ┃ " +" ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " diff --git a/src/snapshots/bluetui__notification__tests__10048321478723220837-Warning.snap b/src/snapshots/bluetui__notification__tests__10048321478723220837-Warning.snap new file mode 100644 index 0000000..9379d69 --- /dev/null +++ b/src/snapshots/bluetui__notification__tests__10048321478723220837-Warning.snap @@ -0,0 +1,28 @@ +--- +source: src/notification.rs +expression: terminal.backend() +--- +" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ " +" ┃ Warning ┃ " +" ┃ extremely long WITH newline Lorem ipsum dolor sit amet, consectetur ┃ " +" ┃adipiscing elit. Sed id mauris sit amet libero convallis fringilla quis non┃ " +" ┃ augue. In sollicitudin quam sed magna finibus, vitae malesuada magna ┃ " +" ┃ porttitor. ┃ " +" ┃ Pellentesque in dictum dui. Nullam nec mi venenatis, faucibus odio eget, ┃ " +" ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " +" " diff --git a/src/snapshots/bluetui__notification__tests__short-Error.snap b/src/snapshots/bluetui__notification__tests__11353925441405961020-Error.snap similarity index 100% rename from src/snapshots/bluetui__notification__tests__short-Error.snap rename to src/snapshots/bluetui__notification__tests__11353925441405961020-Error.snap diff --git a/src/snapshots/bluetui__notification__tests__short-Info.snap b/src/snapshots/bluetui__notification__tests__11353925441405961020-Info.snap similarity index 100% rename from src/snapshots/bluetui__notification__tests__short-Info.snap rename to src/snapshots/bluetui__notification__tests__11353925441405961020-Info.snap diff --git a/src/snapshots/bluetui__notification__tests__short-Warning.snap b/src/snapshots/bluetui__notification__tests__11353925441405961020-Warning.snap similarity index 100% rename from src/snapshots/bluetui__notification__tests__short-Warning.snap rename to src/snapshots/bluetui__notification__tests__11353925441405961020-Warning.snap diff --git "a/src/snapshots/bluetui__notification__tests__with\nnewline-Error.snap" b/src/snapshots/bluetui__notification__tests__15528810436234314490-Error.snap similarity index 100% rename from "src/snapshots/bluetui__notification__tests__with\nnewline-Error.snap" rename to src/snapshots/bluetui__notification__tests__15528810436234314490-Error.snap diff --git "a/src/snapshots/bluetui__notification__tests__with\nnewline-Info.snap" b/src/snapshots/bluetui__notification__tests__15528810436234314490-Info.snap similarity index 100% rename from "src/snapshots/bluetui__notification__tests__with\nnewline-Info.snap" rename to src/snapshots/bluetui__notification__tests__15528810436234314490-Info.snap diff --git "a/src/snapshots/bluetui__notification__tests__with\nnewline-Warning.snap" b/src/snapshots/bluetui__notification__tests__15528810436234314490-Warning.snap similarity index 100% rename from "src/snapshots/bluetui__notification__tests__with\nnewline-Warning.snap" rename to src/snapshots/bluetui__notification__tests__15528810436234314490-Warning.snap diff --git "a/src/snapshots/bluetui__notification__tests__longer with\nnewline-Error.snap" b/src/snapshots/bluetui__notification__tests__16756392106269011238-Error.snap similarity index 71% rename from "src/snapshots/bluetui__notification__tests__longer with\nnewline-Error.snap" rename to src/snapshots/bluetui__notification__tests__16756392106269011238-Error.snap index 5159f20..2d1a469 100644 --- "a/src/snapshots/bluetui__notification__tests__longer with\nnewline-Error.snap" +++ b/src/snapshots/bluetui__notification__tests__16756392106269011238-Error.snap @@ -2,11 +2,11 @@ source: src/notification.rs expression: terminal.backend() --- -" ┏━━━━━━━━━━━━━┓ " -" ┃ Error ┃ " -" ┃ longer with ┃ " -" ┃ newline ┃ " -" ┗━━━━━━━━━━━━━┛ " +" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ " +" ┃ Error ┃ " +" ┃ extremely long WITHOUT newline Lorem ipsum dolor sit amet, consectetur ┃ " +" ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ " +" " " " " " " " diff --git "a/src/snapshots/bluetui__notification__tests__longer with\nnewline-Info.snap" b/src/snapshots/bluetui__notification__tests__16756392106269011238-Info.snap similarity index 71% rename from "src/snapshots/bluetui__notification__tests__longer with\nnewline-Info.snap" rename to src/snapshots/bluetui__notification__tests__16756392106269011238-Info.snap index 320de75..903984e 100644 --- "a/src/snapshots/bluetui__notification__tests__longer with\nnewline-Info.snap" +++ b/src/snapshots/bluetui__notification__tests__16756392106269011238-Info.snap @@ -2,11 +2,11 @@ source: src/notification.rs expression: terminal.backend() --- -" ┏━━━━━━━━━━━━━┓ " -" ┃ Info ┃ " -" ┃ longer with ┃ " -" ┃ newline ┃ " -" ┗━━━━━━━━━━━━━┛ " +" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ " +" ┃ Info ┃ " +" ┃ extremely long WITHOUT newline Lorem ipsum dolor sit amet, consectetur ┃ " +" ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ " +" " " " " " " " diff --git "a/src/snapshots/bluetui__notification__tests__longer with\nnewline-Warning.snap" b/src/snapshots/bluetui__notification__tests__16756392106269011238-Warning.snap similarity index 71% rename from "src/snapshots/bluetui__notification__tests__longer with\nnewline-Warning.snap" rename to src/snapshots/bluetui__notification__tests__16756392106269011238-Warning.snap index 0255284..e57f06f 100644 --- "a/src/snapshots/bluetui__notification__tests__longer with\nnewline-Warning.snap" +++ b/src/snapshots/bluetui__notification__tests__16756392106269011238-Warning.snap @@ -2,11 +2,11 @@ source: src/notification.rs expression: terminal.backend() --- -" ┏━━━━━━━━━━━━━┓ " -" ┃ Warning ┃ " -" ┃ longer with ┃ " -" ┃ newline ┃ " -" ┗━━━━━━━━━━━━━┛ " +" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ " +" ┃ Warning ┃ " +" ┃ extremely long WITHOUT newline Lorem ipsum dolor sit amet, consectetur ┃ " +" ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ " +" " " " " " " "