diff --git a/webapp/src/components/calculations/calculations.test.tsx b/webapp/src/components/calculations/calculations.test.tsx index b514fdf9c..ddc14fc14 100644 --- a/webapp/src/components/calculations/calculations.test.tsx +++ b/webapp/src/components/calculations/calculations.test.tsx @@ -79,6 +79,20 @@ describe('components/calculations/calculation logic', () => { card5.fields.properties.property_person = '' card5.fields.properties.property_checkbox = '' + // clone of card 3 but created / updated 1 second later + const card6 = TestBlockFactory.createCard(board) + card6.createAt = 1625639401000 + card6.createdBy = 'user_id_2' + card6.updateAt = 1625639401000 + card6.modifiedBy = 'user_id_2' + + // clone of card 3 but created / updated 1 minute later + const card7 = TestBlockFactory.createCard(board) + card7.createAt = 1625639460000 + card7.createdBy = 'user_id_2' + card7.updateAt = 1625639460000 + card7.modifiedBy = 'user_id_2' + const cards = [card1, card2, card3, card4] const properties: Record = { @@ -188,6 +202,26 @@ describe('components/calculations/calculation logic', () => { }) }) + test('countUniqueValue for cards created 1 second apart', () => { + const result = Calculations.countUniqueValue([card3, card6], properties.createdTime) + expect(result).toBe('1') + }) + + test('countUniqueValue for cards updated 1 second apart', () => { + const result = Calculations.countUniqueValue([card3, card6], properties.updatedTime) + expect(result).toBe('1') + }) + + test('countUniqueValue for cards created 1 minute apart', () => { + const result = Calculations.countUniqueValue([card3, card7], properties.createdTime) + expect(result).toBe('2') + }) + + test('countUniqueValue for cards updated 1 minute apart', () => { + const result = Calculations.countUniqueValue([card3, card7], properties.updatedTime) + expect(result).toBe('2') + }) + test('sum', () => { const result = Calculations.sum(cards, properties.number) expect(result).toBe('170') diff --git a/webapp/src/components/calculations/calculations.ts b/webapp/src/components/calculations/calculations.ts index ebae874e1..5153cb900 100644 --- a/webapp/src/components/calculations/calculations.ts +++ b/webapp/src/components/calculations/calculations.ts @@ -18,13 +18,13 @@ function getCardProperty(card: Card, property: IPropertyTemplate): string | stri return card.createdBy } case ('createdTime'): { - return card.createAt + return fixTimestampToMinutesAccuracy(card.createAt) } case ('updatedBy'): { return card.modifiedBy } case ('updatedTime'): { - return card.updateAt + return fixTimestampToMinutesAccuracy(card.updateAt) } default: { return card.fields.properties[property.id] @@ -32,6 +32,12 @@ function getCardProperty(card: Card, property: IPropertyTemplate): string | stri } } +function fixTimestampToMinutesAccuracy(timestamp: number) { + // For timestamps that are formatted as hour/minute strings on the UI, we throw away the (milli)seconds + // so that things like counting unique values work intuitively + return timestamp - (timestamp % 60000) +} + function cardsWithValue(cards: readonly Card[], property: IPropertyTemplate): Card[] { return cards. filter((card) => Boolean(getCardProperty(card, property)))