Skip to content

Commit

Permalink
Add a test of Field.
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsenD98 committed Jul 2, 2024
1 parent 1babee3 commit f80c1d9
Showing 1 changed file with 109 additions and 9 deletions.
118 changes: 109 additions & 9 deletions test/qml/tst_featureForm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,34 @@ TestCase {
}

/**
* Test case for featureForm (Apiary type).
* Test case for the featureForm (Apiary type).
*
* This function checks the visibility of the toolbar, the title label, and the tab row.
* It also verifies the presence and values of various UI elements within each tab.
* This test verifies that the feature form is properly initialized and displays the expected data for a selected feature.
*
* Specifically, it checks:
* - The toolbar visibility
* - The title text
* - The tab row count
* - Each tab has a corresponding text and is currently selected
* - The fields in the "General" tab are correctly populated with values
* Preconditions:
* - The featureForm object is initialized and has a reference to a layer.
*
* Steps:
* 1. Verify that the toolbar is not visible.
* 2. Verify that the title label text is "View feature on Apiary".
* 3. Verify that the tab row has 6 rows and that each row has a valid tab name (e.g., "General", "Picture", "Issues", "Review", "Consumption", "GNSS").
* 4. For each tab:
* - Verify that the tab delegate has a valid text value matching the expected tab name.
* - Verify that the tab delegate is currently selected (i.e., isCurrentIndex is true).
* 5. For each field repeater item in the "General" tab:
* - Verify that the item loader has a valid container name matching the expected value.
* - Verify that the field container has a child element with a text value matching the expected container name.
* - Verify that the attribute editor loader has a valid widget type and source matching the expected values.
* - Verify that the attribute editor loader's current feature attribute value matches the expected value.
*
* Expected Results:
* 1. The toolbar is not visible.
* 2. The title label text is "View feature on Apiary".
* 3. The tab row has 6 rows with valid tab names.
* 4. Each tab delegate has a valid text value and is currently selected.
* 5. Each field repeater item in the "General" tab has valid container names, widget types, and source values, and matches the expected attribute editor loader values.
*/

function test_01_featureForm() {
const toolbar = Utils.findChildren(featureForm, "toolbar")
compare(toolbar.visible, false)
Expand Down Expand Up @@ -147,4 +163,88 @@ TestCase {
compare(initialValue, testModel[j].value)
}
}

/**
* Test case for the featureForm (Field type).
*
* This test verifies that the feature form is properly initialized and displays the expected data for a selected feature.
*
* Preconditions:
* - The qgisProject object is initialized and has a layer named "Fields" with at least one feature.
* - The featureForm object is initialized and has a reference to the "Fields" layer.
*
* Steps:
* 1. Set the mSelectedLayer property of featureForm to the "Fields" layer.
* 2. Set the mSelectedFeature property of featureForm to the first feature in the "Fields" layer.
* 3. Verify that the toolbar is not visible.
* 4. Verify that the title label text is "View feature on Fields".
* 5. Verify that the tab row has 4 rows and that each row has a valid tab name (e.g., "General", "Picture", "Review", "Consuming Apiaries").
* 6. For each tab:
* - Verify that the tab delegate has a valid text value matching the expected tab name.
* - Verify that the tab delegate is currently selected (i.e., isCurrentIndex is true).
* 7. For each field repeater item in the "General" tab:
* - Verify that the item loader has a valid container name matching the expected value.
* - Verify that the field container has a child element with a text value matching the expected container name.
* - Verify that the attribute editor loader has a valid widget type and source matching the expected values.
* - Verify that the attribute editor loader's current feature attribute value matches the expected value.
*
* Expected Results:
* 1. The toolbar is not visible.
* 2. The title label text is "View feature on Fields".
* 3. The tab row has 4 rows with valid tab names.
* 4. Each tab delegate has a valid text value and is currently selected.
* 5. Each field repeater item in the "General" tab has valid container names, widget types, and source values, and matches the expected attribute editor loader values.
*/
function test_02_featureForm() {
featureForm.mSelectedLayer = qgisProject.mapLayersByName('Fields')[0]
featureForm.mSelectedFeature = qgisProject.mapLayersByName('Fields')[0].getFeature("39")

const toolbar = Utils.findChildren(featureForm, "toolbar")
compare(toolbar.visible, false)

const titleLabel = Utils.findChildren(featureForm, "titleLabel")
compare(titleLabel.text, "View feature on Fields")

const tabRow = Utils.findChildren(featureForm, "tabRow")
compare(tabRow.model.hasTabs, true)
compare(tabRow.model.rowCount(), 4)

const tabs = ["General", "Picture","Review", "Consuming Apiaries"]
for (var i = 0; i < tabRow.model.rowCount(); ++i) {
tabRow.currentIndex = i
const delegate = Utils.findChildren(featureForm, "tabRowdDlegate_" + i)
compare(delegate.text, tabs[i])
compare(delegate.isCurrentIndex, true)
compare(tabRow.currentIndex, i)
}

// test fields in tabRow.currentIndex = 0 ("General")
const fieldItem = Utils.findChildren(featureForm, "fieldRepeater")
const testModel = [{
"containerName": "Proprietor",
"widgetType": "ValueMap",
"source": "editorwidgets/ValueMap.qml",
"value": "national"
}, {
"containerName": "Plants",
"widgetType": "ValueMap",
"source": "editorwidgets/ValueMap.qml",
"value": "taraxacum"
}]

for (var j = 0; j < fieldItem.count; ++j) {
const itemLoader = fieldItem.itemAt(j).children[2].children[0]
const fieldContainer = fieldItem.itemAt(j).children[2].children[1]
const attributeEditorLoader = Utils.findChildren(featureForm, "attributeEditorLoader" + itemLoader.containerName)
const attributeConfig = attributeEditorLoader.config
const initialValue = attributeEditorLoader.currentFeature.attribute(itemLoader.containerName)

compare(itemLoader.containerName, testModel[j].containerName)
compare(fieldContainer.children[0].text, testModel[j].containerName)
compare(attributeEditorLoader.widget, testModel[j].widgetType)
compare(attributeEditorLoader.source, testModel[j].source)
compare(initialValue, testModel[j].value)
}
}

}

0 comments on commit f80c1d9

Please sign in to comment.