From e4261413202933472cb6f571fa0226f5d601c21e Mon Sep 17 00:00:00 2001 From: marmoure Date: Wed, 15 Jan 2025 16:26:41 +0100 Subject: [PATCH] [test] unit tests for `followingSiblings` --- packages/lwdita-ast/test/audio.spec.ts | 46 ++++++++++++++++++++++++++ packages/lwdita-ast/test/body.spec.ts | 19 +++++++++++ packages/lwdita-ast/test/dl.spec.ts | 12 +++++++ packages/lwdita-ast/test/p.spec.ts | 20 +++++++++++ packages/lwdita-ast/test/topic.spec.ts | 33 ++++++++++++++++++ packages/lwdita-ast/test/ul.spec.ts | 14 ++++++++ 6 files changed, 144 insertions(+) diff --git a/packages/lwdita-ast/test/audio.spec.ts b/packages/lwdita-ast/test/audio.spec.ts index bd0a252c..807d20a5 100644 --- a/packages/lwdita-ast/test/audio.spec.ts +++ b/packages/lwdita-ast/test/audio.spec.ts @@ -70,4 +70,50 @@ describe('Class AudioNode', () => { expect(audio.muted).to.equal("false"); expect(audio.tabindex).to.equal("1"); }); +}); + +describe('followingSiblings', () => { + it('get expected children for audio after desc', () => { + const audio = new AudioNode({}); + + const childTypes = audio.followingSiblings("desc"); + + expect(childTypes).to.deep.equal([ + { name: 'fallback', single: true, required: false, isGroup: false }, + { name: 'media-source', single: false, required: false, isGroup: false }, + { name: 'media-track', single: false, required: false, isGroup: false } + ]); + }); + + it('get expected children for audio after fallback', () => { + const audio = new AudioNode({}); + + const childTypes = audio.followingSiblings("fallback"); + + expect(childTypes).to.deep.equal([ + { name: 'media-source', single: false, required: false, isGroup: false }, + { name: 'media-track', single: false, required: false, isGroup: false } + ]); + }); + + it('get expected children for audio after media-source', () => { + const audio = new AudioNode({}); + + const childTypes = audio.followingSiblings("media-source"); + + expect(childTypes).to.deep.equal([ + { name: 'media-source', single: false, required: false, isGroup: false }, + { name: 'media-track', single: false, required: false, isGroup: false } + ]); + }); + + it('get expected children for audio after media-track', () => { + const audio = new AudioNode({}); + + const childTypes = audio.followingSiblings("media-track"); + + expect(childTypes).to.deep.equal([ + { name: 'media-track', single: false, required: false, isGroup: false } + ]); + }); }); \ No newline at end of file diff --git a/packages/lwdita-ast/test/body.spec.ts b/packages/lwdita-ast/test/body.spec.ts index bfe4d2b2..3dd49610 100644 --- a/packages/lwdita-ast/test/body.spec.ts +++ b/packages/lwdita-ast/test/body.spec.ts @@ -43,4 +43,23 @@ describe('Class BodyNode', () => { expect(body.outputclass).to.equal("outputclass"); expect(body.class).to.equal("class"); }); +}); + +describe('followingSiblings', () => { + it('get expected children for body after title', () => { + const body = new BodyNode({}); + const childTypes = body.followingSiblings("section"); + + expect(childTypes).to.deep.equal([ + { name: 'section', single: false, required: false, isGroup: false }, + { name: 'div', single: true, required: false, isGroup: false } + ]); + }); + + it('get expected children for body after body', () => { + const body = new BodyNode({}); + const childTypes = body.followingSiblings("div"); + + expect(childTypes).to.deep.equal([]); + }); }); \ No newline at end of file diff --git a/packages/lwdita-ast/test/dl.spec.ts b/packages/lwdita-ast/test/dl.spec.ts index 2734bb7a..20994c4f 100644 --- a/packages/lwdita-ast/test/dl.spec.ts +++ b/packages/lwdita-ast/test/dl.spec.ts @@ -49,4 +49,16 @@ describe('Class DlNode', () => { expect(dl.outputclass).to.equal("outputclass"); expect(dl.class).to.equal("class"); }); +}); + +describe('followingSiblings', () => { + it('get expected children for dl after dlentry', () => { + const dl = new DlNode({}); + + const childTypes = dl.followingSiblings("dlentry"); + + expect(childTypes).to.deep.equal([ + { name: 'dlentry', single: false, required: true, isGroup: false } + ]); + }); }); \ No newline at end of file diff --git a/packages/lwdita-ast/test/p.spec.ts b/packages/lwdita-ast/test/p.spec.ts index c0b981d1..29690d5f 100644 --- a/packages/lwdita-ast/test/p.spec.ts +++ b/packages/lwdita-ast/test/p.spec.ts @@ -48,3 +48,23 @@ describe('Class PNode', () => { expect(p.class).to.equal("class"); }); }); + +describe('followingSiblings', () => { + it('get expected children for p after strong', () => { + const p = new PNode({}); + const childTypes = p.followingSiblings("strong"); + + expect(childTypes).to.deep.equal([ + { name: 'inline', single: false, required: false, isGroup: true }, + ]); + }); + + it('get expected children for p after image', () => { + const p = new PNode({}); + const childTypes = p.followingSiblings("image"); + + expect(childTypes).to.deep.equal([ + { name: 'inline', single: false, required: false, isGroup: true }, + ]); + }); +}); \ No newline at end of file diff --git a/packages/lwdita-ast/test/topic.spec.ts b/packages/lwdita-ast/test/topic.spec.ts index bea6bcba..d716cf95 100644 --- a/packages/lwdita-ast/test/topic.spec.ts +++ b/packages/lwdita-ast/test/topic.spec.ts @@ -50,4 +50,37 @@ describe('Class TopicNode', () => { expect(topic["ditaarch:DITAArchVersion"]).to.equal("ditaarch:DITAArchVersion"); expect(topic.specializations).to.equal("&included-domains;"); }); +}); + + +describe('followingSiblings', () => { + it('get expected children for topic after title', () => { + const topic = new TopicNode({}); + const childTypes = topic.followingSiblings("title"); + + expect(childTypes).to.deep.equal([ + { name: 'shortdesc', single: true, required: false, isGroup: false }, + { name: 'prolog', single: true, required: false, isGroup: false }, + { name: 'body', single: true, required: false, isGroup: false } + ]); + }); + + it('get expected children for topic after body', () => { + const topic = new TopicNode({}); + const childTypes = topic.followingSiblings("body"); + + expect(childTypes).to.deep.equal([]); + }); + + it('get expected children for topic', () => { + const topic = new TopicNode({}); + const childTypes = topic.followingSiblings(); + + expect(childTypes).to.deep.equal([ + { name: 'title', single: true, required: true, isGroup: false }, + { name: 'shortdesc', single: true, required: false, isGroup: false }, + { name: 'prolog', single: true, required: false, isGroup: false }, + { name: 'body', single: true, required: false, isGroup: false } + ]); + }); }); \ No newline at end of file diff --git a/packages/lwdita-ast/test/ul.spec.ts b/packages/lwdita-ast/test/ul.spec.ts index eee53677..1191ccdb 100644 --- a/packages/lwdita-ast/test/ul.spec.ts +++ b/packages/lwdita-ast/test/ul.spec.ts @@ -18,6 +18,7 @@ along with this program. If not, see . import { doNodeTest } from "./tests"; import { UlNode, isUlNode } from "../src/nodes/ul"; import { expect } from "chai"; +import { LiNode } from "../src"; doNodeTest( UlNode, @@ -49,4 +50,17 @@ describe('Class UlNode', () => { expect(ul.outputclass).to.equal("outputclass"); expect(ul.class).to.equal("class"); }); +}); + + +describe('followingSiblings', () => { + it('get expected children for ul after li', () => { + const ul = new UlNode({}); + + const childTypes = ul.followingSiblings("li"); + + expect(childTypes).to.deep.equal([ + { name: 'li', single: false, required: true, isGroup: false } + ]); + }); }); \ No newline at end of file