+
diff --git a/src/modules/user/settings/settings.ts b/src/modules/user/settings/settings.ts
index 00de4854..0b6c2eba 100644
--- a/src/modules/user/settings/settings.ts
+++ b/src/modules/user/settings/settings.ts
@@ -13,6 +13,7 @@ export class Settings {
@observable public selectedTheme: string;
@observable public selectedLanguage: string;
@observable public selectedMessuarementSystem: MessuarementSystem;
+ @observable public preferCl: boolean;
@observable public showMocktails: boolean;
public themes = [
@@ -73,6 +74,7 @@ export class Settings {
public attached() {
this.selectedTheme = this._themeService.getLocalStorageResult();
this.selectedMessuarementSystem = this._localStorageService.getMessuarementSystem();
+ this.preferCl = this._localStorageService.getPreferCl();
this._settings = this._localStorageService.getSettings();
this.selectedLanguage = this._settings.language;
this.showMocktails = this._settings.showMocktails;
@@ -93,6 +95,14 @@ export class Settings {
await this._localStorageService.updateMessuarmentSystem(newValue);
}
+ async preferClChanged(newValue: boolean, oldValue: boolean) {
+ if (oldValue === undefined) {
+ return;
+ }
+
+ await this._localStorageService.updatePreferCL(newValue);
+ }
+
async showMocktailsChanged(newValue: boolean, oldValue: boolean) {
if (oldValue === undefined) {
return;
diff --git a/src/services/local-storage-service.ts b/src/services/local-storage-service.ts
index 5574673e..5a7867a9 100644
--- a/src/services/local-storage-service.ts
+++ b/src/services/local-storage-service.ts
@@ -215,6 +215,10 @@ export class LocalStorageService {
return this._activeIngredientListId;
}
+ public getPreferCl() {
+ return this._settings.preferCl ?? false;
+ }
+
public getIngredientList() {
return this._ingredientLists.find(x => x.id === this._activeIngredientListId);
}
@@ -254,6 +258,11 @@ export class LocalStorageService {
this._activeIngredientListId = id;
}
+ public async updatePreferCL(preferCl: boolean) {
+ this._settings.preferCl = preferCl;
+ await this.updateSettings(this._settings);
+ }
+
public async keyExists(key: string): Promise {
const { keys } = await Preferences.keys();
if (keys.length > 0 && keys.includes(key)) {
diff --git a/tests/converters/amount-format.test.ts b/tests/converters/amount-format.test.ts
new file mode 100644
index 00000000..625ebe0d
--- /dev/null
+++ b/tests/converters/amount-format.test.ts
@@ -0,0 +1,88 @@
+import { LocalStorageService } from 'services/local-storage-service';
+import { expect } from '@jest/globals';
+import { AmountFormatValueConverter } from '../../src/converters/amount-format';
+import { Unit } from 'domain/enums/unit';
+import { MessuarementSystem } from 'domain/enums/messuarement-system';
+
+describe('IngredientService', () => {
+ let localStorageService: LocalStorageService;
+ let sut: AmountFormatValueConverter;
+
+ beforeEach(async () => {
+ localStorageService = new LocalStorageService();
+ await localStorageService.initialize();
+
+ sut = new AmountFormatValueConverter(localStorageService);
+ });
+
+ afterEach(() => {
+ window.localStorage.clear();
+ });
+
+ describe('Metric', () => {
+ beforeEach(async () => {
+ await localStorageService.updateMessuarmentSystem(MessuarementSystem.Metric);
+ });
+
+ test('Pass Milliliter - Should return same as input', () => {
+ const result = sut.toView('10', 1, Unit.ML, false);
+
+ expect(result).toEqual('10 ml');
+ });
+
+ test('Pass Milliliter and multiplyer - Should return multiplied value', () => {
+ const result = sut.toView('10', 3, Unit.ML, false);
+
+ expect(result).toEqual('30 ml');
+ });
+
+ test('Pass Milliliter with preferCl - Should return value in Cl', () => {
+ const result = sut.toView('10', 1, Unit.ML, true);
+
+ expect(result).toEqual('1 cl');
+ });
+
+ test('Pass Milliliter with preferCl - Should handle fraction', () => {
+ const result = sut.toView('5', 1, Unit.ML, true);
+
+ expect(result).toEqual('1/2 cl');
+ });
+
+ test('Pass Milliliter and multiplyer with preferCl - Should return multiplied value but in Cl', () => {
+ const result = sut.toView('10', 3, Unit.ML, true);
+
+ expect(result).toEqual('3 cl');
+ });
+ });
+
+ describe('Imperial', () => {
+ test('Pass Milliliter - Should return in fl oz', () => {
+ const result = sut.toView('30', 1, Unit.ML, false);
+
+ expect(result).toEqual('1 fl oz');
+ });
+
+ test('Pass Milliliter with preferCl- Should return same as above', () => {
+ const result = sut.toView('30', 1, Unit.ML, true);
+
+ expect(result).toEqual('1 fl oz');
+ });
+
+ test('Pass Milliliter and multiplyer - Should return multiplied value', () => {
+ const result = sut.toView('30', 3, Unit.ML, false);
+
+ expect(result).toEqual('3 fl oz');
+ });
+
+ test('Pass Milliliter with preferCl - Should return value in Cl', () => {
+ const result = sut.toView('15', 1, Unit.ML, false);
+
+ expect(result).toEqual('1/2 fl oz');
+ });
+
+ test('should return empty string when value is empty', () => {
+ const result = sut.toView('', 1, Unit.ML, false);
+ expect(result).toEqual('');
+ });
+ });
+});