status-desktop/ui/StatusQ/tests/TestUtils/tst_test-LocaleUtils.qml
Alex Jbanca 4a30d13bdc
feat(LinkPreviews): Integrate Link previews with the backend (#12523)
* feat(StatusQ): Adding numberToLocaleStringInCompactForm function to LocaleUtils

This function will format the number in a compact form
E.g: 1000 -> 1K; 1000000 -> 1M; 1100000 -> 1.1M

+ adding tests

fix(statusQ): Update numberToLocaleStringInCompactForm to return the locale number when greter than 999T

fix(StatusQ): extend the test_numberToLocaleStringInCompactForm with new data

* feat(LinkPreviews): Update the link preview area in StatusChatInput to use the new model

Changes:
1. Create a new component `LinkPreviewMiniCardDelegate.qml` that filters the model data to properly fill the link preview card with the needed data based on the preview type
2. Update storybook pages
3. Small updates to LinkPreviewMiniCard

* feat(LinkPreviews): Update the link previews in message history to use the new backend

Changes:
1. Create delegate items for LinkPreviewCard and gif link preview to clean the LinksMessageView component and filter the model data based on the preview type
2. Remove UserProfileCard and reuse the LinkPreviewCard to display contacts link previews
3. Update LinkPreviewCard so that it can accommodate status link previews (communities, channels, contacts). The generic properties (title, description, footer) have been dropped and replaced with specialised properties for each preview type.
4. Fix LinkPreviewCard layout to better accommodate different content variants (missing properties, long/short title, missing description, missing icon)
5. Fixing the link preview context menu and click actions

fix: Move inline components to separate files

Fixing the linux builds using Qt 5.15.2 affected by this bug:
https://bugreports.qt.io/browse/QTBUG-89180

* fix: Align LinkPreviewMiniCard implementation with LinkPreviewCard and remove state based model filtering
2023-10-25 18:20:02 +03:00

291 lines
7.7 KiB
QML

import QtQuick 2.15
import QtTest 1.15
import StatusQ.Core 0.1
TestCase {
id: testCase
name: "LocaleUtils"
function test_currencyAmountToLocaleString_data() {
function currencyAmount(amount, displayDecimals, stripTrailingZeroes, symbol) {
return { amount, displayDecimals, stripTrailingZeroes, symbol }
}
return [
{
amount: null,
amountString: "N/A"
},
{
amount: "",
amountString: "N/A"
},
{
amount: "string",
amountString: "N/A"
},
{
amount: {},
amountString: "N/A"
},
{
amount: { amount: 4 },
amountString: "4"
},
{
amount: currencyAmount(1, 4, false, "ETH"),
amountString: "1.0000 ETH"
},
{
amount: currencyAmount(1.00001, 4, false, "ETH"),
amountString: "1.0000 ETH"
},
{
amount: currencyAmount(1.00009, 4, false, "ETH"),
amountString: "1.0001 ETH"
},
{
amount: currencyAmount(1.00005, 4, false, "ETH"),
amountString: "1.0001 ETH"
},
{
amount: currencyAmount(1, 4, true, "ETH"),
amountString: "1 ETH"
},
{
amount: currencyAmount(1.00001, 4, true, "ETH"),
amountString: "1 ETH"
},
{
amount: currencyAmount(1.00009, 4, true, "ETH"),
amountString: "1.0001 ETH"
},
{
amount: currencyAmount(1.00005, 4, true, "ETH"),
amountString: "1.0001 ETH"
},
{
amount: currencyAmount(1, 0, false, "ETH"),
amountString: "1 ETH"
},
{
amount: currencyAmount(1.4, 0, false, "ETH"),
amountString: "1 ETH"
},
{
amount: currencyAmount(1.5, 0, false, "ETH"),
amountString: "2 ETH"
},
{
amount: currencyAmount(1.8, 0, false, "ETH"),
amountString: "2 ETH"
},
{
amount: currencyAmount(1, 4, true, "ETH"),
amountString: "1 ETH"
},
{
amount: currencyAmount(100000000000, 4, false, "ETH"),
amountString: "100.00B ETH"
},
{
amount: currencyAmount(1000000, 4, true, "ETH"),
amountString: "1,000,000 ETH"
},
{
amount: currencyAmount(100000000000, 4, true, "ETH"),
amountString: "100B ETH"
},
{
amount: currencyAmount(0.0009, 4, true, "ETH"),
amountString: "0.0009 ETH"
},
{
amount: currencyAmount(0.0009, 3, true, "ETH"),
amountString: "<0.001 ETH"
},
{
amount: currencyAmount(0.0009, 1, true, "ETH"),
amountString: "<0.1 ETH"
},
{
amount: currencyAmount(0.0009, 0, true, "ETH"),
amountString: "<1 ETH"
}
]
}
function test_currencyAmountToLocaleString(data) {
const locale = Qt.locale("en_US")
compare(LocaleUtils.currencyAmountToLocaleString(
data.amount, null, locale), data.amountString)
}
function test_numberToLocaleStringInCompactForm_data() {
return [
{
amount: NaN,
amountString: "nan"
},
{
amount: null,
amountString: "0"
},
{
amount: "",
amountString: "0"
},
{
amount: "string",
amountString: "nan"
},
{
amount: {},
amountString: "nan"
},
{
amount: -1,
amountString: "-1"
},
{
amount: -1.1,
amountString: "-1.1"
},
{
amount: -1.1234,
amountString: "-1.12"
},
{
amount: -1000,
amountString: "-1K"
},
{
amount: -1000.1,
amountString: "-1K"
},
{
amount: -100000,
amountString: "-100K"
},
{
amount: -1001,
amountString: "-1K"
},
{
amount: -1100,
amountString: "-1.1K"
},
{
amount: -1000000,
amountString: "-1M"
},
{
amount: -1100000.123,
amountString: "-1.1M"
},
{
amount: -1000000000,
amountString: "-1B"
},
{
amount: -1100000000,
amountString: "-1.1B"
},
{
amount: -1000000000.123,
amountString: "-1B"
},
{
amount: -1000000000000,
amountString: "-1T"
},
{
amount: -999000000000000,
amountString: "-999T"
},
{
amount: -1000000000000000,
amountString: "-1,000,000,000,000,000"
},
{
amount: 0,
amountString: "0"
},
{
amount: 1,
amountString: "1"
},
{
amount: 1.1,
amountString: "1.1"
},
{
amount: 1.1234,
amountString: "1.12"
},
{
amount: 1000,
amountString: "1K"
},
{
amount: 1000.1,
amountString: "1K"
},
{
amount: 100000,
amountString: "100K"
},
{
amount: 1001,
amountString: "1K"
},
{
amount: 1100,
amountString: "1.1K"
},
{
amount: 1000000,
amountString: "1M"
},
{
amount: 1100000.123,
amountString: "1.1M"
},
{
amount: 1000000000,
amountString: "1B"
},
{
amount: 1100000000,
amountString: "1.1B"
},
{
amount: 1000000000.123,
amountString: "1B"
},
{
amount: 1000000000000,
amountString: "1T"
},
{
amount: 999000000000000,
amountString: "999T"
},
{
amount: 1000000000000000,
amountString: "1,000,000,000,000,000"
}
]
}
function test_numberToLocaleStringInCompactForm(data) {
const locale = Qt.locale("en_US")
compare(LocaleUtils.numberToLocaleStringInCompactForm(
data.amount, locale), data.amountString)
}
}