mod common;
use common::{OutputAssertions, TestRepo};
use std::fs;
#[test]
fn test_submit_with_single_template() {
let repo = TestRepo::new();
let github_dir = repo.path().join(".github");
fs::create_dir(&github_dir).unwrap();
fs::write(
github_dir.join("PULL_REQUEST_TEMPLATE.md"),
"## Description\n\nPlease describe your changes.\n\n## Testing\n\nHow was this tested?",
)
.unwrap();
let output = repo.run_stax(&["create", "test-branch", "-m", "test commit"]);
output.assert_success();
assert!(repo.current_branch_contains("test-branch"));
}
#[test]
fn test_template_discovery_multiple() {
let repo = TestRepo::new();
let template_dir = repo.path().join(".github/PULL_REQUEST_TEMPLATE");
fs::create_dir_all(&template_dir).unwrap();
fs::write(
template_dir.join("feature.md"),
"# Feature template\n\n## Changes\n\n",
)
.unwrap();
fs::write(
template_dir.join("bugfix.md"),
"# Bugfix template\n\n## Bug Description\n\n",
)
.unwrap();
fs::write(
template_dir.join("docs.md"),
"# Docs template\n\n## Documentation Changes\n\n",
)
.unwrap();
let templates = stax::github::pr_template::discover_pr_templates(&repo.path()).unwrap();
assert_eq!(templates.len(), 3);
let names: Vec<_> = templates.iter().map(|t| t.name.as_str()).collect();
assert!(names.contains(&"feature"));
assert!(names.contains(&"bugfix"));
assert!(names.contains(&"docs"));
}
#[test]
fn test_no_template_in_repo() {
let repo = TestRepo::new();
let output = repo.run_stax(&["create", "test-branch", "-m", "test commit"]);
output.assert_success();
assert!(repo.current_branch_contains("test-branch"));
}
#[test]
fn test_no_template_flag_skips_template() {
let repo = TestRepo::new();
let github_dir = repo.path().join(".github");
fs::create_dir(&github_dir).unwrap();
fs::write(
github_dir.join("PULL_REQUEST_TEMPLATE.md"),
"# Template content",
)
.unwrap();
let templates = stax::github::pr_template::discover_pr_templates(&repo.path()).unwrap();
assert_eq!(templates.len(), 1);
}
#[test]
fn test_templates_in_subdirectory() {
let repo = TestRepo::new();
let template_dir = repo.path().join(".github/PULL_REQUEST_TEMPLATE");
fs::create_dir_all(&template_dir).unwrap();
fs::write(template_dir.join("default.md"), "# Default template\n").unwrap();
let output = repo.run_stax(&["create", "test-branch", "-m", "test commit"]);
output.assert_success();
assert!(template_dir.join("default.md").exists());
}
#[test]
fn test_template_in_docs_directory() {
let repo = TestRepo::new();
let docs_dir = repo.path().join("docs");
fs::create_dir_all(&docs_dir).unwrap();
fs::write(
docs_dir.join("PULL_REQUEST_TEMPLATE.md"),
"# Docs location template\n",
)
.unwrap();
let output = repo.run_stax(&["create", "test-branch", "-m", "test commit"]);
output.assert_success();
assert!(docs_dir.join("PULL_REQUEST_TEMPLATE.md").exists());
}