Skip to content

Commit 92410da

Browse files
committed
refactor: Add sampleTaskLinesForValidStatuses()
1 parent 59d99f9 commit 92410da

3 files changed

+42
-3
lines changed

src/Statuses/StatusSettingsReport.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { StatusSettings } from '../Config/StatusSettings';
22
import { MarkdownTable } from '../lib/MarkdownTable';
33
import { i18n } from '../i18n/i18n';
4-
import type { StatusConfiguration } from './StatusConfiguration';
5-
import { StatusType } from './StatusConfiguration';
4+
import { type StatusConfiguration, StatusType } from './StatusConfiguration';
65
import { Status } from './Status';
6+
import { StatusRegistry } from './StatusRegistry';
77

88
function getFirstIndex(statusConfigurations: StatusConfiguration[], wantedSymbol: string) {
99
return statusConfigurations.findIndex((s) => s.symbol === wantedSymbol);
@@ -114,3 +114,25 @@ export function tabulateStatusSettings(statusSettings: StatusSettings) {
114114
});
115115
return table.markdown;
116116
}
117+
118+
/**
119+
* Generates a list of Markdown lines, containing sample tasks based on the given status settings.
120+
*
121+
* @param {StatusSettings} statusSettings - The settings object containing custom and core statuses.
122+
*
123+
* @returns {string[]} An array of markdown strings representing sample tasks.
124+
* Each task includes a symbol, an introductory text, and the name of the status.
125+
* Only the actually registered symbols are used; duplicate and empty symbols are ignored.
126+
*/
127+
export function sampleTaskLinesForValidStatuses(statusSettings: StatusSettings) {
128+
const statusRegistry = new StatusRegistry();
129+
StatusSettings.applyToStatusRegistry(statusSettings, statusRegistry);
130+
const registeredStatuses: StatusConfiguration[] = statusRegistry.registeredStatuses;
131+
132+
return registeredStatuses.map((status, index) => {
133+
const intro = `Sample task ${index + 1}`;
134+
const symbol = `status symbol=${getPrintableSymbol(status.symbol)}`;
135+
const name = `status name='${status.name}'`;
136+
return `- [${status.symbol}] ${intro}: ${symbol} ${name}`;
137+
});
138+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- [ ] Sample task 1: status symbol=`space` status name='Todo'
2+
- [x] Sample task 2: status symbol=`x` status name='Done'
3+
- [/] Sample task 3: status symbol=`/` status name='A slash'
4+
- [p] Sample task 4: status symbol=`p` status name='A p'

tests/Statuses/StatusSettingsReport.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { StatusSettings } from '../../src/Config/StatusSettings';
2-
import { tabulateStatusSettings } from '../../src/Statuses/StatusSettingsReport';
2+
import { sampleTaskLinesForValidStatuses, tabulateStatusSettings } from '../../src/Statuses/StatusSettingsReport';
33
import type { StatusCollection } from '../../src/Statuses/StatusCollection';
44
import { verifyWithFileExtension } from '../TestingTools/ApprovalTestHelpers';
55
import { coreStatusesData, createStatuses } from '../TestingTools/StatusesTestHelpers';
@@ -36,4 +36,17 @@ describe('StatusSettingsReport', () => {
3636
const markdown = tabulateStatusSettings(statusSettings);
3737
verifyWithFileExtension(markdown, '.md');
3838
});
39+
40+
it('should create set of sample task lines, excluding duplicate and empty symbols', () => {
41+
const customStatusesData: StatusCollection = [
42+
['/', 'A slash', 'x', 'IN_PROGRESS'],
43+
['/', 'In Progress DUPLICATE - SHOULD NOT BE IN SAMPLE TASK LINES', 'x', 'IN_PROGRESS'],
44+
['', 'EMPTY STATUS SYMBOL - SHOULD NOT BE IN SAMPLE TASK LINES', '', 'TODO'],
45+
['p', 'A p', 'q', 'TODO'],
46+
];
47+
const { statusSettings } = createStatuses(coreStatusesData, customStatusesData);
48+
49+
const taskLines = sampleTaskLinesForValidStatuses(statusSettings);
50+
verifyWithFileExtension(taskLines.join('\n'), '.md');
51+
});
3952
});

0 commit comments

Comments
 (0)