Skip to content

Commit

Permalink
Token/Asset selectors fixes
Browse files Browse the repository at this point in the history
- clear search on close (AssetSelectorCompact)
- sectionProperty removed
- highlighting fixed in TokenSelectorPanel
- setCustom renamed to setSelection
- test data moved into Component object
  • Loading branch information
micieslak committed Sep 23, 2024
1 parent 249e1ae commit 00fe754
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 165 deletions.
9 changes: 4 additions & 5 deletions storybook/pages/AssetSelectorCompactPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Pane {
}
],

sectionText: "My assets on Mainnet"
sectionName: "My assets on Mainnet"
},
{
tokensKey: "key_2",
Expand All @@ -41,7 +41,7 @@ Pane {
}
],

sectionText: "My assets on Mainnet"
sectionName: "My assets on Mainnet"
},
{
tokensKey: "key_2",
Expand All @@ -53,7 +53,7 @@ Pane {
tokensKey: "DAI",
balances: [],

sectionText: "Popular assets"
sectionName: "Popular assets"
},
{
tokensKey: "key_3",
Expand All @@ -65,7 +65,7 @@ Pane {
tokensKey: "ZRX",
balances: [],

sectionText: "Popular assets"
sectionName: "Popular assets"
}
]

Expand All @@ -86,7 +86,6 @@ Pane {
width: 400

model: assetsModel
sectionProperty: "sectionText"

onSelected: console.log("asset selected:", key)
}
Expand Down
9 changes: 4 additions & 5 deletions storybook/pages/AssetSelectorPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Pane {
}
],

sectionText: "My assets on Mainnet"
sectionName: "My assets on Mainnet"
},
{
tokensKey: "eth_key",
Expand All @@ -39,7 +39,7 @@ Pane {
}
],

sectionText: "My assets on Mainnet"
sectionName: "My assets on Mainnet"
},
{
tokensKey: "dai_key",
Expand All @@ -50,7 +50,7 @@ Pane {
iconSource: Constants.tokenIcon("DAI"),
balances: [],

sectionText: "Popular assets"
sectionName: "Popular assets"
},
{
tokensKey: "zrx_key",
Expand All @@ -61,7 +61,7 @@ Pane {
iconSource: Constants.tokenIcon("ZRX"),
balances: [],

sectionText: "Popular assets"
sectionName: "Popular assets"
}
]

Expand All @@ -81,7 +81,6 @@ Pane {
anchors.centerIn: parent

model: assetsModel
sectionProperty: "sectionText"

onSelected: console.log("asset selected:", key)
}
Expand Down
9 changes: 4 additions & 5 deletions storybook/pages/SearchableAssetsPanelPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Pane {
}
],

sectionText: ""
sectionName: ""
},
{
tokensKey: "eth_key",
Expand All @@ -53,7 +53,7 @@ Pane {
}
],

sectionText: ""
sectionName: ""
},
{
tokensKey: "dai_key",
Expand All @@ -64,7 +64,7 @@ Pane {
iconSource: Constants.tokenIcon("DAI"),
balances: [],

sectionText: "Popular assets"
sectionName: "Popular assets"
},
{
tokensKey: "zrx_key",
Expand All @@ -75,7 +75,7 @@ Pane {
iconSource: Constants.tokenIcon("ZRX"),
balances: [],

sectionText: "Popular assets"
sectionName: "Popular assets"
}
]

Expand All @@ -102,7 +102,6 @@ Pane {
highlightedKey: "key_2"

model: assetsModel
sectionProperty: "sectionText"

onSelected: console.log("selected:", key)
}
Expand Down
114 changes: 54 additions & 60 deletions storybook/qmlTests/tests/tst_AssetSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,65 @@ Item {
width: 600
height: 600

readonly property var assetsData: [
{
tokensKey: "stt_key",
communityId: "",
name: "Status Test Token",
currencyBalanceAsString: "42,23 USD",
symbol: "STT",
iconSource: Constants.tokenIcon("STT"),

balances: [
{
balanceAsString: "0,56",
iconUrl: "network/Network=Ethereum"
}
],

sectionText: "My assets on Mainnet"
},
{
tokensKey: "eth_key",
communityId: "",
name: "Ether",
currencyBalanceAsString: "4 276,86 USD",
symbol: "ETH",
iconSource: Constants.tokenIcon("ETH"),

balances: [
{
balanceAsString: "0,12",
iconUrl: "network/Network=Ethereum"
}
],

sectionText: "My assets on Mainnet"
},
{
tokensKey: "dai_key",
communityId: "",
name: "Dai Stablecoin",
currencyBalanceAsString: "45,92 USD",
symbol: "DAI",
iconSource: Constants.tokenIcon("DAI"),
balances: [],

sectionText: "Popular assets"
}
]

ListModel {
id: assetsModel

Component.onCompleted: append(assetsData)
}

Component {
id: selectorCmp

AssetSelector {
id: selector

anchors.centerIn: parent
model: assetsModel

readonly property var assetsData: [
{
tokensKey: "stt_key",
communityId: "",
name: "Status Test Token",
currencyBalanceAsString: "42,23 USD",
symbol: "STT",
iconSource: Constants.tokenIcon("STT"),

balances: [
{
balanceAsString: "0,56",
iconUrl: "network/Network=Ethereum"
}
],

sectionName: "My assets on Mainnet"
},
{
tokensKey: "eth_key",
communityId: "",
name: "Ether",
currencyBalanceAsString: "4 276,86 USD",
symbol: "ETH",
iconSource: Constants.tokenIcon("ETH"),

balances: [
{
balanceAsString: "0,12",
iconUrl: "network/Network=Ethereum"
}
],

sectionName: "My assets on Mainnet"
},
{
tokensKey: "dai_key",
communityId: "",
name: "Dai Stablecoin",
currencyBalanceAsString: "45,92 USD",
symbol: "DAI",
iconSource: Constants.tokenIcon("DAI"),
balances: [],

sectionName: "Popular assets"
}
]

model: ListModel {
Component.onCompleted: append(selector.assetsData)
}

readonly property SignalSpy selectedSpy: SignalSpy {
target: selector
Expand All @@ -89,8 +86,6 @@ Item {
function test_basic() {
const selector = createTemporaryObject(selectorCmp, root)
selector.nonInteractiveKey = "eth_key"
selector.sectionProperty = "sectionText"

compare(selector.isSelected, false)
waitForRendering(selector)

Expand All @@ -102,7 +97,6 @@ Item {
const panel = findChild(selector.Overlay.overlay, "searchableAssetsPanel")
compare(panel.model, selector.model)
compare(panel.nonInteractiveKey, selector.nonInteractiveKey)
compare(panel.sectionProperty, selector.sectionProperty)
}

function test_basicSelection() {
Expand All @@ -121,7 +115,7 @@ Item {
const listView = findChild(selector.Overlay.overlay, "assetsListView")
verify(listView)

compare(listView.count, root.assetsData.length)
compare(listView.count, selector.assetsData.length)
waitForRendering(listView)

const delegate1 = listView.itemAtIndex(0)
Expand Down Expand Up @@ -196,7 +190,7 @@ Item {
waitForRendering(selector)

const imageUrl = Constants.tokenIcon("DAI")
selector.setCustom("Custom", imageUrl, "custom_key")
selector.setSelection("Custom", imageUrl, "custom_key")

compare(selector.isSelected, true)
compare(selector.selectedSpy.count, 0)
Expand Down
Loading

0 comments on commit 00fe754

Please sign in to comment.