test: add untracked file

[?]
May 29, 2025, 10:39 AM
YYKXNBFL44LLOBABLXBKOF7IFUIGIEL2SYIPLGDH6UOEY5EZZZSQC

Dependencies

  • [2] VCNKFNUF app init test
  • [3] I56UGW7U make record test, fix log update
  • [4] KMB6FND3 test view update fn rather than direct fn calls

Change contents

  • edit in inflorescence/src/test.rs at line 1
    [2.2521][3.1258:1279]()
    use std::sync::Arc;
  • edit in inflorescence/src/test.rs at line 15
    [3.1682]
    [3.1682]
    use std::collections::BTreeSet;
    use std::sync::Arc;
  • edit in inflorescence/src/test.rs at line 69
    [3.2071][3.2071:2099]()
    initial_change_len,
  • edit in inflorescence/src/test.rs at line 73
    [3.2194]
    [3.2194]
    let initial_change_len = state.repo.as_ref().unwrap().log.len();
  • edit in inflorescence/src/test.rs at line 263
    [3.4746]
    [3.4746]
    /// Test add untracked file
    #[test(tokio::test)]
    async fn test_add_untracked_file() {
    let TestState {
    mut state,
    mut tasks,
    mut fs_watch_task,
    id: _,
    repo,
    } = setup_state().await;
    let repo_path = repo.dir.path();
    assert!(state.repo.as_ref().unwrap().untracked_files.is_empty());
    assert!(state.repo.as_ref().unwrap().changed_files.is_empty());
    // Add an untracked file
    let file_to_record = "new_file.rs";
    fs::write(repo_path.join(file_to_record), "some contents")
    .await
    .unwrap();
    // Wait for the FS watch to pick it up
    let msg = await_next_msg(&mut fs_watch_task).await;
    assert_matches!(
    &msg,
    Msg::View(app::Msg::ToRepo(
    repo::MsgIn::RefreshChangedAndUntrackedFiles
    ))
    );
    // Update the state with it to send it to repo
    let _task = update(&mut state, msg);
    // Wait for response from repo
    let msg = await_next_msg(&mut tasks).await;
    assert_matches!(&msg, Msg::FromRepo(repo::MsgOut::Refreshed(_)));
    let _task = update(&mut state, msg);
  • edit in inflorescence/src/test.rs at line 299
    [3.4747]
    [3.4747]
    assert_eq!(state.repo.as_ref().unwrap().untracked_files.len(), 1);
    assert!(state
    .repo
    .as_ref()
    .unwrap()
    .untracked_files
    .contains(file_to_record));
    assert!(state.repo.as_ref().unwrap().changed_files.is_empty());
    // Select it
    update(
    &mut state,
    Msg::View(app::Msg::Cursor(cursor::Msg::Select(
    cursor::Select::UntrackedFile {
    ix: 0,
    path: file_to_record.to_string(),
    },
    ))),
    );
    // Selection triggers `LoadedSrcFile`
    let _msg = task::await_next_msg(&mut tasks).await;
    // Add it to tracked files
    let _task = update(&mut state, Msg::AddUntrackedFile);
    // Wait for it to be added
    let msg = task::await_next_msg(&mut tasks).await;
    assert_matches!(
    &msg,
    Msg::FromRepo(repo::MsgOut::AddedUntrackedFile { path }) if path == file_to_record
    );
    assert!(state.repo.as_ref().unwrap().untracked_files.is_empty());
    assert_eq!(state.repo.as_ref().unwrap().changed_files.len(), 1);
    assert!(state
    .repo
    .as_ref()
    .unwrap()
    .changed_files
    .contains_key(file_to_record));
    assert_eq!(
    state
    .repo
    .as_ref()
    .unwrap()
    .changed_files
    .get(file_to_record)
    .unwrap(),
    &BTreeSet::from_iter([repo::ChangedFileDiff::Add])
    );
    }
  • edit in inflorescence/src/test.rs at line 429
    [3.7001][3.7001:7033]()
    let initial_change_len = 2;
  • replacement in inflorescence/src/test.rs at line 430
    [3.7082][3.7082:7129]()
    assert_eq!(log.len(), initial_change_len);
    [3.7082]
    [3.7129]
    assert_eq!(log.len(), 2);
  • edit in inflorescence/src/test.rs at line 438
    [3.7294][3.7294:7322]()
    initial_change_len,
  • edit in inflorescence/src/test.rs at line 451
    [3.7573][3.7573:7604]()
    initial_change_len: usize,