diff --git a/src/tests.rs b/src/tests.rs index 650bae8..07e9bdf 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,19 +1,21 @@ +//! Unit testing on app-updates. use crate::aesthetics::{AesPlugin, Aesthetics, Distribution, Gy, Point, RestoreEvent, Unscale}; use crate::geom::{AesFilter, GeomHist, HistTag, Xaxis}; use crate::gui::{file_drop, ActiveData, UiState}; use crate::{data, escher, geom, info}; use bevy::prelude::*; +use bevy::time::TimePlugin; use bevy_prototype_lyon::prelude::{GeometryBuilder, Path, PathBuilder, ShapeBundle, Stroke}; -use bevy::asset::FileAssetIo; use bevy::tasks::IoTaskPool; /// Setup to test systems that require [`AsserServer`] as an argument. /// Adapted form bevy source code. -fn setup(asset_path: impl AsRef) -> AssetServer { - IoTaskPool::init(Default::default); - - AssetServer::new(FileAssetIo::new(asset_path, &None)) +fn setup<'appl>(app: &'appl mut App, asset_path: &str) { + IoTaskPool::get_or_init(Default::default); + let mut asset_plug = AssetPlugin::default(); + asset_plug.file_path = asset_path.to_string(); + app.add_plugins(asset_plug); } #[test] @@ -43,7 +45,10 @@ fn gy_dist_aes_spaws_xaxis_spawns_hist() { app.world.spawn(( ShapeBundle { path: GeometryBuilder::build_as(&line), - transform: Transform::from_xyz(1., 1., 1.), + spatial: SpatialBundle { + transform: Transform::from_xyz(1., 1., 1.), + ..default() + }, ..default() }, Stroke::new(Color::rgb(51. / 255., 78. / 255., 101. / 255.), 10.0), @@ -59,8 +64,7 @@ fn gy_dist_aes_spaws_xaxis_spawns_hist() { }, )); - let asset_server = setup("assets"); - app.insert_resource(asset_server); + setup(&mut app, "assets"); app.insert_resource(ActiveData::default()); app.insert_resource(UiState::default()); app.add_plugins(AesPlugin); @@ -107,7 +111,10 @@ fn point_dist_aes_spaws_box_axis_spawns_box() { app.world.spawn(( ShapeBundle { path: GeometryBuilder::build_as(&line), - transform: Transform::from_xyz(1., 1., 1.), + spatial: SpatialBundle { + transform: Transform::from_xyz(1., 1., 1.), + ..default() + }, ..default() }, Stroke::new(Color::rgb(51. / 255., 78. / 255., 101. / 255.), 10.0), @@ -123,9 +130,9 @@ fn point_dist_aes_spaws_box_axis_spawns_box() { }, )); + setup(&mut app, "asset1"); app.insert_resource(UiState::default()); app.insert_resource(ActiveData::default()); - app.insert_resource(AssetServer::new(FileAssetIo::new("asset1", &None))); app.add_plugins(AesPlugin); app.update(); @@ -153,23 +160,23 @@ fn loading_file_drop_does_not_crash() { let mut app = App::new(); app.insert_resource(UiState::default()); app.add_event::(); - let asset_server = setup("assets"); - let escher_handle: Handle = asset_server.load("ecoli_core_map.json"); + setup(&mut app, "assets"); app.insert_resource(data::ReactionState { reaction_data: None, loaded: false, }); - app.insert_resource(asset_server); - app.insert_resource(Time::default()); - app.insert_resource(escher::MapState { - escher_map: escher_handle, - loaded: false, - }); - app.init_schedule(bevy::asset::LoadAssets); + app.add_plugins(TimePlugin); app.add_plugins(info::InfoPlugin); app.add_event::(); app.add_plugins(data::DataPlugin); app.add_plugins(escher::EscherPlugin); + app.init_asset::(); + let asset_server = app.world.get_resource::().unwrap(); + let escher_handle: Handle = asset_server.load("ecoli_core_map.json"); + app.insert_resource(escher::MapState { + escher_map: escher_handle, + loaded: false, + }); app.add_systems(Update, file_drop); app.update();