mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 15:59:51 +02:00
Add some test coverage for getBranchesAsObjArray
This commit is contained in:
@@ -7,15 +7,19 @@ import cryptoRandomString from 'crypto-random-string';
|
|||||||
jest.mock('crypto-random-string');
|
jest.mock('crypto-random-string');
|
||||||
|
|
||||||
describe('when parsing a gitGraph', function() {
|
describe('when parsing a gitGraph', function() {
|
||||||
let i = 0;
|
let randomNumber;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
parser.yy = gitGraphAst;
|
parser.yy = gitGraphAst;
|
||||||
parser.yy.clear();
|
parser.yy.clear();
|
||||||
|
randomNumber = 0;
|
||||||
cryptoRandomString.mockImplementation(() => {
|
cryptoRandomString.mockImplementation(() => {
|
||||||
i = i + 1;
|
randomNumber = randomNumber + 1;
|
||||||
return String(i);
|
return String(randomNumber);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
cryptoRandomString.mockReset();
|
||||||
|
});
|
||||||
it('should handle a gitGraph defintion', function() {
|
it('should handle a gitGraph defintion', function() {
|
||||||
const str = 'gitGraph:\n' + 'commit\n';
|
const str = 'gitGraph:\n' + 'commit\n';
|
||||||
|
|
||||||
@@ -234,7 +238,7 @@ describe('when parsing a gitGraph', function() {
|
|||||||
parser.yy.prettyPrint();
|
parser.yy.prettyPrint();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('it should generate a secure random ID for commits', () => {
|
it('it should generate a secure random ID for commits', function() {
|
||||||
const str = 'gitGraph:\n' + 'commit\n' + 'commit\n';
|
const str = 'gitGraph:\n' + 'commit\n' + 'commit\n';
|
||||||
const EXPECTED_LENGTH = 7;
|
const EXPECTED_LENGTH = 7;
|
||||||
const EXPECTED_CHARACTERS = '0123456789abcdef';
|
const EXPECTED_CHARACTERS = '0123456789abcdef';
|
||||||
@@ -261,4 +265,23 @@ describe('when parsing a gitGraph', function() {
|
|||||||
expect(commits[key].id).toEqual(key);
|
expect(commits[key].id).toEqual(key);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('it should generate an array of known branches', function() {
|
||||||
|
const str =
|
||||||
|
'gitGraph:\n' +
|
||||||
|
'commit\n' +
|
||||||
|
'branch b1\n' +
|
||||||
|
'checkout b1\n' +
|
||||||
|
'commit\n' +
|
||||||
|
'commit\n' +
|
||||||
|
'branch b2\n';
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
const branches = gitGraphAst.getBranchesAsObjArray();
|
||||||
|
|
||||||
|
expect(branches).toHaveLength(3);
|
||||||
|
expect(branches[0]).toHaveProperty('name', 'master');
|
||||||
|
expect(branches[1]).toHaveProperty('name', 'b1');
|
||||||
|
expect(branches[2]).toHaveProperty('name', 'b2');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user