2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-16 20:25:26 +00:00

Format code

This commit is contained in:
Asterix\Oliver
2025-06-14 10:59:13 +10:00
parent 0349ebb0b3
commit 387dc1eb39
96 changed files with 5478 additions and 7340 deletions

View File

@ -10,23 +10,19 @@ import "package:inventree/user_profile.dart";
import "setup.dart";
void main() {
setupTestEnv();
setUp(() async {
await setupServerProfile(select: true);
// Ensure the profile is selected
assert(! await UserProfileDBManager().selectProfileByName("Missing Profile"));
assert(
!await UserProfileDBManager().selectProfileByName("Missing Profile"));
assert(await UserProfileDBManager().selectProfileByName(testServerName));
});
group("Login Tests:", () {
test("Disconnected", () async {
// Test that calling disconnect() does the right thing
var api = InvenTreeAPI();
@ -37,7 +33,6 @@ void main() {
expect(api.isConnected(), equals(false));
expect(api.isConnecting(), equals(false));
expect(api.hasToken, equals(false));
});
test("Login Failure", () async {
@ -66,7 +61,6 @@ void main() {
debugContains("Token request failed: STATUS 401");
debugContains("showSnackIcon: 'Not Connected'");
});
test("Bad Token", () async {
@ -125,6 +119,5 @@ void main() {
debugContains("Received token from server");
debugContains("showSnackIcon: 'Connected to Server'");
});
});
}
}

View File

@ -18,7 +18,6 @@ import "package:inventree/inventree/stock.dart";
import "setup.dart";
void main() {
setupTestEnv();
@ -64,14 +63,12 @@ void main() {
debugContains("showSnackIcon: 'No match for barcode'");
assert(debugMessageCount() == 3);
});
});
group("Test StockItemScanIntoLocationHandler:", () {
// Tests for scanning a stock item into a location
test("Scan Into Location", () async {
final item = await InvenTreeStockItem().get(1) as InvenTreeStockItem?;
assert(item != null);
@ -90,7 +87,6 @@ void main() {
await handler.processBarcode('{"stocklocation": 1}');
await item.reload();
assert(item.locationId == 1);
});
});
@ -98,7 +94,8 @@ void main() {
// Tests for scanning items into a stock location
test("Scan In Items", () async {
final location = await InvenTreeStockLocation().get(1) as InvenTreeStockLocation?;
final location =
await InvenTreeStockLocation().get(1) as InvenTreeStockLocation?;
assert(location != null);
assert(location!.pk == 1);
@ -115,7 +112,6 @@ void main() {
assert(item!.pk == id);
assert(item!.locationId == 1);
}
});
});
@ -123,7 +119,8 @@ void main() {
// Tests for scanning a location into a parent location
test("Scan Parent", () async {
final location = await InvenTreeStockLocation().get(7) as InvenTreeStockLocation?;
final location =
await InvenTreeStockLocation().get(7) as InvenTreeStockLocation?;
assert(location != null);
assert(location!.pk == 7);
@ -146,14 +143,10 @@ void main() {
});
group("Test PartBarcodes:", () {
// Assign a custom barcode to a Part instance
test("Assign Barcode", () async {
// Unlink barcode first
await InvenTreeAPI().unlinkBarcode({
"part": "2"
});
await InvenTreeAPI().unlinkBarcode({"part": "2"});
final part = await InvenTreePart().get(2) as InvenTreePart?;
@ -164,22 +157,17 @@ void main() {
assert(part!.customBarcode.isEmpty);
// Assign custom barcode data to the part
await InvenTreeAPI().linkBarcode({
"part": "2",
"barcode": "xyz-123"
});
await InvenTreeAPI().linkBarcode({"part": "2", "barcode": "xyz-123"});
await part!.reload();
assert(part.customBarcode.isNotEmpty);
// Check we can de-register a barcode also
// Unlink barcode first
await InvenTreeAPI().unlinkBarcode({
"part": "2"
});
await InvenTreeAPI().unlinkBarcode({"part": "2"});
await part.reload();
assert(part.customBarcode.isEmpty);
});
});
}
}

View File

@ -10,7 +10,6 @@ import "package:inventree/inventree/part.dart";
import "setup.dart";
void main() {
setupTestEnv();
@ -35,18 +34,15 @@ void main() {
}
// Filter by parent category
results = await InvenTreePartCategory().list(
filters: {
"parent": "1",
}
);
results = await InvenTreePartCategory().list(filters: {
"parent": "1",
});
assert(results.length == 3);
});
});
group("Part Tests:", () {
test("Basics", () async {
assert(InvenTreePart().URL == "part/");
});
@ -68,11 +64,9 @@ void main() {
}
// Filter by category
results = await InvenTreePart().list(
filters: {
"category": "2",
}
);
results = await InvenTreePart().list(filters: {
"category": "2",
});
assert(results.length == 2);
});
@ -99,7 +93,6 @@ void main() {
assert(part.unallocatedStockString == "9000");
assert(part.inStockString == "9000");
}
});
test("Part Adjust", () async {
@ -117,11 +110,9 @@ void main() {
// Change the name to something else
response = await part.update(
values: {
"name": "Woogle",
}
);
response = await part.update(values: {
"name": "Woogle",
});
assert(response.isValid());
assert(response.statusCode == 200);
@ -130,11 +121,7 @@ void main() {
assert(part.name == "Woogle");
// And change it back again
response = await part.update(
values: {
"name": "M2x4 LPHS"
}
);
response = await part.update(values: {"name": "M2x4 LPHS"});
assert(response.isValid());
assert(response.statusCode == 200);
@ -144,5 +131,4 @@ void main() {
}
});
});
}
}

View File

@ -10,23 +10,26 @@ import "setup.dart";
void main() {
setupTestEnv();
setUp(() async {
});
setUp(() async {});
group("Settings Tests:", () {
test("Default Values", () async {
// Boolean values
expect(await InvenTreeSettingsManager().getBool("test", false), equals(false));
expect(await InvenTreeSettingsManager().getBool("test", true), equals(true));
expect(await InvenTreeSettingsManager().getBool("test", false),
equals(false));
expect(
await InvenTreeSettingsManager().getBool("test", true), equals(true));
// String values
expect(await InvenTreeSettingsManager().getValue("test", "x"), equals("x"));
expect(
await InvenTreeSettingsManager().getValue("test", "x"), equals("x"));
});
test("Set value", () async {
await InvenTreeSettingsManager().setValue("abc", "xyz");
expect(await InvenTreeSettingsManager().getValue("abc", "123"), equals("xyz"));
expect(await InvenTreeSettingsManager().getValue("abc", "123"),
equals("xyz"));
});
test("Booleans", () async {
@ -36,16 +39,18 @@ void main() {
// Use default values when a setting does not exist
assert(await InvenTreeSettingsManager().getBool("chicken", true) == true);
assert(await InvenTreeSettingsManager().getBool("chicken", false) == false);
assert(
await InvenTreeSettingsManager().getBool("chicken", false) == false);
// Explicitly set to true
await InvenTreeSettingsManager().setValue("chicken", true);
assert(await InvenTreeSettingsManager().getBool("chicken", false) == true);
assert(
await InvenTreeSettingsManager().getBool("chicken", false) == true);
// Explicitly set to false
await InvenTreeSettingsManager().setValue("chicken", false);
assert(await InvenTreeSettingsManager().getBool("chicken", true) == false);
assert(
await InvenTreeSettingsManager().getBool("chicken", true) == false);
});
});
}
}

View File

@ -1,4 +1,3 @@
import "package:flutter/services.dart";
import "package:flutter_test/flutter_test.dart";
import "package:inventree/api.dart";
@ -16,7 +15,8 @@ void setupTestEnv() {
CustomBinding();
// Mock the path provider
const MethodChannel channel = MethodChannel("plugins.flutter.io/path_provider");
const MethodChannel channel =
MethodChannel("plugins.flutter.io/path_provider");
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
return ".";
@ -29,41 +29,36 @@ const String testServerName = "Test Server";
const String testUsername = "testuser";
const String testPassword = "testpassword";
/*
* Request an API token for the given profile
*/
Future<bool> fetchProfileToken({
UserProfile? profile,
String username = testUsername,
String password = testPassword
}) async {
Future<bool> fetchProfileToken(
{UserProfile? profile,
String username = testUsername,
String password = testPassword}) async {
profile ??= await UserProfileDBManager().getProfileByName(testServerName);
assert(profile != null);
final response = await InvenTreeAPI().fetchToken(profile!, username, password);
final response =
await InvenTreeAPI().fetchToken(profile!, username, password);
return response.successful();
}
/*
* Setup a valid profile, and return it
*/
Future<UserProfile> setupServerProfile({bool select = true, bool fetchToken = false}) async {
Future<UserProfile> setupServerProfile(
{bool select = true, bool fetchToken = false}) async {
// Setup a valid server profile
UserProfile? profile = await UserProfileDBManager().getProfileByName(testServerName);
UserProfile? profile =
await UserProfileDBManager().getProfileByName(testServerName);
if (profile == null) {
// Profile does not already exist - create it!
bool result = await UserProfileDBManager().addProfile(
UserProfile(
server: testServerAddress,
name: testServerName
)
);
UserProfile(server: testServerAddress, name: testServerName));
assert(result);
}
@ -84,15 +79,13 @@ Future<UserProfile> setupServerProfile({bool select = true, bool fetchToken = fa
return profile!;
}
/*
* Complete all steps necessary to login to the server
*/
Future<void> connectToTestServer() async {
// Setup profile, and fetch user token as necessary
final profile = await setupServerProfile(fetchToken: true);
// Connect to the server
assert(await InvenTreeAPI().connectToServer(profile));
}
}

View File

@ -56,21 +56,16 @@ void main() {
// Run a set of tests for user profile functionality
group("Profile Tests:", () {
test("Add Invalid Profiles", () async {
// Add a profile with missing data
bool result = await UserProfileDBManager().addProfile(
UserProfile()
);
bool result = await UserProfileDBManager().addProfile(UserProfile());
expect(result, equals(false));
// Add a profile with a new name
result = await UserProfileDBManager().addProfile(
UserProfile(
name: "Another Test Profile",
)
);
result = await UserProfileDBManager().addProfile(UserProfile(
name: "Another Test Profile",
));
expect(result, equals(true));
@ -81,7 +76,8 @@ void main() {
});
test("Profile Name Check", () async {
bool result = await UserProfileDBManager().profileNameExists("doesnotexist");
bool result =
await UserProfileDBManager().profileNameExists("doesnotexist");
expect(result, equals(false));
result = await UserProfileDBManager().profileNameExists("Test Server");
@ -100,7 +96,8 @@ void main() {
expect(p.name, equals(testServerName));
expect(p.server, equals(testServerAddress));
expect(p.toString(), equals("<${p.key}> Test Server : http://localhost:8000/"));
expect(p.toString(),
equals("<${p.key}> Test Server : http://localhost:8000/"));
// Test that we can update the profile
p.name = "different name";
@ -110,5 +107,4 @@ void main() {
}
});
});
}
}

View File

@ -1,5 +1,3 @@
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:flutter_test/flutter_test.dart";
@ -7,15 +5,10 @@ import "package:inventree/barcode/barcode.dart";
import "package:inventree/barcode/wedge_controller.dart";
import "package:inventree/helpers.dart";
void main() {
testWidgets("Wedge Scanner Test", (tester) async {
await tester.pumpWidget(
MaterialApp(
home: WedgeBarcodeController(BarcodeScanHandler())
)
);
MaterialApp(home: WedgeBarcodeController(BarcodeScanHandler())));
// Generate some keyboard data
await simulateKeyDownEvent(LogicalKeyboardKey.keyA);
@ -27,6 +20,5 @@ void main() {
debugContains("scanned: abc");
debugContains("No match for barcode");
debugContains("Server Error");
});
}
}