Skip to content

Commit c65d6dd

Browse files
authored
test: increase coverage test in src/lib.rs (#62)
1 parent 10cdd41 commit c65d6dd

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

.github/workflows/rust.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,31 @@ env:
1313
jobs:
1414
build:
1515
runs-on: ${{matrix.os}}
16+
env:
17+
DISPLAY: ':99'
1618
strategy:
1719
fail-fast: false
1820
matrix:
1921
os: [macos-latest, ubuntu-latest, windows-latest]
22+
include:
23+
- os: ubuntu-latest
24+
headless: Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
2025

2126
steps:
2227
- uses: actions/checkout@v3
2328
- uses: Swatinem/rust-cache@v2
24-
29+
with:
30+
# To only cache runs from `master`
31+
save-if: ${{ github.ref == 'refs/heads/main' }}
2532
- if: matrix.os == 'ubuntu-latest'
2633
uses: awalsh128/cache-apt-pkgs-action@latest
2734
with:
2835
packages: libxtst-dev libevdev-dev libxdo-dev
2936
version: 1.0
3037

38+
- name: Setup headless environment
39+
run: ${{matrix.headless}}
40+
3141
- name: Add components
3242
run: rustup component add clippy rustfmt
3343

src/lib.rs

+56
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,59 @@ impl Frontend for Wish {
453453
self.predicates_widget.text(&texts.join("\n"));
454454
}
455455
}
456+
457+
#[cfg(test)]
458+
mod tests {
459+
use crate::{Config, Wish};
460+
use afrim::frontend::Frontend;
461+
use std::path::Path;
462+
use std::thread;
463+
use std::time::Duration;
464+
465+
#[test]
466+
fn test_api() {
467+
let config = Config::from_file(Path::new("data/full_sample.toml")).unwrap();
468+
let mut afrim_wish = Wish::init(config);
469+
afrim_wish.build();
470+
471+
// Test without data.
472+
afrim_wish.clear_predicates();
473+
afrim_wish.next_predicate();
474+
afrim_wish.previous_predicate();
475+
assert!(afrim_wish.get_selected_predicate().is_none());
476+
afrim_wish.display();
477+
478+
// Test the adding of predicates.
479+
afrim_wish.set_page_size(3);
480+
afrim_wish.set_input("Test started!");
481+
afrim_wish.add_predicate("test", "123", "ok");
482+
afrim_wish.add_predicate("test1", "23", "ok");
483+
afrim_wish.add_predicate("test12", "1", "ok");
484+
afrim_wish.add_predicate("test123", "", "ok");
485+
afrim_wish.add_predicate("test1234", "", "");
486+
afrim_wish.display();
487+
488+
// Test the geometry.
489+
(0..100).for_each(|i| {
490+
if i % 10 != 0 {
491+
return;
492+
};
493+
let i = i as f64;
494+
afrim_wish.update_position((i, i));
495+
thread::sleep(Duration::from_millis(100));
496+
});
497+
498+
// Test the navigation.
499+
afrim_wish.previous_predicate();
500+
assert_eq!(
501+
afrim_wish.get_selected_predicate(),
502+
Some(&("test1234".to_owned(), "".to_owned(), "".to_owned()))
503+
);
504+
afrim_wish.next_predicate();
505+
assert_eq!(
506+
afrim_wish.get_selected_predicate(),
507+
Some(&("test".to_owned(), "123".to_owned(), "ok".to_owned()))
508+
);
509+
afrim_wish.display();
510+
}
511+
}

0 commit comments

Comments
 (0)