mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-27 15:20:30 -04:00
Book Editing: Support adding new sections to a book (#17074)
* add a new section command
This commit is contained in:
@@ -20,6 +20,8 @@ import { BookTreeViewProvider } from '../../book/bookTreeView';
|
||||
import { NavigationProviders } from '../../common/constants';
|
||||
import { BookVersion } from '../../book/bookVersionHandler';
|
||||
import * as yaml from 'js-yaml';
|
||||
import { TocEntryPathHandler } from '../../book/tocEntryPathHandler';
|
||||
import * as utils from '../../common/utils';
|
||||
|
||||
export function equalTOC(actualToc: IJupyterBookSectionV2[], expectedToc: IJupyterBookSectionV2[]): boolean {
|
||||
for (let [i, section] of actualToc.entries()) {
|
||||
@@ -552,6 +554,26 @@ describe('BookTocManagerTests', function () {
|
||||
should(JSON.stringify(listFiles).includes('test')).be.true('Empty directories within the moving element directory are not deleted');
|
||||
});
|
||||
|
||||
it('Add new section', async () => {
|
||||
bookTocManager = new BookTocManager(sourceBookModel);
|
||||
const fileBasename = `addSectionTest-${utils.generateGuid()}`;
|
||||
const sectionTitle = 'Section Test';
|
||||
const testFilePath = path.join(run.sectionA.sectionRoot, fileBasename).concat(utils.FileExtension.Markdown);
|
||||
await fs.writeFile(testFilePath, '');
|
||||
const pathDetails = new TocEntryPathHandler(testFilePath, run.sourceBook.rootBookFolderPath, sectionTitle);
|
||||
await bookTocManager.addNewTocEntry(pathDetails, sectionA, true);
|
||||
let toc: JupyterBookSection[] = yaml.safeLoad((await fs.promises.readFile(run.sourceBook.tocPath)).toString());
|
||||
const sectionAIndex = toc.findIndex(entry => entry.title === sectionA.title);
|
||||
let newSectionIndex = -1;
|
||||
let newSection = undefined;
|
||||
if (sectionAIndex) {
|
||||
newSectionIndex = toc[sectionAIndex].sections?.findIndex(entry => entry.title === sectionTitle);
|
||||
newSection = toc[sectionAIndex].sections[newSectionIndex];
|
||||
}
|
||||
should(newSectionIndex).not.be.equal(-1, 'The new section should exist in the toc file');
|
||||
should(newSection.sections).not.undefined();
|
||||
});
|
||||
|
||||
afterEach(async function (): Promise<void> {
|
||||
sinon.restore();
|
||||
if (await exists(sourceBookFolderPath)) {
|
||||
|
||||
Reference in New Issue
Block a user