Migrate first_chapter_is_copied_as_index_even_if_not_first_elem to BookTest

This commit is contained in:
Eric Huss 2025-04-22 08:55:24 -07:00
parent d23bdaa527
commit 3fce1151dd
3 changed files with 31 additions and 15 deletions

View file

@ -271,21 +271,6 @@ fn example_book_can_build() {
md.build().unwrap();
}
#[test]
fn first_chapter_is_copied_as_index_even_if_not_first_elem() {
let temp = DummyBook::new().build().unwrap();
let mut cfg = Config::default();
cfg.set("book.src", "index_html_test")
.expect("Couldn't set config.book.src to \"index_html_test\"");
let md = MDBook::load_with_config(temp.path(), cfg).unwrap();
md.build().unwrap();
let root = temp.path().join("book");
let chapter = fs::read_to_string(root.join("chapter_1.html")).expect("read chapter 1");
let index = fs::read_to_string(root.join("index.html")).expect("read index");
pretty_assertions::assert_eq!(chapter, index);
}
#[test]
fn theme_dir_overrides_work_correctly() {
let book_dir = dummy_book::new_copy_of_example_book().unwrap();

View file

@ -21,3 +21,23 @@ fn edit_url_template_explicit_src() {
title=\"Suggest an edit\" aria-label=\"Suggest an edit\">",
);
}
// Checks that index.html is generated correctly, even when the first few
// chapters are drafts.
#[test]
fn first_chapter_is_copied_as_index_even_if_not_first_elem() {
BookTest::from_dir("rendering/first_chapter_is_copied_as_index_even_if_not_first_elem")
// These two files should be equal.
.check_main_file(
"book/chapter_1.html",
str![[
r##"<h1 id="chapter-1"><a class="header" href="#chapter-1">Chapter 1</a></h1>"##
]],
)
.check_main_file(
"book/index.html",
str![[
r##"<h1 id="chapter-1"><a class="header" href="#chapter-1">Chapter 1</a></h1>"##
]],
);
}

View file

@ -0,0 +1,11 @@
# Summary
---
- [None of these should be treated as the "index chapter"]()
# Part 1
- [Not this either]()
- [Chapter 1](./chapter_1.md)
- [And not this]()