Files
apidash/test/models/settings_model_test.dart
Ankit Mahato 8810dc3a35 Fix SettingsModel equality for defaultAIModel map
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.
2025-08-31 20:13:45 +05:30

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));
});
}