|
| 1 | +local unit_test_functions = require("unit-test-functions") |
| 2 | + |
| 3 | +local LOG = unit_test_functions.print_msg |
| 4 | +local SUCCESS = unit_test_functions.test_successful |
| 5 | +local FAIL = unit_test_functions.test_failed |
| 6 | +local INVALID = unit_test_functions.test_invalid |
| 7 | +local ASSERT = unit_test_functions.assert |
| 8 | +local ASSERT_EQUAL = unit_test_functions.assert_equal |
| 9 | + |
| 10 | +local test_search = function(tick) |
| 11 | + LOG("Unit testing mod configuration:") |
| 12 | + for mod_name, mod_version in pairs(script.active_mods) do |
| 13 | + LOG(mod_name .. " version " .. mod_version) |
| 14 | + end |
| 15 | + |
| 16 | + -- Setup |
| 17 | + local player = game.get_player(1) ---@cast player -? |
| 18 | + player.exit_cutscene() |
| 19 | + |
| 20 | + local surface = player.surface |
| 21 | + |
| 22 | + --surface.clear(true) |
| 23 | + local chest = surface.create_entity{ |
| 24 | + name = "steel-chest", |
| 25 | + position = {5, 5}, |
| 26 | + force = player.force, |
| 27 | + } ---@cast chest -? |
| 28 | + |
| 29 | + chest.insert({name = "iron-plate", count = 100}) |
| 30 | + |
| 31 | + -- Run test |
| 32 | + |
| 33 | + remote.call("factory-search", "set_search_state", player, |
| 34 | + ---@diagnostic disable-next-line: missing-fields |
| 35 | + { |
| 36 | + all_qualities = true, |
| 37 | + all_surfaces = true, |
| 38 | + consumers = false, |
| 39 | + producers = false, |
| 40 | + storage = true, |
| 41 | + logistics = false, |
| 42 | + modules = false, |
| 43 | + requesters = false, |
| 44 | + ground_items = false, |
| 45 | + entities = false, |
| 46 | + signals = false, |
| 47 | + map_tags = false, |
| 48 | + }) |
| 49 | + remote.call("factory-search", "search", player, {name = "iron-plate"}) |
| 50 | + |
| 51 | + -- Check result |
| 52 | + local search_frame = player.gui.screen["fs_frame"] |
| 53 | + local results_flow = search_frame |
| 54 | + .children[2] -- inside_shallow_frame |
| 55 | + .children[2] -- horizontal flow |
| 56 | + .children[2] -- scroll pane |
| 57 | + .children[1] -- vertical flow |
| 58 | + .children[2] -- result_flow |
| 59 | + |
| 60 | + local surface_counts_flow = results_flow.children[1] -- [2] when include_surface_name |
| 61 | + local item_count_label = surface_counts_flow.children[1] |
| 62 | + ASSERT(item_count_label.caption[5] == "100", "Item count label does not show the correct number of items.") |
| 63 | + |
| 64 | + local results_table = results_flow |
| 65 | + .children[2] -- vertical frame (slot_button_deep_frame) ([3] when include_surface_name) |
| 66 | + .children[3] -- table (storage results) |
| 67 | + |
| 68 | + ASSERT(#results_table.children == 1, "No results found in search table, test failed.") |
| 69 | + local result_button = results_table.children[1] |
| 70 | + ASSERT(result_button.sprite == "entity/steel-chest", "Result button does not have the correct sprite.") |
| 71 | + ASSERT(result_button.number == 1, "Result button does not have the correct number of items.") |
| 72 | + ASSERT(result_button.tags.position.x == 5.5 and result_button.tags.position.y == 5.5, |
| 73 | + "Result button does not have the correct position tags.") |
| 74 | + ASSERT(result_button.tags.surface == surface.name, "Result button does not have the correct surface tag.") |
| 75 | + return SUCCESS |
| 76 | +end |
| 77 | + |
| 78 | +return {test_search = test_search} |
0 commit comments