Skip to content

Commit

Permalink
[test] unit tests for followingSiblings
Browse files Browse the repository at this point in the history
  • Loading branch information
marmoure committed Jan 16, 2025
1 parent 4f2b72f commit e426141
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/lwdita-ast/test/audio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
]);
});
});
19 changes: 19 additions & 0 deletions packages/lwdita-ast/test/body.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});
});
12 changes: 12 additions & 0 deletions packages/lwdita-ast/test/dl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
]);
});
});
20 changes: 20 additions & 0 deletions packages/lwdita-ast/test/p.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
]);
});
});
33 changes: 33 additions & 0 deletions packages/lwdita-ast/test/topic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
]);
});
});
14 changes: 14 additions & 0 deletions packages/lwdita-ast/test/ul.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import { doNodeTest } from "./tests";
import { UlNode, isUlNode } from "../src/nodes/ul";
import { expect } from "chai";
import { LiNode } from "../src";

doNodeTest(
UlNode,
Expand Down Expand Up @@ -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 }
]);
});
});

0 comments on commit e426141

Please sign in to comment.