diff options
Diffstat (limited to 'tests/auto/qml/qmldesigner/wizard/presetmodel-test.cpp')
-rw-r--r-- | tests/auto/qml/qmldesigner/wizard/presetmodel-test.cpp | 116 |
1 files changed, 55 insertions, 61 deletions
diff --git a/tests/auto/qml/qmldesigner/wizard/presetmodel-test.cpp b/tests/auto/qml/qmldesigner/wizard/presetmodel-test.cpp index 3c16688458..8452ca8222 100644 --- a/tests/auto/qml/qmldesigner/wizard/presetmodel-test.cpp +++ b/tests/auto/qml/qmldesigner/wizard/presetmodel-test.cpp @@ -100,6 +100,14 @@ UserPresetData aUserPreset(const QString &categId, const QString &wizardName, co return preset; } +UserPresetData aRecentPreset(const QString &categId, const QString &wizardName, const QString &screenSizeName) +{ + UserPresetData preset = aUserPreset(categId, wizardName, wizardName); + preset.screenSize = screenSizeName; + + return preset; +} + MATCHER_P2(PresetIs, category, name, PrintToString(PresetItem{name, category})) { return arg->categoryId == category && arg->wizardName == name; @@ -139,6 +147,7 @@ TEST(QdsPresetModel, haveSameArraySizeForPresetsAndCategories) PresetData data; data.setData( + /*wizard presets*/ { aCategory("A.categ", "A", {"item a", "item b"}), aCategory("B.categ", "B", {"item c", "item d"}), @@ -157,6 +166,7 @@ TEST(QdsPresetModel, haveWizardPresetsNoRecents) // When data.setData( + /*wizard presets*/ { aCategory("A.categ", "A", {"item a", "item b"}), aCategory("B.categ", "B", {"item c", "item d"}), @@ -179,6 +189,7 @@ TEST(QdsPresetModel, whenHaveUserPresetsButNoWizardPresetsReturnEmpty) // When data.setData({/*builtin presets*/}, + /*user presets*/ { aUserPreset("A.Mobile", "Scroll", "iPhone5"), aUserPreset("B.Desktop", "Launcher", "MacBook"), @@ -196,9 +207,10 @@ TEST(QdsPresetModel, haveRecentsNoWizardPresets) data.setData({/*wizardPresets*/}, {/*user presets*/}, + /*recent presets*/ { - {"A.categ", "Desktop", "640 x 480"}, - {"B.categ", "Mobile", "800 x 600"}, + aRecentPreset("A.categ", "Desktop", "640 x 480"), + aRecentPreset("B.categ", "Mobile", "800 x 600"), }); ASSERT_THAT(data.categories(), IsEmpty()); @@ -220,8 +232,8 @@ TEST(QdsPresetModel, recentsAddedWithWizardPresets) {/*user presets*/}, /*recents*/ { - {"A.categ", "Desktop", "800 x 600"}, - {"B.categ", "Mobile", "640 x 480"}, + aRecentPreset("A.categ", "Desktop", "800 x 600"), + aRecentPreset("B.categ", "Mobile", "640 x 480"), }); // Then @@ -247,6 +259,7 @@ TEST(QdsPresetModel, userPresetsAddedWithWizardPresets) aCategory("A.categ", "A", {"Desktop", "item b"}), aCategory("B.categ", "B", {"Mobile"}), }, + /*user presets*/ { aUserPreset("A.categ", "Desktop", "Windows10"), }, @@ -272,6 +285,7 @@ TEST(QdsPresetModel, doesNotAddUserPresetsOfNonExistingCategory) { aCategory("A.categ", "A", {"Desktop"}), // Only category "A.categ" exists }, + /*user presets*/ { aUserPreset("Bad.Categ", "Desktop", "Windows8"), // Bad.Categ does not exist }, @@ -293,6 +307,7 @@ TEST(QdsPresetModel, doesNotAddUserPresetIfWizardPresetItRefersToDoesNotExist) { aCategory("A.categ", "A", {"Desktop"}), }, + /*user presets*/ { aUserPreset("B.categ", "BadWizard", "Tablet"), // BadWizard referenced does not exist }, @@ -314,6 +329,7 @@ TEST(QdsPresetModel, userPresetWithSameNameAsWizardPreset) { aCategory("A.categ", "A", {"Desktop"}), }, + /*user presets*/ { aUserPreset("A.categ", "Desktop", "Desktop"), }, @@ -326,34 +342,7 @@ TEST(QdsPresetModel, userPresetWithSameNameAsWizardPreset) ElementsAre(UserPresetIs("A.categ", "Desktop", "Desktop")))); } -TEST(QdsPresetModel, recentOfUserPresetReferringToExistingWizardPreset) -{ - // Given - PresetData data; - - // When - data.setData( - /*wizard presets*/ - { - aCategory("A.categ", "A", {"Desktop"}), - }, - { - aUserPreset("A.categ", "Desktop", "Windows 7"), - }, - /*recents*/ - { - {"A.categ", "Windows 7", "200 x 300", /*is user*/true} - }); - - // Then - ASSERT_THAT(data.categories(), ElementsAre("Recents", "A", "Custom")); - ASSERT_THAT(data.presets(), - ElementsAre(ElementsAre(UserPresetIs("A.categ", "Desktop", "Windows 7")), - ElementsAre(PresetIs("A.categ", "Desktop")), - ElementsAre(UserPresetIs("A.categ", "Desktop", "Windows 7")))); -} - -TEST(QdsPresetModel, recentOfUserPresetReferringToNonexistingWizardPreset) +TEST(QdsPresetModel, recentOfNonExistentWizardPreset) { // Given PresetData data; @@ -364,12 +353,10 @@ TEST(QdsPresetModel, recentOfUserPresetReferringToNonexistingWizardPreset) { aCategory("A.categ", "A", {"Desktop"}), }, - { - aUserPreset("A.categ", "Not-Desktop", "Windows 7"), // Non-existing Wizard Preset - }, + {/*user presets*/}, /*recents*/ { - {"A.categ", "Windows 7", "200 x 300", /*is user*/true} + aRecentPreset("A.categ", "Windows 7", "200 x 300") }); // Then @@ -377,7 +364,7 @@ TEST(QdsPresetModel, recentOfUserPresetReferringToNonexistingWizardPreset) ASSERT_THAT(data.presets(), ElementsAre(ElementsAre(PresetIs("A.categ", "Desktop")))); } -TEST(QdsPresetModel, recentOfNonExistentUserPreset) +TEST(QdsPresetModel, recentsShouldNotBeSorted) { // Given PresetData data; @@ -386,20 +373,26 @@ TEST(QdsPresetModel, recentOfNonExistentUserPreset) data.setData( /*wizard presets*/ { - aCategory("A.categ", "A", {"Desktop"}), + aCategory("A.categ", "A", {"Desktop", "item b"}), + aCategory("B.categ", "B", {"item c", "Mobile"}), + aCategory("Z.categ", "Z", {"Z.desktop"}), }, {/*user presets*/}, /*recents*/ { - {"A.categ", "Windows 7", "200 x 300", /*is user*/true} + aRecentPreset("Z.categ", "Z.desktop", "200 x 300"), + aRecentPreset("B.categ", "Mobile", "200 x 300"), + aRecentPreset("A.categ", "Desktop", "200 x 300"), }); // Then - ASSERT_THAT(data.categories(), ElementsAre("A")); - ASSERT_THAT(data.presets(), ElementsAre(ElementsAre(PresetIs("A.categ", "Desktop")))); + ASSERT_THAT(data.presets()[0], + ElementsAre(PresetIs("Z.categ", "Z.desktop"), + PresetIs("B.categ", "Mobile"), + PresetIs("A.categ", "Desktop"))); } -TEST(QdsPresetModel, recentsShouldNotBeSorted) +TEST(QdsPresetModel, recentsOfSameWizardProjectButDifferentSizesAreRecognizedAsDifferentPresets) { // Given PresetData data; @@ -408,26 +401,25 @@ TEST(QdsPresetModel, recentsShouldNotBeSorted) data.setData( /*wizard presets*/ { - aCategory("A.categ", "A", {"Desktop", "item b"}), - aCategory("B.categ", "B", {"item c", "Mobile"}), - aCategory("Z.categ", "Z", {"Z.desktop"}), + aCategory("A.categ", "A", {"Desktop"}), + aCategory("B.categ", "B", {"Mobile"}), }, {/*user presets*/}, /*recents*/ { - {"Z.categ", "Z.desktop", "200 x 300"}, - {"B.categ", "Mobile", "200 x 300"}, - {"A.categ", "Desktop", "200 x 300"}, + aRecentPreset("B.categ", "Mobile", "400 x 400"), + aRecentPreset("B.categ", "Mobile", "200 x 300"), + aRecentPreset("A.categ", "Desktop", "640 x 480"), }); // Then ASSERT_THAT(data.presets()[0], - ElementsAre(PresetIs("Z.categ", "Z.desktop"), - PresetIs("B.categ", "Mobile"), - PresetIs("A.categ", "Desktop"))); + ElementsAre(PresetIs("B.categ", "Mobile", "400 x 400"), + PresetIs("B.categ", "Mobile", "200 x 300"), + PresetIs("A.categ", "Desktop", "640 x 480"))); } -TEST(QdsPresetModel, recentsOfSameWizardProjectButDifferentSizesAreRecognizedAsDifferentPresets) +TEST(QdsPresetModel, allowRecentsWithTheSameName) { // Given PresetData data; @@ -437,21 +429,23 @@ TEST(QdsPresetModel, recentsOfSameWizardProjectButDifferentSizesAreRecognizedAsD /*wizard presets*/ { aCategory("A.categ", "A", {"Desktop"}), - aCategory("B.categ", "B", {"Mobile"}), }, {/*user presets*/}, /*recents*/ { - {"B.categ", "Mobile", "400 x 400"}, - {"B.categ", "Mobile", "200 x 300"}, - {"A.categ", "Desktop", "640 x 480"}, + /* NOTE: it is assumed recents with the same name and size have other fields that + * distinguishes them from one another. It is the responsibility of the caller, who + * calls data.setData() to make sure that the recents do not contain duplicates. */ + aRecentPreset("A.categ", "Desktop", "200 x 300"), + aRecentPreset("A.categ", "Desktop", "200 x 300"), + aRecentPreset("A.categ", "Desktop", "200 x 300"), }); // Then ASSERT_THAT(data.presets()[0], - ElementsAre(PresetIs("B.categ", "Mobile", "400 x 400"), - PresetIs("B.categ", "Mobile", "200 x 300"), - PresetIs("A.categ", "Desktop", "640 x 480"))); + ElementsAre(PresetIs("A.categ", "Desktop"), + PresetIs("A.categ", "Desktop"), + PresetIs("A.categ", "Desktop"))); } TEST(QdsPresetModel, outdatedRecentsAreNotShown) @@ -469,8 +463,8 @@ TEST(QdsPresetModel, outdatedRecentsAreNotShown) {/*user presets*/}, /*recents*/ { - {"B.categ", "NoLongerExists", "400 x 400"}, - {"A.categ", "Desktop", "640 x 480"}, + aRecentPreset("B.categ", "NoLongerExists", "400 x 400"), + aRecentPreset("A.categ", "Desktop", "640 x 480"), }); // Then |