Error in `visIgraphLayout(., layout = "layout_nicely", type = "full")`: This function need 'igraph' package to compute layout. Please 
         install it before.

# Test file for create_citation_network function
# Helper function to create mock citation analysis results
citation1 = c("Smith et al. (2020)", "Jones et al. (2019)", "Smith et al. (2020)", "Brown et al. (2021)"),
citation2 = c("Jones et al. (2019)", "Brown et al. (2021)", "Brown et al. (2021)", "Davis et al. (2022)"),
citation_text_clean = c("Smith et al. (2020)", "Jones et al. (2019)",
section = c("Introduction", "Methods", "Results", "Discussion", "Results"),
# Test 1: Basic functionality with valid input
test_that("create_citation_network creates valid network with default parameters", {
# Test 2: Network statistics are correctly calculated
test_that("network statistics are correctly computed", {
# Test 3: max_distance parameter filters correctly
test_that("max_distance parameter filters citation pairs", {
# With max_distance = 500, should exclude the pair with distance 800
network_500 <- create_citation_network(mock_data, max_distance = 500)
# With max_distance = 200, should only include pair with distance 150
network_200 <- create_citation_network(mock_data, max_distance = 200)
expect_true(stats_500$n_edges < 4)  # Less than total possible edges
# Test 4: min_connections parameter filters nodes
test_that("min_connections parameter filters nodes correctly", {
network_min1 <- create_citation_network(mock_data, min_connections = 1)
network_min2 <- create_citation_network(mock_data, min_connections = 2)
# Higher min_connections should result in fewer nodes
test_that("show_labels parameter controls label display", {
network_with_labels <- create_citation_network(mock_data, show_labels = TRUE)
network_no_labels <- create_citation_network(mock_data, show_labels = FALSE)
# Test 6: Handles NULL or empty network_data
test_that("function handles NULL or empty network_data gracefully", {
network_data = data.frame(citation1 = character(0),
# Test 7: Warning when no pairs within max_distance
test_that("function warns when no pairs within max_distance", {
expect_warning(result <- create_citation_network(mock_data, max_distance = 50),
"No citation pairs found within the specified maximum distance")
# Test 8: Warning when no valid connections after filtering
test_that("function warns when no valid connections after filtering", {
# Set very high min_connections that no node can satisfy
expect_warning(result <- create_citation_network(mock_data, min_connections = 100),
# Test 9: Multi-section citations are correctly identified
test_that("multi-section citations are correctly identified", {
# Smith et al. (2020) appears in both Introduction and Results
# Test 10: Section colors are properly applied
test_that("section colors are properly applied", {
# Test 11: Edge properties are correctly set
test_that("edge properties reflect distance correctly", {
network <- create_citation_network(mock_data, max_distance = 1000)
# Test 12: Section distribution is calculated
test_that("section distribution is calculated in statistics", {
test_that("unknown sections are handled correctly", {
# Test 14: Network attributes contain expected components
test_that("returned network has all expected attributes", {