mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 02:07:00 +08:00
Replaces direct comparison of defaultAIModel with mapEquals to ensure deep equality. Updates related tests to include defaultAIModel in test cases for serialization, deserialization, copyWith, and toString.
123 lines
3.3 KiB
Dart
123 lines
3.3 KiB
Dart
import 'package:apidash_core/apidash_core.dart';
|
|
import 'package:test/test.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:apidash/models/settings_model.dart';
|
|
import 'package:apidash/consts.dart';
|
|
|
|
void main() {
|
|
const sm = SettingsModel(
|
|
isDark: false,
|
|
alwaysShowCollectionPaneScrollbar: true,
|
|
size: Size(300, 200),
|
|
offset: Offset(100, 150),
|
|
defaultUriScheme: SupportedUriSchemes.http,
|
|
defaultCodeGenLang: CodegenLanguage.curl,
|
|
saveResponses: true,
|
|
promptBeforeClosing: true,
|
|
activeEnvironmentId: null,
|
|
historyRetentionPeriod: HistoryRetentionPeriod.oneWeek,
|
|
workspaceFolderPath: null,
|
|
isSSLDisabled: true,
|
|
isDashBotEnabled: true,
|
|
defaultAIModel: {"model": "llama"},
|
|
);
|
|
|
|
test('Testing toJson()', () {
|
|
const expectedResult = {
|
|
"isDark": false,
|
|
"alwaysShowCollectionPaneScrollbar": true,
|
|
"width": 300.0,
|
|
"height": 200.0,
|
|
"dx": 100.0,
|
|
"dy": 150.0,
|
|
"defaultUriScheme": "http",
|
|
"defaultCodeGenLang": "curl",
|
|
"saveResponses": true,
|
|
"promptBeforeClosing": true,
|
|
"activeEnvironmentId": null,
|
|
"historyRetentionPeriod": "oneWeek",
|
|
"workspaceFolderPath": null,
|
|
"isSSLDisabled": true,
|
|
"isDashBotEnabled": true,
|
|
"defaultAIModel": {"model": "llama"}
|
|
};
|
|
expect(sm.toJson(), expectedResult);
|
|
});
|
|
|
|
test('Testing fromJson()', () {
|
|
const input = {
|
|
"isDark": false,
|
|
"alwaysShowCollectionPaneScrollbar": true,
|
|
"width": 300.0,
|
|
"height": 200.0,
|
|
"dx": 100.0,
|
|
"dy": 150.0,
|
|
"defaultUriScheme": "http",
|
|
"defaultCodeGenLang": "curl",
|
|
"saveResponses": true,
|
|
"promptBeforeClosing": true,
|
|
"activeEnvironmentId": null,
|
|
"historyRetentionPeriod": "oneWeek",
|
|
"workspaceFolderPath": null,
|
|
"isSSLDisabled": true,
|
|
"isDashBotEnabled": true,
|
|
"defaultAIModel": {"model": "llama"}
|
|
};
|
|
expect(SettingsModel.fromJson(input), sm);
|
|
});
|
|
|
|
test('Testing copyWith()', () {
|
|
const expectedResult = SettingsModel(
|
|
isDark: true,
|
|
alwaysShowCollectionPaneScrollbar: true,
|
|
size: Size(300, 200),
|
|
offset: Offset(100, 150),
|
|
defaultUriScheme: SupportedUriSchemes.http,
|
|
defaultCodeGenLang: CodegenLanguage.curl,
|
|
saveResponses: false,
|
|
promptBeforeClosing: true,
|
|
activeEnvironmentId: null,
|
|
historyRetentionPeriod: HistoryRetentionPeriod.oneWeek,
|
|
isSSLDisabled: false,
|
|
isDashBotEnabled: false,
|
|
defaultAIModel: {"model": "llama"},
|
|
);
|
|
expect(
|
|
sm.copyWith(
|
|
isDark: true,
|
|
saveResponses: false,
|
|
isSSLDisabled: false,
|
|
isDashBotEnabled: false,
|
|
),
|
|
expectedResult);
|
|
});
|
|
|
|
test('Testing toString()', () {
|
|
const expectedResult = '''{
|
|
"isDark": false,
|
|
"alwaysShowCollectionPaneScrollbar": true,
|
|
"width": 300.0,
|
|
"height": 200.0,
|
|
"dx": 100.0,
|
|
"dy": 150.0,
|
|
"defaultUriScheme": "http",
|
|
"defaultCodeGenLang": "curl",
|
|
"saveResponses": true,
|
|
"promptBeforeClosing": true,
|
|
"activeEnvironmentId": null,
|
|
"historyRetentionPeriod": "oneWeek",
|
|
"workspaceFolderPath": null,
|
|
"isSSLDisabled": true,
|
|
"isDashBotEnabled": true,
|
|
"defaultAIModel": {
|
|
"model": "llama"
|
|
}
|
|
}''';
|
|
expect(sm.toString(), expectedResult);
|
|
});
|
|
|
|
test('Testing hashcode', () {
|
|
expect(sm.hashCode, greaterThan(0));
|
|
});
|
|
}
|