Skip to content

fix diagram generation https://github.com/serverlessworkflow/specification/issues/587 #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib/diagram/mermaidState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Specification } from '../definitions';
import { isObject } from '../utils';
import {Specification} from '../definitions';
import {isObject} from '../utils';

export class MermaidState {
constructor(
Expand Down Expand Up @@ -144,7 +144,7 @@ export class MermaidState {
if (isObject(this.state.end)) {
const end = this.state.end as Specification.End;

if (end.produceEvents!.length > 0) {
if (end.produceEvents) {
transitionLabel = 'Produced event = [' + end.produceEvents!.map((pe) => pe.eventRef).join(',') + ']';
}
}
Expand Down
33 changes: 31 additions & 2 deletions tests/lib/diagram/mermaidState.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ CheckApplication --> RejectApplication : \${ .applicants | .age < 18 }
CheckApplication --> RejectApplication : default`);
});

it('should create source code for data-based state with end condition', () => {
it('should create source code for data-based state with end = true ', () => {
const databasedswitch = new Specification.Databasedswitchstate(
JSON.parse(`{
JSON.parse(`{
"type":"switch",
"name":"CheckApplication",
"dataConditions": [
Expand All @@ -138,6 +138,35 @@ CheckApplication --> [*] : \${ .applicants | .age < 18 }
CheckApplication --> StartApplication : default`);
});


it('should create source code for operation state with end.terminate = true ', () => {
const databasedswitch = new Specification.Databasedswitchstate(
JSON.parse(`{
"name": "GreetPerson",
"type": "operation",
"actions": [
{
"name": "greetAction",
"functionRef": {
"refName": "greetFunction",
"arguments": {
"message": "$.greeting $.name"
}
}
}
],
"end": {
"terminate": true
}
}`)
);
const mermaidState = new MermaidState(databasedswitch);
expect(mermaidState.sourceCode()).toBe(`GreetPerson : GreetPerson
GreetPerson : type = Operation State
GreetPerson : Num. of actions = 1
GreetPerson --> [*]`);
});

it('should create source code for operation state', () => {
const states = new Specification.Operationstate(
JSON.parse(`{
Expand Down