|
1 | 1 | describe("Spectre Library", function() |
2 | | - local controls |
3 | | - local frostbearer = "Metadata/Monsters/LeagueCrucible/Cold/Pyromaniac" |
| 2 | + local controls, searchText, showAll, showAllCheckbox, corpseOnly |
| 3 | + |
| 4 | + -- Picks a Spectre that only Show All reveals, with a name that no recommended Spectre matches |
| 5 | + local function findHiddenSpectre(itemisedCorpse) |
| 6 | + local minions = build.data.minions |
| 7 | + local recommendedNames = { } |
| 8 | + for id in pairs(build.data.spectres) do |
| 9 | + if minions[id].extraFlags and minions[id].extraFlags.recommendedSpectre then |
| 10 | + table.insert(recommendedNames, minions[id].name:lower()) |
| 11 | + end |
| 12 | + end |
| 13 | + local candidates = { } |
| 14 | + for id in pairs(build.data.spectres) do |
| 15 | + local minion = minions[id] |
| 16 | + local name = minion.name:lower() |
| 17 | + if not (minion.extraFlags and minion.extraFlags.recommendedSpectre) |
| 18 | + and (minion.itemisedCorpse ~= nil) == itemisedCorpse and name:match("^[%a ]+$") then |
| 19 | + local hidden = true |
| 20 | + for _, recommendedName in ipairs(recommendedNames) do |
| 21 | + if recommendedName:find(name, 1, true) then |
| 22 | + hidden = false |
| 23 | + break |
| 24 | + end |
| 25 | + end |
| 26 | + -- Keep the name distinct from skill names so that it only matches in the name search modes |
| 27 | + for _, skill in pairs(build.data.skills) do |
| 28 | + if skill.name and skill.name:lower():find(name, 1, true) then |
| 29 | + hidden = false |
| 30 | + break |
| 31 | + end |
| 32 | + end |
| 33 | + if hidden then |
| 34 | + table.insert(candidates, id) |
| 35 | + end |
| 36 | + end |
| 37 | + end |
| 38 | + table.sort(candidates) |
| 39 | + assert.is_truthy(candidates[1], "Expected a Spectre that is only listed with Show All") |
| 40 | + return candidates[1], minions[candidates[1]].name |
| 41 | + end |
| 42 | + |
| 43 | + local function setCorpseOnly(state) |
| 44 | + corpseOnly.state = state |
| 45 | + corpseOnly.changeFunc(state) |
| 46 | + end |
4 | 47 |
|
5 | 48 | before_each(function() |
6 | 49 | newBuild() |
7 | 50 | build:OpenSpectreLibrary() |
8 | 51 | controls = main.popups[1].controls |
| 52 | + searchText = controls.source.controls.searchText |
| 53 | + showAll = controls.source.controls.showAllForSearch |
| 54 | + showAllCheckbox = controls.sortMonsterCheckboxShowAll |
| 55 | + corpseOnly = controls.sortMonsterCheckboxFilterCorpse |
9 | 56 | end) |
10 | 57 |
|
11 | 58 | after_each(function() |
12 | 59 | main:ClosePopup() |
13 | 60 | end) |
14 | 61 |
|
15 | 62 | it("offers to enable Show All when a spectre search has no recommended matches", function() |
16 | | - local searchText = controls.source.controls.searchText |
17 | | - local showAll = controls.source.controls.showAllForSearch |
18 | | - searchText:SetText("forge", true) |
| 63 | + local id, name = findHiddenSpectre(false) |
| 64 | + searchText:SetText(name, true) |
19 | 65 | assert.are.equal(0, #controls.source.list) |
20 | 66 | assert.is_truthy(showAll and showAll:IsShown(), |
21 | 67 | "An empty recommended search should offer Show All") |
22 | 68 |
|
23 | 69 | searchText:SetText("", true) |
24 | 70 | assert.is_false(showAll:IsShown()) |
25 | | - searchText:SetText("forge", true) |
| 71 | + searchText:SetText(name, true) |
26 | 72 | showAll.onClick() |
27 | 73 |
|
28 | | - assert.is_true(controls.sortMonsterCheckboxShowAll.state) |
29 | | - assert.are.equal("forge", searchText.buf) |
30 | | - assert.is_truthy(isValueInArray(controls.source.list, frostbearer)) |
| 74 | + assert.is_true(showAllCheckbox.state) |
| 75 | + assert.are.equal(name, searchText.buf) |
| 76 | + assert.is_truthy(isValueInArray(controls.source.list, id)) |
31 | 77 | assert.is_false(showAll:IsShown()) |
| 78 | + end) |
32 | 79 |
|
| 80 | + it("does not offer Show All when it would not find anything either", function() |
33 | 81 | searchText:SetText("no such spectre", true) |
34 | 82 | assert.are.equal(0, #controls.source.list) |
35 | 83 | assert.is_false(showAll:IsShown()) |
| 84 | + |
| 85 | + -- Hidden by the monster type filter, which Show All does not change |
| 86 | + local id, name = findHiddenSpectre(false) |
| 87 | + local typeCheckbox = controls["sortMonsterCheckbox" .. build.data.minions[id].monsterCategory] |
| 88 | + searchText:SetText(name, true) |
| 89 | + assert.is_true(showAll:IsShown()) |
| 90 | + typeCheckbox.state = false |
| 91 | + typeCheckbox.changeFunc(false) |
| 92 | + assert.are.equal(0, #controls.source.list) |
| 93 | + assert.is_false(showAll:IsShown()) |
| 94 | + typeCheckbox.state = true |
| 95 | + typeCheckbox.changeFunc(true) |
| 96 | + assert.is_true(showAll:IsShown()) |
| 97 | + |
| 98 | + -- No Spectre has a skill with this name |
| 99 | + controls.source.controls.searchModeDropDown:SetSel(2) |
| 100 | + assert.are.equal(0, #controls.source.list) |
| 101 | + assert.is_false(showAll:IsShown()) |
36 | 102 | end) |
37 | 103 |
|
38 | 104 | it("keeps Corpse Only enabled when expanding an empty search", function() |
39 | | - local corpseOnly = controls.sortMonsterCheckboxFilterCorpse |
40 | | - corpseOnly.state = true |
41 | | - corpseOnly.changeFunc(true) |
42 | | - controls.source.controls.searchText:SetText("forge", true) |
| 105 | + local plainId, plainName = findHiddenSpectre(false) |
| 106 | + local corpseId, corpseName = findHiddenSpectre(true) |
| 107 | + setCorpseOnly(true) |
43 | 108 |
|
44 | | - local showAll = controls.source.controls.showAllForSearch |
45 | | - assert.is_truthy(showAll and showAll:IsShown()) |
| 109 | + -- Show All would still hide a Spectre that has no itemised corpse |
| 110 | + searchText:SetText(plainName, true) |
| 111 | + assert.are.equal(0, #controls.source.list) |
| 112 | + assert.is_false(showAll:IsShown()) |
| 113 | + |
| 114 | + searchText:SetText(corpseName, true) |
| 115 | + assert.are.equal(0, #controls.source.list) |
| 116 | + assert.is_true(showAll:IsShown()) |
46 | 117 | showAll.onClick() |
47 | 118 |
|
48 | 119 | assert.is_true(corpseOnly.state) |
49 | | - assert.are.equal(0, #controls.source.list) |
| 120 | + assert.is_true(showAllCheckbox.state) |
| 121 | + assert.is_truthy(isValueInArray(controls.source.list, corpseId)) |
| 122 | + assert.is_nil(isValueInArray(controls.source.list, plainId)) |
50 | 123 | end) |
51 | 124 | end) |
0 commit comments