Skip to content

Commit

Permalink
test: update test suite to bevy 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
carrascomj committed Mar 13, 2024
1 parent b1c6c79 commit 4ec2e9b
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -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<std::path::Path>) -> 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]
Expand Down Expand Up @@ -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),
Expand All @@ -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);
Expand Down Expand Up @@ -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),
Expand All @@ -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();

Expand Down Expand Up @@ -153,23 +160,23 @@ fn loading_file_drop_does_not_crash() {
let mut app = App::new();
app.insert_resource(UiState::default());
app.add_event::<RestoreEvent>();
let asset_server = setup("assets");
let escher_handle: Handle<escher::EscherMap> = 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::<FileDragAndDrop>();
app.add_plugins(data::DataPlugin);
app.add_plugins(escher::EscherPlugin);
app.init_asset::<Font>();
let asset_server = app.world.get_resource::<AssetServer>().unwrap();
let escher_handle: Handle<escher::EscherMap> = 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();
Expand Down

0 comments on commit 4ec2e9b

Please sign in to comment.