Skip to content

Commit

Permalink
updated components to display formatting in readonly (#221)
Browse files Browse the repository at this point in the history
* updated components to display formatting in readonly

* updated based on comment

---------

Co-authored-by: mohas22 <[email protected]>
  • Loading branch information
samhere06 and mohas22 authored Nov 5, 2024
1 parent 6158d68 commit 3419eca
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 114 deletions.
55 changes: 30 additions & 25 deletions src/components/fields/Currency/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,41 +104,46 @@ class Currency extends FormComponentBase {
// of any component that's a child of BridgeBase with a call to this.prepareForRender();
this.prepareForRender();

// return if not visible
if (!this.bVisible) {
return nothing;
}
// Handle and return if read only rendering
if (this.bReadonly) {
return html`
<text-form
.pConn=${this.thePConn}
?disabled=${this.bDisabled}
const theContent = html`
<lion-input-amount
?readonly=${this.bReadonly}
?visible=${this.bVisible}
label=${this.label}
value=${this.value}
testId=${this.testId}
.modelValue=${parseFloat(this.value)}
dataTestId=${this.testId}
currency=${this.currencyISOCode}
>
</text-form>
</lion-input-amount>
`;
this.renderTemplates.push(theContent);

return this.renderTemplates;
}

// lion-input-amount options as based on Intl.NumberFormat standard
// NOTE: we set modelValue to parseFloat(this.value). This helps validation.
const theContent = html`${this.bVisible
? html` <lion-input-amount
id=${this.theComponentId}
dataTestId=${this.testId}
.modelValue=${parseFloat(this.value)}
.fieldName=${this.label}
.validators=${this.lionValidatorsArray}
.feedbackCondition=${this.requiredFeedbackCondition.bind(this)}
currency=${this.currencyISOCode}
?readonly=${this.bReadonly}
?disabled=${this.bDisabled}
@click=${this.fieldOnChange}
@blur=${this.fieldOnBlur}
@change=${this.fieldOnChange}
>
<span slot="label">${this.annotatedLabel}</span>
</lion-input-amount>`
: nothing}`;
const theContent = html` <lion-input-amount
id=${this.theComponentId}
dataTestId=${this.testId}
.modelValue=${parseFloat(this.value)}
.fieldName=${this.label}
.validators=${this.lionValidatorsArray}
.feedbackCondition=${this.requiredFeedbackCondition.bind(this)}
currency=${this.currencyISOCode}
?readonly=${this.bReadonly}
?disabled=${this.bDisabled}
@click=${this.fieldOnChange}
@blur=${this.fieldOnBlur}
@change=${this.fieldOnChange}
>
<span slot="label">${this.annotatedLabel}</span>
</lion-input-amount>`;

this.renderTemplates.push(theContent);

Expand Down
60 changes: 33 additions & 27 deletions src/components/fields/Decimal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,49 @@ class Decimal extends FormComponentBase {
// of any component that's a child of BridgeBase with a call to this.prepareForRender();
this.prepareForRender();

// return if not visible
if (!this.bVisible) {
return nothing;
}

// Handle and return if read only rendering
if (this.bReadonly) {
return html`
<text-form
.pConn=${this.thePConn}
?disabled=${this.bDisabled}
const theContent = html`
<lion-input-amount
id=${this.theComponentId}
?readonly=${this.bReadonly}
?visible=${this.bVisible}
label=${this.label}
value=${this.value}
testId=${this.testId}
.modelValue=${this.value}
dataTestId=${this.testId}
>
</text-form>
</lion-input-amount>
`;
this.renderTemplates.push(theContent);

return this.renderTemplates;
}

loadDefaultFeedbackMessages();

const theContent = html`${this.bVisible
? html` <div class="form-group">
<lion-input-amount
id=${this.theComponentId}
name="Amount"
dataTestId=${this.testId}
.modelValue=${this.value}
.fieldName=${this.label}
.validators=${this.lionValidatorsArray}
.feedbackCondition=${this.requiredFeedbackCondition.bind(this)}
?readonly=${this.bReadonly}
?disabled=${this.bDisabled}
@click=${this.fieldOnChange}
@blur=${this.fieldOnBlur}
@change=${this.fieldOnChange}
>
<span slot="label">${this.annotatedLabel}</span>
</lion-input-amount>
</div>`
: nothing}`;
const theContent = html` <div class="form-group">
<lion-input-amount
id=${this.theComponentId}
name="Amount"
dataTestId=${this.testId}
.modelValue=${this.value}
.fieldName=${this.label}
.validators=${this.lionValidatorsArray}
.feedbackCondition=${this.requiredFeedbackCondition.bind(this)}
?readonly=${this.bReadonly}
?disabled=${this.bDisabled}
@click=${this.fieldOnChange}
@blur=${this.fieldOnBlur}
@change=${this.fieldOnChange}
>
<span slot="label">${this.annotatedLabel}</span>
</lion-input-amount>
</div>`;

this.renderTemplates.push(theContent);

Expand Down
67 changes: 39 additions & 28 deletions src/components/fields/Integer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,44 +69,55 @@ class Integer extends FormComponentBase {
// of any component that's a child of BridgeBase with a call to this.prepareForRender();
this.prepareForRender();

// return if not visible
if (!this.bVisible) {
return nothing;
}

// Handle and return if read only rendering
if (this.bReadonly) {
return html`
<text-form
.pConn=${this.thePConn}
?disabled=${this.bDisabled}
const theContent = html`
<lion-input-amount
id=${this.theComponentId}
?readonly=${this.bReadonly}
?visible=${this.bVisible}
label=${this.label}
value=${this.value}
testId=${this.testId}
.formatOptions="${{
minimumFractionDigits: 0,
maximumFractionDigits: 0
}}"
.modelValue=${this.value}
dataTestId=${this.testId}
>
</text-form>
</lion-input-amount>
`;

this.renderTemplates.push(theContent);

return this.renderTemplates;
}

// lion-input-amount options as based on Intl.NumberFormat standard
// NOTE: we set modelValue to parseInt(this.value) to trim any decimal. This helps validation.
const theContent = html`${this.bVisible
? html` <lion-input-amount
id=${this.theComponentId}
dataTestId=${this.testId}
.fieldName=${this.label}
.formatOptions="${{
minimumFractionDigits: 0,
maximumFractionDigits: 0
}}"
.modelValue=${parseInt(this.value, 10)}
.validators=${this.lionValidatorsArray}
.feedbackCondition=${this.requiredFeedbackCondition.bind(this)}
?readonly=${this.bReadonly}
?disabled=${this.bDisabled}
@click=${this.fieldOnChange}
@blur=${this.fieldOnBlur}
@change=${this.fieldOnChange}
>
<span slot="label">${this.annotatedLabel}</span>
</lion-input-amount>`
: nothing}`;
const theContent = html` <lion-input-amount
id=${this.theComponentId}
dataTestId=${this.testId}
.fieldName=${this.label}
.formatOptions="${{
minimumFractionDigits: 0,
maximumFractionDigits: 0
}}"
.modelValue=${parseInt(this.value, 10)}
.validators=${this.lionValidatorsArray}
.feedbackCondition=${this.requiredFeedbackCondition.bind(this)}
?readonly=${this.bReadonly}
?disabled=${this.bDisabled}
@click=${this.fieldOnChange}
@blur=${this.fieldOnBlur}
@change=${this.fieldOnChange}
>
<span slot="label">${this.annotatedLabel}</span>
</lion-input-amount>`;

this.renderTemplates.push(theContent);

Expand Down
56 changes: 31 additions & 25 deletions src/components/fields/Percentage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,41 +77,47 @@ class Percentage extends FormComponentBase {
// of any component that's a child of BridgeBase with a call to this.prepareForRender();
this.prepareForRender();

// return if not visible
if (!this.bVisible) {
return nothing;
}

// Handle and return if read only rendering
if (this.bReadonly) {
return html`
<text-form
.pConn=${this.thePConn}
?disabled=${this.bDisabled}
const theContent = html`
<lion-input-amount
id=${this.theComponentId}
?readonly=${this.bReadonly}
?visible=${this.bVisible}
label=${this.label}
value=${this.value}
testId=${this.testId}
.formatOptions=${{ style: 'percent', minimumFractionDigits: 0, maximumFractionDigits: 4 }}
.modelValue=${parseFloat(this.value)}
dataTestId=${this.testId}
>
</text-form>
</lion-input-amount>
`;
this.renderTemplates.push(theContent);

return this.renderTemplates;
}

// lion-input-amount options as based on Intl.NumberFormat standard
// NOTE: we set modelValue to parseFloat(this.value). This helps validation.
const theContent = html`${this.bVisible
? html` <lion-input-amount
id=${this.theComponentId}
dataTestId=${this.testId}
.fieldName=${this.label}
.formatOptions=${{ style: 'percent', minimumFractionDigits: 0, maximumFractionDigits: 4 }}
.modelValue=${parseFloat(this.value)}
.validators=${this.lionValidatorsArray}
.feedbackCondition=${this.requiredFeedbackCondition.bind(this)}
?readonly=${this.bReadonly}
?disabled=${this.bDisabled}
@click=${this.fieldOnChange}
@blur=${this.fieldOnBlur}
@change=${this.fieldOnChange}
>
<span slot="label">${this.annotatedLabel}</span>
</lion-input-amount>`
: nothing}`;
const theContent = html` <lion-input-amount
id=${this.theComponentId}
dataTestId=${this.testId}
.fieldName=${this.label}
.formatOptions=${{ style: 'percent', minimumFractionDigits: 0, maximumFractionDigits: 4 }}
.modelValue=${parseFloat(this.value)}
.validators=${this.lionValidatorsArray}
.feedbackCondition=${this.requiredFeedbackCondition.bind(this)}
?readonly=${this.bReadonly}
?disabled=${this.bDisabled}
@blur=${this.fieldOnBlur}
@change=${this.fieldOnChange}
>
<span slot="label">${this.annotatedLabel}</span>
</lion-input-amount>`;

this.renderTemplates.push(theContent);

Expand Down
18 changes: 12 additions & 6 deletions tests/e2e/DigV2/ComplexFields/DataReference.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ test.describe('E2E test', () => {

/** Testing the values present on Confirm screen */
await expect(assignment.locator('text-form[value="Basic Product"]')).toBeVisible();
await expect(assignment.locator('text-form[value="75"]')).toBeVisible();
await expect(assignment.locator('currency-form >> lion-input-amount')).toBeVisible();
await expect(await assignment.locator('currency-form >> lion-input-amount >> input').inputValue()).toBe('75.00');
await expect(assignment.locator('text-form[value="9f2584c2-5cb4-4abe-a261-d68050ee0f66"]')).toBeVisible();

await page.locator('button:has-text("Previous")').click();
Expand All @@ -64,7 +65,8 @@ test.describe('E2E test', () => {

/** Testing the values present on Confirm screen */
await expect(assignment.locator('text-form[value="Basic Product"]')).toBeVisible();
await expect(assignment.locator('text-form[value="75"]')).toBeVisible();
await expect(assignment.locator('currency-form >> lion-input-amount')).toBeVisible();
await expect(await assignment.locator('currency-form >> lion-input-amount >> input').inputValue()).toBe('75.00');
await expect(assignment.locator('text-form[value="9f2584c2-5cb4-4abe-a261-d68050ee0f66"]')).toBeVisible();

await page.locator('button:has-text("Previous")').click();
Expand All @@ -84,7 +86,8 @@ test.describe('E2E test', () => {

/** Testing the values present on Confirm screen */
await expect(assignment.locator('text-form[value="Luxury Product"]')).toBeVisible();
await expect(assignment.locator('text-form[value="200"]')).toBeVisible();
await expect(assignment.locator('currency-form >> lion-input-amount')).toBeVisible();
await expect(await assignment.locator('currency-form >> lion-input-amount >> input').inputValue()).toBe('200.00');
await expect(assignment.locator('text-form[value="d63e2d8a-bd39-47b6-8dab-dce78a8bf91d"]')).toBeVisible();

await page.locator('button:has-text("Previous")').click();
Expand All @@ -105,7 +108,8 @@ test.describe('E2E test', () => {

/** Testing the values present on Confirm screen */
await expect(assignment.locator('text-form[value="Basic Product"]')).toBeVisible();
await expect(assignment.locator('text-form[value="75"]')).toBeVisible();
await expect(assignment.locator('currency-form >> lion-input-amount')).toBeVisible();
await expect(await assignment.locator('currency-form >> lion-input-amount >> input').inputValue()).toBe('75.00');
await expect(assignment.locator('text-form[value="9f2584c2-5cb4-4abe-a261-d68050ee0f66"]')).toBeVisible();

await page.locator('button:has-text("Previous")').click();
Expand Down Expand Up @@ -150,7 +154,8 @@ test.describe('E2E test', () => {

/** Testing the values present on Confirm screen */
await expect(assignment.locator('text-form[value="Basic Product"]')).toBeVisible();
await expect(assignment.locator('text-form[value="75"]')).toBeVisible();
await expect(assignment.locator('currency-form >> lion-input-amount')).toBeVisible();
await expect(await assignment.locator('currency-form >> lion-input-amount >> input').inputValue()).toBe('75.00');
await expect(assignment.locator('text-form[value="9f2584c2-5cb4-4abe-a261-d68050ee0f66"]')).toBeVisible();

await page.locator('button:has-text("Previous")').click();
Expand Down Expand Up @@ -187,7 +192,8 @@ test.describe('E2E test', () => {

/** Testing the values present on Confirm screen */
await expect(assignment.locator('text-form[value="Basic Product"]')).toBeVisible();
await expect(assignment.locator('text-form[value="75"]')).toBeVisible();
await expect(assignment.locator('currency-form >> lion-input-amount')).toBeVisible();
await expect(await assignment.locator('currency-form >> lion-input-amount >> input').inputValue()).toBe('75.00');
await expect(assignment.locator('text-form[value="9f2584c2-5cb4-4abe-a261-d68050ee0f66"]')).toBeVisible();

await page.locator('button:has-text("Previous")').click();
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/DigV2/FormFields/Decimal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test.describe('E2E test', () => {
/** Selecting Update from the Sub Category dropdown */
await page.selectOption('lion-select[datatestid="9463d5f18a8924b3200b56efaad63bda"] select', 'Update');

const readonlyDecimal = page.locator('lion-input[datatestid="acdcc5f01c940f07cf14373612721a0c"] >> input');
const readonlyDecimal = page.locator('lion-input-amount[datatestid="acdcc5f01c940f07cf14373612721a0c"]');
attributes = await common.getAttributes(readonlyDecimal);
await expect(attributes.includes('readonly')).toBeTruthy();

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/DigV2/FormFields/Integer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test.describe('E2E test', () => {
/** Selecting Update from the Sub Category dropdown */
await page.selectOption('lion-select[datatestid="9463d5f18a8924b3200b56efaad63bda"] select', 'Update');

const readonlyInteger = page.locator('lion-input[datatestid="c6f04035ab4212992a31968bf190875b"] >> input');
const readonlyInteger = page.locator('lion-input-amount[datatestid="c6f04035ab4212992a31968bf190875b"]');
attributes = await common.getAttributes(readonlyInteger);
await expect(attributes.includes('readonly')).toBeTruthy();

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/DigV2/FormFields/Percentage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test.describe('E2E test', () => {
/** Selecting Update from the Sub Category dropdown */
await page.selectOption('lion-select[datatestid="9463d5f18a8924b3200b56efaad63bda"] select', 'Update');

const readonlyPercentage = page.locator('lion-input[datatestid="4d28c40ee619dafd16f7f4813e18ece6"] >> input');
const readonlyPercentage = page.locator('lion-input-amount[datatestid="4d28c40ee619dafd16f7f4813e18ece6"]');
attributes = await common.getAttributes(readonlyPercentage);
await expect(attributes.includes('readonly')).toBeTruthy();

Expand Down

0 comments on commit 3419eca

Please sign in to comment.