mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 17:57:19 +02:00
Update tests
This commit is contained in:
parent
62a43c7196
commit
8465616621
2 changed files with 120 additions and 46 deletions
105
src/app.rs
105
src/app.rs
|
@ -1,4 +1,5 @@
|
||||||
use crate::calendar::Calendar;
|
use crate::calendar::Calendar;
|
||||||
|
use crate::config;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::help::Help;
|
use crate::help::Help;
|
||||||
|
@ -574,23 +575,26 @@ impl TTApp {
|
||||||
.get(&format!("color.{}priority.{}", tag_name, p))
|
.get(&format!("color.{}priority.{}", tag_name, p))
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
style = style.fg(c.fg).bg(c.bg);
|
style = config::blend(style, c);
|
||||||
for modifier in c.modifiers {
|
|
||||||
style = style.add_modifier(modifier);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
} else if tag_name == "project." {
|
||||||
if task
|
if let Some(p) = task.project() {
|
||||||
|
let c = self
|
||||||
|
.config
|
||||||
|
.color
|
||||||
|
.get(&format!("color.project.{}", p))
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_default();
|
||||||
|
style = config::blend(style, c);
|
||||||
|
}
|
||||||
|
} else if task
|
||||||
.tags()
|
.tags()
|
||||||
.unwrap_or(&vec![])
|
.unwrap_or(&vec![])
|
||||||
.contains(&tag_name.to_string().replace(".", "").to_uppercase())
|
.contains(&tag_name.to_string().replace(".", "").to_uppercase())
|
||||||
{
|
{
|
||||||
let color_tag_name = format!("color.{}", tag_name);
|
let color_tag_name = format!("color.{}", tag_name);
|
||||||
let c = self.config.color.get(&color_tag_name).cloned().unwrap_or_default();
|
let c = self.config.color.get(&color_tag_name).cloned().unwrap_or_default();
|
||||||
style = style.fg(c.fg).bg(c.bg);
|
style = config::blend(style, c);
|
||||||
for modifier in c.modifiers {
|
|
||||||
style = style.add_modifier(modifier);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1353,11 +1357,10 @@ impl TTApp {
|
||||||
let reference = TimeZone::from_utc_datetime(now.offset(), d);
|
let reference = TimeZone::from_utc_datetime(now.offset(), d);
|
||||||
let now = TimeZone::from_utc_datetime(now.offset(), &now.naive_utc());
|
let now = TimeZone::from_utc_datetime(now.offset(), &now.naive_utc());
|
||||||
let d = d.clone();
|
let d = d.clone();
|
||||||
let reference = reference - chrono::Duration::nanoseconds(1);
|
if (reference - chrono::Duration::nanoseconds(1)).month() == now.month() {
|
||||||
if reference.month() == now.month() {
|
|
||||||
add_tag(&mut task, "MONTH".to_string());
|
add_tag(&mut task, "MONTH".to_string());
|
||||||
}
|
}
|
||||||
if reference.month() % 4 == now.month() % 4 {
|
if (reference - chrono::Duration::nanoseconds(1)).month() % 4 == now.month() % 4 {
|
||||||
add_tag(&mut task, "QUARTER".to_string());
|
add_tag(&mut task, "QUARTER".to_string());
|
||||||
}
|
}
|
||||||
match get_date_state(&d, self.config.due) {
|
match get_date_state(&d, self.config.due) {
|
||||||
|
@ -1367,6 +1370,12 @@ impl TTApp {
|
||||||
}
|
}
|
||||||
DateState::AfterToday => {
|
DateState::AfterToday => {
|
||||||
add_tag(&mut task, "DUE".to_string());
|
add_tag(&mut task, "DUE".to_string());
|
||||||
|
if reference.day() == now.day() + 1 {
|
||||||
|
add_tag(&mut task, "TOMORROW".to_string());
|
||||||
|
}
|
||||||
|
if reference.year() == now.year() {
|
||||||
|
add_tag(&mut task, "YEAR".to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
@ -1701,15 +1710,67 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_task_style() {
|
fn test_task_tags() {
|
||||||
let app = TTApp::new();
|
let app = TTApp::new().unwrap();
|
||||||
match app {
|
let task = app.task_by_id(1).unwrap();
|
||||||
Ok(app) => {
|
|
||||||
if let Some(task) = app.task_by_id(1) {
|
let tags = vec!["PENDING".to_string(), "PRIORITY".to_string()];
|
||||||
let style = app.style_for_task(&task);
|
|
||||||
}
|
for tag in tags {
|
||||||
}
|
assert!(task.tags().unwrap().contains(&tag));
|
||||||
_ => {}
|
}
|
||||||
|
|
||||||
|
let app = TTApp::new().unwrap();
|
||||||
|
let task = app.task_by_id(11).unwrap();
|
||||||
|
let tags = vec![
|
||||||
|
"COLOR",
|
||||||
|
"PENDING",
|
||||||
|
"ANNOTATED",
|
||||||
|
"TAGGED",
|
||||||
|
// "MONTH",
|
||||||
|
// "QUARTER",
|
||||||
|
// "DUE",
|
||||||
|
// "TOMORROW",
|
||||||
|
// "YEAR",
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
for tag in tags {
|
||||||
|
assert!(task.tags().unwrap().contains(&tag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_task_style() {
|
||||||
|
let app = TTApp::new().unwrap();
|
||||||
|
let task = app.task_by_id(1).unwrap();
|
||||||
|
for r in vec![
|
||||||
|
"deleted",
|
||||||
|
"completed",
|
||||||
|
"active",
|
||||||
|
"keyword.",
|
||||||
|
"tag.",
|
||||||
|
"project.",
|
||||||
|
"overdue",
|
||||||
|
"scheduled",
|
||||||
|
"due.today",
|
||||||
|
"due",
|
||||||
|
"blocked",
|
||||||
|
"blocking",
|
||||||
|
"recurring",
|
||||||
|
"tagged",
|
||||||
|
"uda.",
|
||||||
|
] {
|
||||||
|
assert!(app.config.rule_precedence_color.contains(&r.to_string()));
|
||||||
|
}
|
||||||
|
let style = app.style_for_task(&task);
|
||||||
|
|
||||||
|
dbg!(style);
|
||||||
|
assert!(style == Style::default().fg(Color::Green).bg(Color::Reset));
|
||||||
|
|
||||||
|
let task = app.task_by_id(11).unwrap();
|
||||||
|
let style = app.style_for_task(&task);
|
||||||
|
dbg!(style);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,18 @@ use std::collections::HashMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::str;
|
use std::str;
|
||||||
use tui::style::{Color, Modifier};
|
use tui::style::{Color, Modifier, Style};
|
||||||
|
|
||||||
|
pub fn blend(style: Style, c: TColor) -> Style {
|
||||||
|
let mut style = style.fg(c.fg);
|
||||||
|
if style.bg.is_none() || c.bg != Color::Reset {
|
||||||
|
style = style.bg(c.bg);
|
||||||
|
}
|
||||||
|
for modifier in c.modifiers {
|
||||||
|
style = style.add_modifier(modifier);
|
||||||
|
}
|
||||||
|
style
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TColor {
|
pub struct TColor {
|
||||||
|
@ -29,6 +40,8 @@ impl TColor {
|
||||||
pub fn new(fg: Color, bg: Color, modifiers: Vec<Modifier>) -> Self {
|
pub fn new(fg: Color, bg: Color, modifiers: Vec<Modifier>) -> Self {
|
||||||
Self { fg, bg, modifiers }
|
Self { fg, bg, modifiers }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn blend(&mut self, c: Color) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait TaskWarriorBool {
|
trait TaskWarriorBool {
|
||||||
|
@ -191,37 +204,37 @@ impl Config {
|
||||||
let c = 16 + red * 36 + green * 6 + blue;
|
let c = 16 + red * 36 + green * 6 + blue;
|
||||||
Color::Indexed(c)
|
Color::Indexed(c)
|
||||||
} else if s == "bright red" {
|
} else if s == "bright red" {
|
||||||
Color::Red
|
|
||||||
} else if s == "bright green" {
|
|
||||||
Color::Green
|
|
||||||
} else if s == "bright yellow" {
|
|
||||||
Color::Yellow
|
|
||||||
} else if s == "bright blue" {
|
|
||||||
Color::Blue
|
|
||||||
} else if s == "bright magenta" {
|
|
||||||
Color::Magenta
|
|
||||||
} else if s == "bright cyan" {
|
|
||||||
Color::Cyan
|
|
||||||
} else if s == "bright white" {
|
|
||||||
Color::White
|
|
||||||
} else if s == "bright black" {
|
|
||||||
Color::Black
|
|
||||||
} else if s.contains("red") {
|
|
||||||
Color::LightRed
|
Color::LightRed
|
||||||
} else if s.contains("green") {
|
} else if s == "bright green" {
|
||||||
Color::LightGreen
|
Color::LightGreen
|
||||||
} else if s.contains("yellow") {
|
} else if s == "bright yellow" {
|
||||||
Color::LightYellow
|
Color::LightYellow
|
||||||
} else if s.contains("blue") {
|
} else if s == "bright blue" {
|
||||||
Color::LightBlue
|
Color::LightBlue
|
||||||
} else if s.contains("magenta") {
|
} else if s == "bright magenta" {
|
||||||
Color::LightMagenta
|
Color::LightMagenta
|
||||||
} else if s.contains("cyan") {
|
} else if s == "bright cyan" {
|
||||||
Color::LightCyan
|
Color::LightCyan
|
||||||
} else if s.contains("white") {
|
} else if s == "bright white" {
|
||||||
Color::Indexed(7)
|
Color::Indexed(7)
|
||||||
} else if s.contains("black") {
|
} else if s == "bright black" {
|
||||||
Color::Indexed(0)
|
Color::Indexed(0)
|
||||||
|
} else if s.contains("red") {
|
||||||
|
Color::Red
|
||||||
|
} else if s.contains("green") {
|
||||||
|
Color::Green
|
||||||
|
} else if s.contains("yellow") {
|
||||||
|
Color::Yellow
|
||||||
|
} else if s.contains("blue") {
|
||||||
|
Color::Blue
|
||||||
|
} else if s.contains("magenta") {
|
||||||
|
Color::Magenta
|
||||||
|
} else if s.contains("cyan") {
|
||||||
|
Color::Cyan
|
||||||
|
} else if s.contains("white") {
|
||||||
|
Color::White
|
||||||
|
} else if s.contains("black") {
|
||||||
|
Color::Black
|
||||||
} else {
|
} else {
|
||||||
default
|
default
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue