Skip to content

Commit

Permalink
#55: Ordering listed timesheet entries by start date
Browse files Browse the repository at this point in the history
  • Loading branch information
gsvarovsky committed Aug 11, 2022
1 parent 4ead28e commit 86bfcdc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
17 changes: 10 additions & 7 deletions packages/cli/lib/TimesheetSession.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { Entry, Session } from 'timeld-common';
import { DefaultFormat, ENTRY_FORMAT_OPTIONS, getSubjectFormat } from './DisplayFormat.mjs';
import { PromiseProc } from './PromiseProc.mjs';
import { Writable } from 'stream';
import { from, mergeMap, toArray } from 'rxjs';
import { consume } from 'rx-flowable/consume';

export default class TimesheetSession extends Repl {
/**
Expand Down Expand Up @@ -157,12 +159,13 @@ export default class TimesheetSession extends Repl {
*/
reportEntriesProc({ selector, format }) {
// TODO: selectors
return new ResultsProc(
this.meld.read({
'@describe': '?entry',
'@where': { '@id': '?entry', '@type': 'Entry' }
}).consume,
getSubjectFormat(format, this.getSession));
return new ResultsProc(consume(this.meld.read({
'@describe': '?entry',
'@where': { '@id': '?entry', '@type': 'Entry' }
}).pipe(toArray(), mergeMap(all => {
all.sort((s1, s2) => s1.start?.['@value']?.localeCompare(s2.start?.['@value']) ?? -1);
return from(all);
}))), getSubjectFormat(format, this.getSession));
}

/**
Expand All @@ -172,7 +175,7 @@ export default class TimesheetSession extends Repl {
entry.sessionId === this.session.id ? 'This session' : this.meld.get(entry.sessionId);

/**
* @param {string | number} selector Entry to modify, using a number or a activity name
* @param {string | number} selector Entry to modify, using a number or an activity name
* @param {number} [duration] in minutes
* @param {string} [activity]
* @param {Date} [start]
Expand Down
15 changes: 14 additions & 1 deletion packages/cli/test/TimesheetSession.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,27 @@ describe('CLI Session', () => {
.resolves.toMatchObject(expectEntry('testing', 120));
});

test('list one entry', async () => {
test('list an entry', async () => {
const outLines = jest.fn(), errLines = jest.fn();
await session.execute('add testing 1h', outLines, errLines);
await session.execute('list', outLines, errLines);
expect(outLines).toHaveBeenLastCalledWith(expect.stringMatching(
/Entry #1: testing/));
});

test('listed entries sorted by time', async () => {
const outLines = jest.fn(), errLines = jest.fn();
await session.execute('add testing3 1h', jest.fn(), errLines);
await session.execute('add testing2 1h --start one hour ago', jest.fn(), errLines);
await session.execute('add testing1 1h --start yesterday 12am', jest.fn(), errLines);
await session.execute('list', outLines, errLines);
expect(outLines.mock.calls).toEqual([
[expect.stringMatching(/Entry #3: testing1/)],
[expect.stringMatching(/Entry #2: testing2/)],
[expect.stringMatching(/Entry #1: testing3/)]
]);
});

describe('import', () => {
test('inline entry', async () => {
const outLines = jest.fn(), errLines = jest.fn();
Expand Down

0 comments on commit 86bfcdc

Please sign in to comment.