Skip to content

Commit

Permalink
Added a spinner to LWC logOrganizationLimits, and cleaned up some Jes…
Browse files Browse the repository at this point in the history
…t tests
  • Loading branch information
jongpie committed Mar 12, 2024
1 parent f2b6e69 commit 46c7bd9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ describe('c-log-organization-limits', () => {
is: LogOrganizationLimits
});
document.body.appendChild(element);
const nullOrganizationLimitsJson = null;
const mockGetRecordWithoutLimitsJson = { ...mockGetRecord };
mockGetRecordWithoutLimitsJson.fields.OrganizationLimits__c.value = null;

getRecord.emit(nullOrganizationLimitsJson);
getRecord.emit(mockGetRecordWithoutLimitsJson);
await Promise.resolve('resolves getRecord()');

const warningNotifyElements = element.shadowRoot.querySelectorAll('.slds-alert_warning');
Expand All @@ -58,9 +59,10 @@ describe('c-log-organization-limits', () => {
is: LogOrganizationLimits
});
document.body.appendChild(element);
const invalidOrganizationLimitsJson = '༼ つ ◕_◕ ༽つ This is not valid JSON!!!';
const mockGetRecordWithInvalidLimitsJson = { ...mockGetRecord };
mockGetRecordWithInvalidLimitsJson.fields.OrganizationLimits__c.value = '༼ つ ◕_◕ ༽つ This is not valid JSON!!!';

getRecord.emit(invalidOrganizationLimitsJson);
getRecord.emit(mockGetRecordWithInvalidLimitsJson);
await Promise.resolve('resolves getRecord()');

const warningNotifyElements = element.shadowRoot.querySelectorAll('.slds-alert_warning');
Expand All @@ -72,6 +74,6 @@ describe('c-log-organization-limits', () => {
expect(layoutItems.length).toBe(1);
const staticFormElements = element.shadowRoot.querySelectorAll('.slds-form-element__static');
expect(staticFormElements.length).toBe(1);
expect(staticFormElements[0].innerHTML).toBe(invalidOrganizationLimitsJson);
expect(staticFormElements[0].innerHTML).toBe(mockGetRecordWithInvalidLimitsJson.fields.OrganizationLimits__c.value);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,53 @@
<c-logger-page-section>
<span slot="title">Organization Limits</span>
<span slot="content">
<template if:false={isValidOrganizationLimitsJson}>
<div class="slds-notify slds-notify_alert slds-alert_warning" role="alert">
<span class="slds-assistive-text">warning</span>
<lightning-icon class="slds-m-right_x-small" icon-name="utility:warning" size="x-small" variant="inverse"></lightning-icon>
<h2>Could not parse Organization Limits JSON data, the current value is displayed below.</h2>
<template if:false={isLoaded}>
<div class="slds-is-relative" style="min-height: 12em">
<lightning-spinner variant="brand"></lightning-spinner>
</div>
<lightning-layout>
<lightning-layout-item class="slds-col slds-p-horizontal_small slds-p-vertical_x-small" size="12">
<div class="slds-form-element slds-form-element_readonly">
<span class="slds-form-element__label">Organization Limits</span>
<div class="slds-form-element__control">
<div class="slds-form-element__static">{organizationLimitsJson}</div>
</div>
</div>
</lightning-layout-item>
</lightning-layout>
</template>
<template if:true={isValidOrganizationLimitsJson}>
<lightning-layout>
<lightning-layout-item class="slds-col slds-p-horizontal_small slds-p-vertical_x-small" size="6">
<template for:each={organizationLimitsLeft} for:item="limit">
<div class="slds-form-element slds-form-element_readonly" data-id={limit.Name} key={limit.Name}>
<span class="slds-form-element__label">{limit.Name}</span>
<template if:true={isLoaded}>
<template if:false={isValidOrganizationLimitsJson}>
<div class="slds-notify slds-notify_alert slds-alert_warning" role="alert">
<span class="slds-assistive-text">warning</span>
<lightning-icon class="slds-m-right_x-small" icon-name="utility:warning" size="x-small" variant="inverse"></lightning-icon>
<h2>Could not parse Organization Limits JSON data, the current value is displayed below.</h2>
</div>
<lightning-layout>
<lightning-layout-item class="slds-col slds-p-horizontal_small slds-p-vertical_x-small" size="12">
<div class="slds-form-element slds-form-element_readonly">
<span class="slds-form-element__label">Organization Limits</span>
<div class="slds-form-element__control">
<div class="slds-form-element__static">{limit.Text}</div>
<div class="slds-form-element__static">{organizationLimitsJson}</div>
</div>
</div>
</template>
</lightning-layout-item>
<lightning-layout-item class="slds-col slds-p-horizontal_small slds-p-vertical_x-small" size="6">
<template for:each={organizationLimitsRight} for:item="limit">
<div class="slds-form-element slds-form-element_readonly" data-id={limit.Name} key={limit.Name}>
<span class="slds-form-element__label">{limit.Name}</span>
<div class="slds-form-element__control">
<div class="slds-form-element__static">{limit.Text}</div>
</lightning-layout-item>
</lightning-layout>
</template>
<template if:true={isValidOrganizationLimitsJson}>
<lightning-layout>
<lightning-layout-item class="slds-col slds-p-horizontal_small slds-p-vertical_x-small" size="6">
<template for:each={organizationLimitsLeft} for:item="limit">
<div class="slds-form-element slds-form-element_readonly" data-id={limit.Name} key={limit.Name}>
<span class="slds-form-element__label">{limit.Name}</span>
<div class="slds-form-element__control">
<div class="slds-form-element__static">{limit.Text}</div>
</div>
</div>
</div>
</template>
</lightning-layout-item>
</lightning-layout>
</template>
</lightning-layout-item>
<lightning-layout-item class="slds-col slds-p-horizontal_small slds-p-vertical_x-small" size="6">
<template for:each={organizationLimitsRight} for:item="limit">
<div class="slds-form-element slds-form-element_readonly" data-id={limit.Name} key={limit.Name}>
<span class="slds-form-element__label">{limit.Name}</span>
<div class="slds-form-element__control">
<div class="slds-form-element__static">{limit.Text}</div>
</div>
</div>
</template>
</lightning-layout-item>
</lightning-layout>
</template>
</template>
</span>
</c-logger-page-section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class LogOrganizationLimits extends LightningElement {
@api
recordId;

isLoaded = false;
isValidOrganizationLimitsJson;
organizationLimitsLeft = [];
organizationLimitsRight = [];
Expand All @@ -14,21 +15,27 @@ export default class LogOrganizationLimits extends LightningElement {
recordId: '$recordId',
fields: [ORGANIZATION_LIMITS_FIELD]
})
async wiredGetLogEntry({ data }) {
async wiredGetLog({ data }) {
if (data) {
const organizationLimitsJson = getFieldValue(data, ORGANIZATION_LIMITS_FIELD);
this._processOrganizationLimits(organizationLimitsJson);
}
}

_processOrganizationLimits(organizationLimitsJson) {
if (!organizationLimitsJson) {
this.isValidOrganizationLimitsJson = false;
this.isLoaded = true;
return;
}

let limits;
try {
limits = JSON.parse(organizationLimitsJson);
this.isValidOrganizationLimitsJson = true;
} catch (error) {
this.isValidOrganizationLimitsJson = false;
this.organizationLimitsJson = organizationLimitsJson;
this.isValidOrganizationLimitsJson = false;
this.isLoaded = true;
return;
}

Expand All @@ -53,5 +60,7 @@ export default class LogOrganizationLimits extends LightningElement {
const halfLimitsLength = Math.ceil(limits.length / 2);
this.organizationLimitsLeft = limits.slice(0, halfLimitsLength);
this.organizationLimitsRight = limits.slice(halfLimitsLength);
this.isValidOrganizationLimitsJson = true;
this.isLoaded = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,7 @@ private class LogHandler_Tests {
organizationLimit.Max = systemOrgLimit.getLimit();
expectedOrganizationLimits.add(organizationLimit);
}
System.Assert.areEqual(
JSON.serializePretty(expectedOrganizationLimits),
log.OrganizationLimits__c,
'The expected:\n' + JSON.serializePretty(expectedOrganizationLimits) + 'received:\n' + log.OrganizationLimits__c
);
System.Assert.areEqual(JSON.serializePretty(expectedOrganizationLimits), log.OrganizationLimits__c);
}

@IsTest
Expand Down

0 comments on commit 46c7bd9

Please sign in to comment.