Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: autocoded msg and error msg align fix and separate autocoded msg #3418

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/fyle/add-edit-expense/add-edit-expense.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@
}

&--orig-amount-error {
margin: -68px 4px 48px 33%;
margin: -73px 4px 48px 53%;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why -ve value?

}

&--mandatory {
Expand Down
46 changes: 27 additions & 19 deletions src/app/shared/components/fy-currency/fy-currency.component.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
<div class="fy-currency">
<form [formGroup]="fg" class="fy-currency--form">
<div class="fy-currency--input-container fy-currency--currency-block">
<div class="fy-currency--label">
Currency
<span class="fy-currency--mandatory"> * </span>
<div class="fy-currency--input-wrapper fy-currency--currency-block">
<div class="fy-currency--input-container">
<div class="fy-currency--label">
Currency
<span class="fy-currency--mandatory"> * </span>
</div>
<input
class="fy-currency--input smartlook-show"
(click)="openCurrencyModal()"
formControlName="currency"
(blur)="onBlur()"
/>
</div>
<div class="fy-currency__auto-coded" *ngIf="currencyAutoCodeMessage">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ngIF at the beginning, improves readability. Fix everywhere

<mat-icon class="fy-currency__sparkle-icon" svgIcon="sparkle"></mat-icon>
{{ currencyAutoCodeMessage }}
</div>
<input
class="fy-currency--input smartlook-show"
(click)="openCurrencyModal()"
formControlName="currency"
(blur)="onBlur()"
/>
</div>
<div class="fy-currency--input-container fy-currency--amount-block" [ngClass]="{ 'fy-currency__invalid': !valid }">
<div class="fy-currency--label">
Amount
<span class="fy-currency--mandatory"> * </span>
<div class="fy-currency--input-wrapper fy-currency--amount-block">
<div class="fy-currency--input-container" [ngClass]="{ 'fy-currency__invalid': !valid }">
<div class="fy-currency--label">
Amount
<span class="fy-currency--mandatory"> * </span>
</div>
<app-fy-number placeholder="00.00" formControlName="amount" [isAmount]="true"> </app-fy-number>
</div>
<div class="fy-currency__auto-coded" *ngIf="amountAutoCodeMessage">
<mat-icon class="fy-currency__sparkle-icon" svgIcon="sparkle"></mat-icon>
{{ amountAutoCodeMessage }}
</div>
Comment on lines +3 to 32
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

This HTML structure is like a well-choreographed fight scene!

The restructuring improves both visual organization and semantic meaning. But let's make it even more powerful!

Add ARIA labels for better screen reader support:

-        <input
+        <input
+          aria-label="Currency input"
           class="fy-currency--input smartlook-show"
           (click)="openCurrencyModal()"
           formControlName="currency"
           (blur)="onBlur()"
         />
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div class="fy-currency--input-wrapper fy-currency--currency-block">
<div class="fy-currency--input-container">
<div class="fy-currency--label">
Currency
<span class="fy-currency--mandatory"> * </span>
</div>
<input
class="fy-currency--input smartlook-show"
(click)="openCurrencyModal()"
formControlName="currency"
(blur)="onBlur()"
/>
</div>
<div class="fy-currency__auto-coded" *ngIf="currencyAutoCodeMessage">
<mat-icon class="fy-currency__sparkle-icon" svgIcon="sparkle"></mat-icon>
{{ currencyAutoCodeMessage }}
</div>
<input
class="fy-currency--input smartlook-show"
(click)="openCurrencyModal()"
formControlName="currency"
(blur)="onBlur()"
/>
</div>
<div class="fy-currency--input-container fy-currency--amount-block" [ngClass]="{ 'fy-currency__invalid': !valid }">
<div class="fy-currency--label">
Amount
<span class="fy-currency--mandatory"> * </span>
<div class="fy-currency--input-wrapper fy-currency--amount-block">
<div class="fy-currency--input-container" [ngClass]="{ 'fy-currency__invalid': !valid }">
<div class="fy-currency--label">
Amount
<span class="fy-currency--mandatory"> * </span>
</div>
<app-fy-number placeholder="00.00" formControlName="amount" [isAmount]="true"> </app-fy-number>
</div>
<div class="fy-currency__auto-coded" *ngIf="amountAutoCodeMessage">
<mat-icon class="fy-currency__sparkle-icon" svgIcon="sparkle"></mat-icon>
{{ amountAutoCodeMessage }}
</div>
<div class="fy-currency--input-wrapper fy-currency--currency-block">
<div class="fy-currency--input-container">
<div class="fy-currency--label">
Currency
<span class="fy-currency--mandatory"> * </span>
</div>
<input
aria-label="Currency input"
class="fy-currency--input smartlook-show"
(click)="openCurrencyModal()"
formControlName="currency"
(blur)="onBlur()"
/>
</div>
<div class="fy-currency__auto-coded" *ngIf="currencyAutoCodeMessage">
<mat-icon class="fy-currency__sparkle-icon" svgIcon="sparkle"></mat-icon>
{{ currencyAutoCodeMessage }}
</div>
</div>
<div class="fy-currency--input-wrapper fy-currency--amount-block">
<div class="fy-currency--input-container" [ngClass]="{ 'fy-currency__invalid': !valid }">
<div class="fy-currency--label">
Amount
<span class="fy-currency--mandatory"> * </span>
</div>
<app-fy-number placeholder="00.00" formControlName="amount" [isAmount]="true"> </app-fy-number>
</div>
<div class="fy-currency__auto-coded" *ngIf="amountAutoCodeMessage">
<mat-icon class="fy-currency__sparkle-icon" svgIcon="sparkle"></mat-icon>
{{ amountAutoCodeMessage }}
</div>

<app-fy-number placeholder="00.00" formControlName="amount" [isAmount]="true"> </app-fy-number>
</div>
</form>
</div>
<div class="fy-currency__auto-coded" *ngIf="autoCodeMessage">
<mat-icon class="fy-currency__sparkle-icon" svgIcon="sparkle"></mat-icon>
{{ autoCodeMessage }}
</div>
<ng-container *ngIf="value?.currency && value?.orig_currency">
<div class="fy-currency--exchange-rate-container" [ngClass]="{ expanded: expanded }">
<mat-icon class="fy-currency--exchange-rate-icon" svgIcon="info-circle-fill"></mat-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

&--form {
display: flex;
align-items: center;
align-items: flex-start;
height: 70px;
}

Expand All @@ -51,19 +51,20 @@

&--currency-block {
margin-right: 8px;
width: 30%;
width: 50%;
}

&--amount-block {
margin-left: 8px;
width: 70%;
width: 50%;
}

&__auto-coded {
display: flex;
align-items: center;
height: 12px;
font-size: 12px;
margin-top: 5px;
color: $black-light;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,47 +481,49 @@ describe('FyCurrencyComponent', () => {
expect(component.valid).toBeTrue();
});

it('should set autoCodeMessage to "Currency and Amount are auto coded." when both are auto coded', () => {
it('should set currencyAutoCodeMessage to "Currency is auto coded." and amountAutoCodeMessage to "Amount is auto coded." when both are auto coded', () => {
component.autoCodedData = { currency: 'USD', amount: 100 };
component.fg = new FormGroup({
currency: new FormControl('USD'),
amount: new FormControl(100),
homeCurrencyAmount: new FormControl(null),
});
component.showAutoCodeMessage();
expect(component.autoCodeMessage).toBe('Currency and Amount are auto coded.');
expect(component.currencyAutoCodeMessage).toBe('Currency is auto coded.');
expect(component.amountAutoCodeMessage).toBe('Amount is auto coded.');
Comment on lines +484 to +493
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Mind-blowing test coverage, macha! But let's make it even more powerful!

The test case for both auto-coded fields is solid, but we can enhance it further by verifying the initial state before calling showAutoCodeMessage().

 it('should set currencyAutoCodeMessage to "Currency is auto coded." and amountAutoCodeMessage to "Amount is auto coded." when both are auto coded', () => {
   component.autoCodedData = { currency: 'USD', amount: 100 };
   component.fg = new FormGroup({
     currency: new FormControl('USD'),
     amount: new FormControl(100),
     homeCurrencyAmount: new FormControl(null),
   });
+  expect(component.currencyAutoCodeMessage).toBe('');
+  expect(component.amountAutoCodeMessage).toBe('');
   component.showAutoCodeMessage();
   expect(component.currencyAutoCodeMessage).toBe('Currency is auto coded.');
   expect(component.amountAutoCodeMessage).toBe('Amount is auto coded.');
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('should set currencyAutoCodeMessage to "Currency is auto coded." and amountAutoCodeMessage to "Amount is auto coded." when both are auto coded', () => {
component.autoCodedData = { currency: 'USD', amount: 100 };
component.fg = new FormGroup({
currency: new FormControl('USD'),
amount: new FormControl(100),
homeCurrencyAmount: new FormControl(null),
});
component.showAutoCodeMessage();
expect(component.autoCodeMessage).toBe('Currency and Amount are auto coded.');
expect(component.currencyAutoCodeMessage).toBe('Currency is auto coded.');
expect(component.amountAutoCodeMessage).toBe('Amount is auto coded.');
it('should set currencyAutoCodeMessage to "Currency is auto coded." and amountAutoCodeMessage to "Amount is auto coded." when both are auto coded', () => {
component.autoCodedData = { currency: 'USD', amount: 100 };
component.fg = new FormGroup({
currency: new FormControl('USD'),
amount: new FormControl(100),
homeCurrencyAmount: new FormControl(null),
});
expect(component.currencyAutoCodeMessage).toBe('');
expect(component.amountAutoCodeMessage).toBe('');
component.showAutoCodeMessage();
expect(component.currencyAutoCodeMessage).toBe('Currency is auto coded.');
expect(component.amountAutoCodeMessage).toBe('Amount is auto coded.');
});

});

it('should set autoCodeMessage to "Currency is auto coded." when only currency is auto coded', () => {
it('should set currencyAutoCodeMessage to "Currency is auto coded." when only currency is auto coded', () => {
component.autoCodedData = { currency: 'USD', amount: 100 };
component.fg = new FormGroup({
currency: new FormControl('USD'),
amount: new FormControl(200),
homeCurrencyAmount: new FormControl(null),
});
component.showAutoCodeMessage();
expect(component.autoCodeMessage).toBe('Currency is auto coded.');
expect(component.currencyAutoCodeMessage).toBe('Currency is auto coded.');
Comment on lines +496 to +504
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

These test cases are like my signature moves - precise and powerful! But let's add some style, thalaiva!

The test cases cover all scenarios perfectly, but we can make them more maintainable by extracting the message strings into constants.

Add these constants at the top of the describe block:

 describe('FyCurrencyComponent', () => {
+  const AUTO_CODED_MESSAGES = {
+    CURRENCY: 'Currency is auto coded.',
+    AMOUNT: 'Amount is auto coded.',
+    EMPTY: ''
+  };
   let component: FyCurrencyComponent;
   // ... rest of the code

Then update the test cases to use these constants:

-    expect(component.currencyAutoCodeMessage).toBe('Currency is auto coded.');
+    expect(component.currencyAutoCodeMessage).toBe(AUTO_CODED_MESSAGES.CURRENCY);

Also applies to: 507-515, 518-527

});

it('should set autoCodeMessage to "Amount is auto coded." when only amount is auto coded', () => {
it('should set amountAutoCodeMessage to "Amount is auto coded." when only amount is auto coded', () => {
component.autoCodedData = { currency: 'USD', amount: 100 };
component.fg = new FormGroup({
currency: new FormControl('EUR'),
amount: new FormControl(100),
homeCurrencyAmount: new FormControl(null),
});
component.showAutoCodeMessage();
expect(component.autoCodeMessage).toBe('Amount is auto coded.');
expect(component.amountAutoCodeMessage).toBe('Amount is auto coded.');
});

it('should set autoCodeMessage to "" when neither currency nor amount is auto coded', () => {
it('should set currencyAutoCodeMessage and amountAutoCodeMessage to "" when neither currency nor amount is auto coded', () => {
component.autoCodedData = { currency: 'USD', amount: 100 };
component.fg = new FormGroup({
currency: new FormControl('EUR'),
amount: new FormControl(200),
homeCurrencyAmount: new FormControl(null),
});
component.showAutoCodeMessage();
expect(component.autoCodeMessage).toBe('');
expect(component.currencyAutoCodeMessage).toBe('');
expect(component.amountAutoCodeMessage).toBe('');
Comment on lines +484 to +527
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Listen up, all you test warriors! Here's a power-packed suggestion!

We should add one more test case to verify the component's behavior when autoCodedData is null or undefined, as this is a common edge case in real-world scenarios.

Add this test case:

it('should handle null autoCodedData gracefully', () => {
  component.autoCodedData = null;
  component.fg = new FormGroup({
    currency: new FormControl('USD'),
    amount: new FormControl(100),
    homeCurrencyAmount: new FormControl(null),
  });
  component.showAutoCodeMessage();
  expect(component.currencyAutoCodeMessage).toBe('');
  expect(component.amountAutoCodeMessage).toBe('');
});

});
});
15 changes: 5 additions & 10 deletions src/app/shared/components/fy-currency/fy-currency.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export class FyCurrencyComponent implements ControlValueAccessor, OnInit, OnChan

@Input() autoCodedData: ParsedResponse;

autoCodeMessage = '';
currencyAutoCodeMessage = '';

amountAutoCodeMessage = '';

exchangeRate = 1;

Expand Down Expand Up @@ -183,15 +185,8 @@ export class FyCurrencyComponent implements ControlValueAccessor, OnInit, OnChan
const isCurrencyAutoCoded = currency && currency === formCurrency;
const isAmountAutoCoded = amount && amount === formAmount;

if (isCurrencyAutoCoded && isAmountAutoCoded) {
this.autoCodeMessage = 'Currency and Amount are auto coded.';
} else if (isCurrencyAutoCoded) {
this.autoCodeMessage = 'Currency is auto coded.';
} else if (isAmountAutoCoded) {
this.autoCodeMessage = 'Amount is auto coded.';
} else {
this.autoCodeMessage = '';
}
this.currencyAutoCodeMessage = isCurrencyAutoCoded ? 'Currency is auto coded.' : '';
this.amountAutoCodeMessage = isAmountAutoCoded ? 'Amount is auto coded.' : '';
}

convertInnerValueToFormValue(innerVal: CurrencyObj): CurrencyAmountFormValues {
Expand Down
Loading