-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Logger new LWC (EG+AR) #959
Open
egraells
wants to merge
4
commits into
trailheadapps:main
Choose a base branch
from
egraells:miscLogger
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
force-app/main/default/lwc/miscI18n/__tests__/miscI18n.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { createElement } from 'lwc'; | ||
import MiscI18n from 'c/miscI18n'; | ||
import USER_LOCALE from '@salesforce/i18n/locale'; | ||
import USER_CURRENCY from '@salesforce/i18n/currency'; | ||
|
||
describe('c-misc-i18n', () => { | ||
afterEach(() => { | ||
// The jsdom instance is shared across test cases in a single file so reset the DOM | ||
while (document.body.firstChild) { | ||
document.body.removeChild(document.body.firstChild); | ||
} | ||
}); | ||
|
||
it('component is initialized with correct variables', () => { | ||
// Create initial element | ||
const element = createElement('c-misc-i18n', { | ||
is: MiscI18n | ||
}); | ||
document.body.appendChild(element); | ||
|
||
const userLocale = element.shadowRoot.querySelector('span.userLocale'); | ||
expect(userLocale).not.toBeNull(); | ||
expect(userLocale.textContent).toBe(USER_LOCALE); | ||
|
||
const dateUserLocale = element.shadowRoot.querySelector( | ||
'span.dateUserLocale' | ||
); | ||
expect(dateUserLocale).not.toBeNull(); | ||
expect(dateUserLocale.textContent).toBe( | ||
new Intl.DateTimeFormat(USER_LOCALE).format(new Date()) | ||
); | ||
|
||
const currencyUserLocale = element.shadowRoot.querySelector( | ||
'span.currencyUserLocale' | ||
); | ||
expect(currencyUserLocale).not.toBeNull(); | ||
expect(currencyUserLocale.textContent).toBe( | ||
new Intl.NumberFormat(USER_LOCALE, { | ||
style: 'currency', | ||
currency: USER_CURRENCY, | ||
currencyDisplay: 'symbol' | ||
}).format(100) | ||
); | ||
|
||
const dateJapanLocale = element.shadowRoot.querySelector( | ||
'span.dateJapanLocale' | ||
); | ||
expect(dateJapanLocale).not.toBeNull(); | ||
expect(dateJapanLocale.textContent).toBe( | ||
new Intl.DateTimeFormat('ja-JP').format(new Date()) | ||
); | ||
|
||
const currencyJapanLocale = element.shadowRoot.querySelector( | ||
'span.currencyJapanLocale' | ||
); | ||
expect(currencyJapanLocale).not.toBeNull(); | ||
expect(currencyJapanLocale.textContent).toBe( | ||
new Intl.NumberFormat('ja-JP', { | ||
style: 'currency', | ||
currency: 'JPY', | ||
currencyDisplay: 'symbol' | ||
}).format(100) | ||
); | ||
}); | ||
|
||
it('is accessible', async () => { | ||
const element = createElement('c-misc-i18n', { | ||
is: MiscI18n | ||
}); | ||
|
||
document.body.appendChild(element); | ||
|
||
await expect(element).toBeAccessible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<lightning-card title="MiscI18n" icon-name="custom:custom19"> | ||
<div class="slds-var-m-around_medium"> | ||
<p> | ||
User's locale: | ||
<span class="userLocale"><b>{userLocale}</b></span> | ||
</p> | ||
<p> | ||
Today's date formatted with {userLocale}: | ||
<span class="dateUserLocale"> | ||
<b>{dateUserLocale}</b> | ||
</span> | ||
</p> | ||
<p> | ||
100 {userCurrency} formatted with {userLocale}: | ||
<span class="currencyUserLocale"> | ||
<b>{currencyUserLocale}</b> | ||
</span> | ||
</p> | ||
<p> | ||
Today's date formatted with {japanLocale}: | ||
<span class="dateJapanLocale"> | ||
<b>{dateJapanLocale}</b> | ||
</span> | ||
</p> | ||
<p> | ||
100 {japanCurrency} formatted with {japanLocale}: | ||
<span class="currencyJapanLocale"> | ||
<b>{currencyJapanLocale}</b> | ||
</span> | ||
</p> | ||
</div> | ||
<c-view-source source="lwc/miscI18n" slot="footer"> | ||
Use the standard JS Intl class to format dates and numbers with | ||
different locales and currencies. | ||
</c-view-source> | ||
</lightning-card> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { LightningElement } from 'lwc'; | ||
import USER_LOCALE from '@salesforce/i18n/locale'; | ||
import USER_CURRENCY from '@salesforce/i18n/currency'; | ||
|
||
export default class I18n extends LightningElement { | ||
userLocale = USER_LOCALE; | ||
userCurrency = USER_CURRENCY; | ||
japanLocale = 'ja-JP'; | ||
japanCurrency = 'JPY'; | ||
|
||
get dateUserLocale() { | ||
const date = new Date(); | ||
return new Intl.DateTimeFormat(USER_LOCALE).format(date); | ||
} | ||
|
||
get dateJapanLocale() { | ||
const date = new Date(); | ||
return new Intl.DateTimeFormat(this.japanLocale).format(date); | ||
} | ||
|
||
get currencyUserLocale() { | ||
return new Intl.NumberFormat(USER_LOCALE, { | ||
style: 'currency', | ||
currency: USER_CURRENCY, | ||
currencyDisplay: 'symbol' | ||
}).format(100); | ||
} | ||
|
||
get currencyJapanLocale() { | ||
return new Intl.NumberFormat(this.japanLocale, { | ||
style: 'currency', | ||
currency: this.japanCurrency, | ||
currencyDisplay: 'symbol' | ||
}).format(100); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>61.0</apiVersion> | ||
<isExposed>true</isExposed> | ||
<targets> | ||
<target>lightning__RecordPage</target> | ||
<target>lightning__AppPage</target> | ||
<target>lightning__HomePage</target> | ||
</targets> | ||
</LightningComponentBundle> |
29 changes: 29 additions & 0 deletions
29
force-app/main/default/lwc/miscLogger/__tests__/miscLogger.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { createElement } from 'lwc'; | ||
import MiscLogger from 'c/miscLogger'; | ||
import { log } from 'lightning/logger'; | ||
|
||
describe('c-misc-logger', () => { | ||
afterEach(() => { | ||
// The jsdom instance is shared across test cases in a single file so reset the DOM | ||
while (document.body.firstChild) { | ||
document.body.removeChild(document.body.firstChild); | ||
} | ||
}); | ||
|
||
it('When log to event monitoring is clicked, the lightning log function is called', () => { | ||
// Create component | ||
const element = createElement('c-misc-logger', { | ||
is: MiscLogger | ||
}); | ||
document.body.appendChild(element); | ||
|
||
// Click button | ||
const buttonEl = element.shadowRoot.querySelector( | ||
'div.event-monitoring lightning-button' | ||
); | ||
buttonEl.click(); | ||
|
||
// Check log function has been called | ||
expect(log).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<template> | ||
<lightning-card title="MiscLogger" icon-name="custom:custom63"> | ||
<div class="slds-var-m-around_medium"> | ||
<p class="slds-var-m-bottom_small"> | ||
<lightning-button | ||
label="Log a message to the console" | ||
onclick={logMessageConsole} | ||
></lightning-button> | ||
</p> | ||
</div> | ||
<div class="slds-var-m-around_medium event-monitoring"> | ||
<p class="slds-var-m-bottom_small"> | ||
<lightning-button | ||
label="Log a message to the console and Event Monitoring" | ||
onclick={logMessageEventMonitoring} | ||
></lightning-button> | ||
</p> | ||
</div> | ||
|
||
<c-view-source source="lwc/misclogger" slot="footer"> | ||
Log custom messages to Event Monitoring, adding observability to | ||
your LWCs. | ||
To use this feature, enable Lightning Logger Events from Setup, under | ||
Event Monitoring Settings. | ||
</c-view-source> | ||
</lightning-card> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { LightningElement } from 'lwc'; | ||
import { log } from 'lightning/logger'; | ||
|
||
export default class MiscLogger extends LightningElement { | ||
logMessageEventMonitoring() { | ||
let msg = { | ||
type: 'click', | ||
action: 'Log' | ||
}; | ||
log(msg); | ||
} | ||
logMessageConsole() { | ||
console.log('This message is logged to the console'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>61.0</apiVersion> | ||
<isExposed>true</isExposed> | ||
<targets> | ||
<target>lightning__AppPage</target> | ||
<target>lightning__RecordPage</target> | ||
<target>lightning__HomePage</target> | ||
</targets> | ||
</LightningComponentBundle> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mention to enable Lightning Logger Events from Setup to test the 'logMessageEventMonitoring'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes done, please review and let me know