-
Notifications
You must be signed in to change notification settings - Fork 106
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
feat(Bonus Pagamenti Digitali): [#175741693] Remove timestamp from transactions when it's equal to 00:00 #2734
Changes from 2 commits
d1197a5
ebd3759
b607b66
ae12afb
7741a43
9801a64
ea16453
4545da0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,56 @@ | ||||
// import * as React from "react"; | ||||
// import { render } from '@testing-library/react-native'; | ||||
import { getSubtitle } from "../BpdTransactionItem"; | ||||
import { EnhancedBpdTransaction } from "../../../components/transactionItem/BpdTransactionItem"; | ||||
import { HPan } from "../../../store/actions/paymentMethods"; | ||||
import { AwardPeriodId } from "../../../store/actions/periods"; | ||||
|
||||
describe("Test how the transaction subtitle changes with different timestamps", () => { | ||||
it("Subtitle shouldn't contain hours and minutes, when the transaction has a timestamp 00:00", () => { | ||||
|
||||
// TODO: test input data should be moved in a separate file | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO should be followed by a ref to a story (es
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll remove the TODO.. I don't know if the team agrees on having a separate module for test input data, this is just my approach |
||||
const myTransaction: EnhancedBpdTransaction = { | ||||
hashPan: '0d4194712c5d820fcbbb2e7ba199e15f73cfd43f8fe49f0aa62e7901253506df' as HPan, | ||||
idTrxAcquirer: '10126487773E', | ||||
idTrxIssuer: 'R64692', | ||||
amount: 87.79, | ||||
awardPeriodId: 2 as AwardPeriodId, | ||||
image: 29, | ||||
maxCashbackForTransactionAmount: 15, | ||||
title: "xxxxxxx", | ||||
trxDate: new Date('2100-12-17T00:00'), | ||||
keyId: "xxxxxxxxx", | ||||
cashback: 8.779, | ||||
circuitType: 'Mastercard' | ||||
}; | ||||
|
||||
expect(getSubtitle(myTransaction)).toMatch("17 Dec · € 87.79 "); | ||||
|
||||
|
||||
}); | ||||
|
||||
it("Subtitle should contain hours and minutes when the transaction has a timestamp 00:00", () => { | ||||
|
||||
// TODO: test input data should be moved in a separate file | ||||
const myTransaction: EnhancedBpdTransaction = { | ||||
hashPan: '0d4194712c5d820fcbbb2e7ba199e15f73cfd43f8fe49f0aa62e7901253506df' as HPan, | ||||
idTrxAcquirer: '10126487773E', | ||||
idTrxIssuer: 'R64692', | ||||
amount: 100000.79, | ||||
awardPeriodId: 2 as AwardPeriodId, | ||||
image: 29, | ||||
maxCashbackForTransactionAmount: 15, | ||||
title: "xxxxxxx", | ||||
trxDate: new Date('2100-12-19T12:39'), | ||||
keyId: "xxxxxxxxx", | ||||
cashback: 8.779, | ||||
circuitType: 'Mastercard' | ||||
}; | ||||
|
||||
expect(getSubtitle(myTransaction)).toMatch("19 Dec, 12:39 · € 100,000.79 "); | ||||
|
||||
|
||||
}); | ||||
|
||||
|
||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,11 +60,18 @@ const CancelBadge = () => ( | |
const Table = (props: Props) => ( | ||
<View> | ||
<View style={styles.rowId}> | ||
<H5 weight={"Regular"} color={"bluegrey"}> | ||
{I18n.t("payment.details.info.dateAndTime")} | ||
<H5 weight={"Regular"} color={"bluegrey"} testID="dateLabel"> | ||
{(props.transaction.trxDate.getHours() === 0 && props.transaction.trxDate.getMinutes() === 0) ? | ||
I18n.t("payment.details.info.onlyDate") : | ||
I18n.t("payment.details.info.dateAndTime")} | ||
</H5> | ||
<H4 weight={"SemiBold"} color={"bluegreyDark"}> | ||
{localeDateFormat( | ||
<H4 weight={"SemiBold"} color={"bluegreyDark"} testID="dateValue"> | ||
{ (props.transaction.trxDate.getHours() === 0 && props.transaction.trxDate.getMinutes() === 0) ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as improvement, could it be better to calculate a const once instead of make the same op twice? const isMidNight =
props.transaction.trxDate.getHours() +
props.transaction.trxDate.getMinutes() ===
0; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, your solution is more clear and readable. I'll change as you suggest |
||
localeDateFormat( | ||
props.transaction.trxDate, | ||
I18n.t("global.dateFormats.fullFormatShortMonthLiteralWithoutTime")) | ||
: | ||
localeDateFormat( | ||
props.transaction.trxDate, | ||
I18n.t("global.dateFormats.fullFormatShortMonthLiteralWithTime") | ||
)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// import { debug } from "console"; | ||
import * as React from "react"; | ||
import { render } from '@testing-library/react-native'; | ||
import { BpdTransactionDetailComponent } from "../BpdTransactionDetailComponent"; | ||
import { EnhancedBpdTransaction } from "../../../../../components/transactionItem/BpdTransactionItem"; | ||
import { HPan } from "../../../../../store/actions/paymentMethods"; | ||
import { AwardPeriodId } from "../../../../../store/actions/periods"; | ||
|
||
describe("Test Transaction Timestamp", () => { | ||
it("It should render label 'Date' and a value without hours and minutes when the transaction has a timestamp 00:00", () => { | ||
|
||
// TODO: test input data should be moved in a separate file | ||
const myTransaction: EnhancedBpdTransaction = { | ||
hashPan: '0d4194712c5d820fcbbb2e7ba199e15f73cfd43f8fe49f0aa62e7901253506df' as HPan, | ||
idTrxAcquirer: '10126487773E', | ||
idTrxIssuer: 'R64692', | ||
amount: 87.79, | ||
awardPeriodId: 2 as AwardPeriodId, | ||
image: 29, | ||
maxCashbackForTransactionAmount: 15, | ||
title: "xxxxxxx", | ||
trxDate: new Date('2100-12-17T00:00'), | ||
keyId: "xxxxxxxxx", | ||
cashback: 8.779, | ||
circuitType: 'Mastercard' | ||
}; | ||
|
||
// cut : Component Under Test | ||
const cut = render(<BpdTransactionDetailComponent transaction={myTransaction} />); | ||
|
||
const dateLabel = cut.getByTestId("dateLabel"); | ||
const dateValue = cut.getByTestId("dateValue"); | ||
|
||
expect(dateLabel.children[0]).toMatch(/Date/); | ||
expect(dateValue.children[0]).toMatch(/17 Dec 2100/); | ||
|
||
}); | ||
|
||
it("It should render label 'Date and time' and a vale woth hours and minutes when the transaction has a timestamp different from 00:00 ", () => { | ||
|
||
// TODO: test input data should be moved in a separate file | ||
|
||
const myTransaction: EnhancedBpdTransaction = { | ||
hashPan: '0d4194712c5d820fcbbb2e7ba199e15f73cfd43f8fe49f0aa62e7901253506df' as HPan, | ||
idTrxAcquirer: '10126487773E', | ||
idTrxIssuer: 'R64692', | ||
amount: 87.79, | ||
awardPeriodId: 2 as AwardPeriodId, | ||
image: 29, | ||
maxCashbackForTransactionAmount: 0, | ||
title: "xxxxxxx", | ||
trxDate: new Date('2100-12-17T01:00'), | ||
keyId: "xxxxxxxxx", | ||
cashback: 8.779, | ||
circuitType: 'Mastercard' | ||
}; | ||
|
||
// cut : Component Under Test | ||
const cut = render(<BpdTransactionDetailComponent transaction={myTransaction} />); | ||
const dateLabel = cut.getByTestId("dateLabel"); | ||
const dateValue = cut.getByTestId("dateValue"); | ||
|
||
expect(dateLabel.children[0]).toMatch(/Date and time/); | ||
expect(dateValue.children[0]).toMatch(/17 Dec 2100, 01:00/); | ||
|
||
}); | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could these imports be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.. I'll clean useless comments