Skip to content

Commit

Permalink
fix: enable localized number inputs for budgets
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrueber committed Apr 18, 2024
1 parent ddf650f commit a67cf06
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { instance, mock } from 'ts-mockito';
import { of } from 'rxjs';
import { anything, instance, mock, when } from 'ts-mockito';

import { AppFacade } from 'ish-core/facades/app.facade';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';
import { CostCenterBuyer } from 'ish-core/models/cost-center/cost-center.model';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';

Expand All @@ -20,6 +21,8 @@ describe('Cost Center Buyer Edit Dialog Component', () => {

beforeEach(async () => {
appFacade = mock(AppFacade);
when(appFacade.currencySymbol$(anything())).thenReturn(of('$'));

organizationManagementFacade = mock(organizationManagementFacade);

await TestBed.configureTestingModule({
Expand All @@ -41,11 +44,15 @@ describe('Cost Center Buyer Edit Dialog Component', () => {
login: ['jlink@test.intershop.de'],
firstName: ['Jack'],
lastName: ['Link'],
budgetValue: [123, [SpecialValidators.moneyAmount]],
budgetValue: [123],
budgetPeriod: ['monthly'],
});

component.costCenterBuyerForm = form;
component.show({
login: 'jlink@test.intershop.de',
budget: { currency: 'USD', value: 10000 },
} as CostCenterBuyer);
});

it('should be created', () => {
Expand All @@ -54,19 +61,6 @@ describe('Cost Center Buyer Edit Dialog Component', () => {
expect(() => fixture.detectChanges()).not.toThrow();
});

it('should not submit a form when the user does not provide money format for budget', () => {
component.costCenterBuyerForm = fb.group({
budgetValue: ['abc', [SpecialValidators.moneyAmount]],
});

fixture.detectChanges();

expect(component.formDisabled).toBeFalse();
component.submitCostCenterBuyerForm();

expect(component.formDisabled).toBeTrue();
});

it('should display all form input fields for cost center buyer update', () => {
fixture.detectChanges();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { CostCenterBuyer } from 'ish-core/models/cost-center/cost-center.model';
import { PriceHelper } from 'ish-core/models/price/price.helper';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { FormsService } from 'ish-shared/forms/utils/forms.service';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';

Expand Down Expand Up @@ -65,16 +64,9 @@ export class CostCenterBuyerEditDialogComponent implements OnInit {
fieldClass: 'col-md-8 pr-0',
label: 'account.costcenter.details.buyers.dialog.editbudget.budget.label',
addonLeft: {
text: this.appFacade.currencySymbol$(this.buyer?.budget.currency),
},
},
validators: {
validation: [SpecialValidators.moneyAmount],
},
validation: {
messages: {
moneyAmount: 'account.costcenter.budget.error.valid',
text: this.appFacade.currencySymbol$(this.buyer?.budget?.currency),
},
mask: 'separator.2',
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,10 @@ export class CostCenterFormComponent implements OnInit {
addonLeft: {
text: this.appFacade.currencySymbol$(currentCurrency),
},
},
validators: {
validation: [SpecialValidators.moneyAmount],
mask: 'separator.2',
},
validation: {
messages: {
moneyAmount: 'account.costcenter.budget.error.valid',
required: 'account.costcenter.budget.error.required',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { FormlyFieldConfig } from '@ngx-formly/core';

import { AppFacade } from 'ish-core/facades/app.facade';
import { whenTruthy } from 'ish-core/utils/operators';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

import { UserBudget } from '../../models/user-budget/user-budget.model';

Expand Down Expand Up @@ -88,14 +87,7 @@ export class UserBudgetFormComponent implements OnInit {
addonLeft: {
text: this.appFacade.currencySymbol$(this.model.currency),
},
},
validators: {
validation: [SpecialValidators.moneyAmount],
},
validation: {
messages: {
moneyAmount: 'account.user.new.OrderLimit.error.valid',
},
mask: 'separator.2',
},
},
{
Expand All @@ -114,14 +106,7 @@ export class UserBudgetFormComponent implements OnInit {
addonLeft: {
text: this.appFacade.currencySymbol$(this.model.currency),
},
},
validators: {
validation: [SpecialValidators.moneyAmount],
},
validation: {
messages: {
moneyAmount: 'account.user.new.Budget.error.valid',
},
mask: 'separator.2',
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { PriceHelper } from 'ish-core/models/price/price.model';
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils';
import { FormsService } from 'ish-shared/forms/utils/forms.service';
import { SpecialValidators } from 'ish-shared/forms/validators/special-validators';

import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';
Expand Down Expand Up @@ -127,16 +126,9 @@ export class CostCenterBuyersPageComponent implements OnInit {
addonLeft: {
text: this.appFacade.currencySymbol$(),
},
mask: 'separator.2',
ariaLabel: 'Buyer budget',
},
validators: {
validation: [SpecialValidators.moneyAmount],
},
validation: {
messages: {
moneyAmount: 'account.costcenter.budget.error.valid',
},
},
},
{
key: 'budgetPeriod',
Expand Down
3 changes: 0 additions & 3 deletions src/assets/i18n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"account.costCenter.status.inactive": "(Inaktiv)",
"account.costcenter.activate.button.title": "Aktivieren",
"account.costcenter.budget.error.required": "Geben Sie einen Geldbetrag ein (Budget).",
"account.costcenter.budget.error.valid": "Geben Sie einen gültigen Geldbetrag ein (Budget).",
"account.costcenter.budget.label": "Budget",
"account.costcenter.budget.period.value.fixed": "vordefiniert",
"account.costcenter.budget.period.value.half-yearly": "halbjährlich",
Expand Down Expand Up @@ -493,8 +492,6 @@
"account.user.list.status.inactive": "(Inaktiv)",
"account.user.login.error.required": "Bitte geben Sie einen Benutzernamen an.",
"account.user.login.invalid.error": "Bitte geben Sie einen gültigen Benutzernamen an.",
"account.user.new.Budget.error.valid": "Geben Sie einen gültigen Geldbetrag ein (Budget).",
"account.user.new.OrderLimit.error.valid": "Geben Sie einen gültigen Geldbetrag ein (Limit pro Bestellung).",
"account.user.new.budget.period.value.half-yearly": "halbjährlich",
"account.user.new.budget.period.value.monthly": "monatlich",
"account.user.new.budget.period.value.quarterly": "quartalsweise",
Expand Down
3 changes: 0 additions & 3 deletions src/assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"account.costCenter.status.inactive": "(Inactive)",
"account.costcenter.activate.button.title": "Activate",
"account.costcenter.budget.error.required": "Please enter an amount of money (Budget).",
"account.costcenter.budget.error.valid": "Please enter a valid amount of money (Budget).",
"account.costcenter.budget.label": "Budget",
"account.costcenter.budget.period.value.fixed": "fixed",
"account.costcenter.budget.period.value.half-yearly": "half-yearly",
Expand Down Expand Up @@ -493,8 +492,6 @@
"account.user.list.status.inactive": "(Inactive)",
"account.user.login.error.required": "Please enter a username.",
"account.user.login.invalid.error": "Please enter a valid username.",
"account.user.new.Budget.error.valid": "Please enter a valid amount of money (Budget).",
"account.user.new.OrderLimit.error.valid": "Please enter a valid amount of money (limit per order).",
"account.user.new.budget.period.value.half-yearly": "half-yearly",
"account.user.new.budget.period.value.monthly": "monthly",
"account.user.new.budget.period.value.quarterly": "quarterly",
Expand Down
3 changes: 0 additions & 3 deletions src/assets/i18n/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"account.costCenter.status.inactive": "(Inactif)",
"account.costcenter.activate.button.title": "Activer",
"account.costcenter.budget.error.required": "Veuillez saisir une valeur monétaire (budget).",
"account.costcenter.budget.error.valid": "Veuillez saisir une valeur monétaire valide (budget).",
"account.costcenter.budget.label": "Budget",
"account.costcenter.budget.period.value.fixed": "fixe",
"account.costcenter.budget.period.value.half-yearly": "semestriel",
Expand Down Expand Up @@ -493,8 +492,6 @@
"account.user.list.status.inactive": "(Inactif)",
"account.user.login.error.required": "Veuillez saisir un nom d’utilisateur",
"account.user.login.invalid.error": "Veuillez saisir un nom d’utilisateur valide",
"account.user.new.Budget.error.valid": "Veuillez saisir une valeur monétaire valide (budget).",
"account.user.new.OrderLimit.error.valid": "Veuillez saisir une valeur monétaire valide (limite par commande).",
"account.user.new.budget.period.value.half-yearly": "semestriel",
"account.user.new.budget.period.value.monthly": "mensuel",
"account.user.new.budget.period.value.quarterly": "trimestriel",
Expand Down

0 comments on commit a67cf06

Please sign in to comment.