Skip to content

Commit

Permalink
fix: In Mermaid diagrams, don't print out an edge to unknown statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
claremacrae committed Oct 20, 2023
1 parent ab3be3a commit 90b39fe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/StatusRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,16 @@ export class StatusRegistry {
const edges: string[] = [];
uniqueStatuses.forEach((status, index) => {
nodes.push(`${index + 1}[${status.name}]`);

// Check the next status:
const nextStatus = this.getNextStatus(status);
// TODO What if (nextStatus.type === StatusType.EMPTY)
const nextStatusIndex = uniqueStatuses.findIndex((status) => status.symbol === nextStatus.symbol);
edges.push(`${index + 1} --> ${nextStatusIndex + 1}`);
const nextStatusIsKnown = nextStatusIndex !== -1;
const nextStatusIsNotInternal = nextStatus.type !== StatusType.EMPTY;

if (nextStatusIsKnown && nextStatusIsNotInternal) {
edges.push(`${index + 1} --> ${nextStatusIndex + 1}`);
}
});

return `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
flowchart LR
1[In Progress]
2[Cancelled]
1 --> 0
2 --> 0
```
24 changes: 24 additions & 0 deletions tests/StatusRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,30 @@ describe('StatusRegistry', () => {
`);
});

it('should not include unknown nextStatusSymbols in mermaid diagrams', () => {
// Arrange
const statusRegistry = new StatusRegistry();
statusRegistry.clearStatuses();
statusRegistry.add(new StatusConfiguration(' ', 'Todo', '/', false, StatusType.TODO));
// Leave '/' as not registered
const originalNumberOfStatuses = statusRegistry.registeredStatuses.length;

// Act
const mermaidText = statusRegistry.mermaidDiagram();

// Assert
expect(statusRegistry.registeredStatuses.length).toEqual(originalNumberOfStatuses);
expect(mermaidText).toMatchInlineSnapshot(`
"
\`\`\`mermaid
flowchart LR
1[Todo]
\`\`\`
"
`);
});

describe('toggling', () => {
it('should allow task to toggle through standard transitions', () => {
// Arrange
Expand Down

0 comments on commit 90b39fe

Please sign in to comment.