Skip to content

Commit e0dd854

Browse files
committed
add tests for modelElementBase
1 parent bb5bb2e commit e0dd854

File tree

4 files changed

+94
-3
lines changed

4 files changed

+94
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Base clases and interfaces for:
1515
- Linting
1616
- Model Element Sequencer
1717

18+
[Changelog](./doc/Changelog.md)
19+
1820
## License
1921

2022
Published as **Apache-2.0** License.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metadev/essential-core",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"bugs": {
55
"url": "https://github.com/metadevpro/essential-core/issues"
66
},

src/modelElementBase.spec.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { expect } from 'chai';
2+
import { ModelElementBase } from './modelElementBase';
3+
import { VisitMode } from './modelElement';
4+
5+
let sut!: ModelElementBase;
6+
describe('ModelElementBase', () => {
7+
beforeEach(() => {
8+
sut = new ModelElementBase();
9+
});
10+
11+
it('getId() is not null', () => {
12+
expect(sut.getId()).not.eqls(null);
13+
});
14+
it('getId() is string', () => {
15+
expect(sut.getId()).not.eqls(null);
16+
expect(typeof sut.getId()).eqls('string');
17+
});
18+
it('getTypeName() is ModelElementDef', () => {
19+
expect(sut.getTypeName()).eqls('ModelElementBase');
20+
});
21+
22+
it('identity check', () => {
23+
expect(sut.identity()).eqls(sut.identity());
24+
const sut2 = new ModelElementBase();
25+
expect(sut2.identity()).not.eqls(sut.identity());
26+
});
27+
it('sameConcept() compared with null', () => {
28+
expect(sut.sameConcept(null)).eqls(false);
29+
});
30+
it('sameConcept() compared with undefined', () => {
31+
expect(sut.sameConcept(undefined)).eqls(false);
32+
});
33+
it('sameConcept() compared with self', () => {
34+
expect(sut.sameConcept(sut)).eqls(true);
35+
});
36+
it('sameConcept() compared with other', () => {
37+
const sut2 = new ModelElementBase();
38+
expect(sut.sameConcept(sut2)).eqls(false);
39+
});
40+
it('equals() compared with self', () => {
41+
expect(sut.equals(sut)).eqls(true);
42+
});
43+
it('equals() compared with other', () => {
44+
const sut2 = new ModelElementBase();
45+
expect(sut.sameConcept(sut2)).eqls(false);
46+
});
47+
it('hashCodeElement() compared with other', () => {
48+
const sut2 = new ModelElementBase();
49+
const hash1 = sut.hashCodeElement();
50+
const hash2 = sut2.hashCodeElement();
51+
expect(hash1).not.eqls(hash2);
52+
});
53+
it('hashCodeElement() compared with self', () => {
54+
const hash1 = sut.hashCodeElement();
55+
const hash2 = sut.hashCodeElement();
56+
expect(hash1).eqls(hash2);
57+
});
58+
it('visit() preOrder', () => {
59+
let acc = 0;
60+
sut.visit(VisitMode.PreOrder, () => {
61+
acc++;
62+
});
63+
expect(acc).eqls(1);
64+
});
65+
it('visit() postOrder', () => {
66+
let acc = 0;
67+
sut.visit(VisitMode.PostOrder, () => {
68+
acc++;
69+
});
70+
expect(acc).eqls(1);
71+
});
72+
it('toJson()', () => {
73+
expect(sut.toJson()).eqls('{}');
74+
});
75+
it('toEssential()', () => {
76+
const id = sut._meta.id;
77+
expect(sut.toEssential()).eqls(`ModelElementBase ${id} {\n}\n`);
78+
});
79+
it('visitChildren()', () => {
80+
let acc = 0;
81+
sut.visitChildren(VisitMode.PreOrder, () => {
82+
acc++;
83+
});
84+
expect(acc).eqls(0);
85+
});
86+
it('validate()', () => {
87+
expect(sut.validate()).eqls([]);
88+
});
89+
});

0 commit comments

Comments
 (0)