From 99c22dcbd9b9ec4338eda4e067cff822f58d7eda Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 00:26:37 +0000 Subject: [PATCH 1/5] Setting up GitHub Classroom Feedback From 28ee56046d8eea5a3f6bc0ee6d7f43c44a6945c4 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 00:26:39 +0000 Subject: [PATCH 2/5] add online IDE url --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9e3dca7..061d8b9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Open in Visual Studio Code](https://classroom.github.com/assets/open-in-vscode-718a45dd9cf7e7f842a935f5ebbe5719a5e09af4491e668f4dbf3b35d5cca122.svg)](https://classroom.github.com/online_ide?assignment_repo_id=15110808&assignment_repo_type=AssignmentRepo) # Developer Kickstart: Introduction to Lightning Web Components (LWC) This repository is a foundational pillar of the Developer Kickstart curriculum at Cloud Code Academy. Crafted specifically for budding Salesforce developers, this module introduces the groundbreaking world of Lightning Web Components. LWC opens a new dimension in Salesforce front-end development, emphasizing modern JavaScript techniques, Salesforce data integration, and interactive user interfaces. From b23394b5c694abe224af3ce0e34f4a14cbdd26e6 Mon Sep 17 00:00:00 2001 From: Oxana Date: Wed, 22 May 2024 22:47:44 -0400 Subject: [PATCH 3/5] Created LWC platformDevCertCalculator. Implemented base functionality --- .../platformDevCertCalculator.test.js | 25 ++++++ .../platformDevCertCalculator.html | 78 +++++++++++++++++++ .../platformDevCertCalculator.js | 71 +++++++++++++++++ .../platformDevCertCalculator.js-meta.xml | 10 +++ 4 files changed, 184 insertions(+) create mode 100644 force-app/main/default/lwc/platformDevCertCalculator/__tests__/platformDevCertCalculator.test.js create mode 100644 force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html create mode 100644 force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js create mode 100644 force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js-meta.xml diff --git a/force-app/main/default/lwc/platformDevCertCalculator/__tests__/platformDevCertCalculator.test.js b/force-app/main/default/lwc/platformDevCertCalculator/__tests__/platformDevCertCalculator.test.js new file mode 100644 index 0000000..46314f6 --- /dev/null +++ b/force-app/main/default/lwc/platformDevCertCalculator/__tests__/platformDevCertCalculator.test.js @@ -0,0 +1,25 @@ +import { createElement } from 'lwc'; +import PlatformDevCertCalculator from 'c/platformDevCertCalculator'; + +describe('c-platform-dev-cert-calculator', () => { + 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('TODO: test case generated by CLI command, please fill in test logic', () => { + // Arrange + const element = createElement('c-platform-dev-cert-calculator', { + is: PlatformDevCertCalculator + }); + + // Act + document.body.appendChild(element); + + // Assert + // const div = element.shadowRoot.querySelector('div'); + expect(1).toBe(1); + }); +}); \ No newline at end of file diff --git a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html new file mode 100644 index 0000000..9c9c023 --- /dev/null +++ b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html @@ -0,0 +1,78 @@ + \ No newline at end of file diff --git a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js new file mode 100644 index 0000000..9cb2577 --- /dev/null +++ b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js @@ -0,0 +1,71 @@ +import { LightningElement } from 'lwc'; +const devFundamentalsWeight = 0.23; +const processAutomationWeight = 0.3; +const userInterfaceWeight = 0.25; +const testDebugDeployWeight = 0.22; +const passingScore = 68; + +export default class PlatformDevCertCalculator extends LightningElement { + + maxFieldValue = 100; + devFundamentalsScore = 50; + processAutomationScore = 50; + userInterfaceScore = 50; + testDebugDeployScore = 50; + certificationScore = 90; + + showResources = false; + passExam = false; + attemptHistory = [ + {Id: 1, Score: 50}, + {Id: 2, Score: 60}, + {Id: 3, Score: 70} + ]; + + handleChange(event) { + // TODO: Add Validity checking + let value = Number(event.target.value); + switch (event.target.name) { + case 'devFundamentals': + this.devFundamentalsScore = value; + break; + case 'processAutomation': + this.processAutomationScore = value; + break; + case 'userInterface': + this.userInterfaceScore = value; + break; + case 'testDebugDeploy': + this.testDebugDeployScore = value; + break; + } + } + + calculateScore() { + let devFundWeightedScore = this.devFundamentalsScore * devFundamentalsWeight; + let procAutomWeightedScore = this.processAutomationScore * processAutomationWeight; + let userIntWeightedScore = this.userInterfaceScore * userInterfaceWeight; + let testDebWeightedScore = this.testDebugDeployScore * testDebugDeployWeight; + this.certificationScore = devFundWeightedScore + procAutomWeightedScore + userIntWeightedScore + testDebWeightedScore; + this.showResourcesIfFailed(); + this.addAttemptHistory(); + } + + showResourcesIfFailed() { + if (this.certificationScore < passingScore) { + this.showResources = true; + } else { + this.showResources = false; + this.passExam = true; + } + } + + addAttemptHistory() { + this.attemptHistory.push( + { + Id: 4, + Score: this.certificationScore + } + ); + } +} \ No newline at end of file diff --git a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js-meta.xml b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js-meta.xml new file mode 100644 index 0000000..508a5d0 --- /dev/null +++ b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js-meta.xml @@ -0,0 +1,10 @@ + + + 59.0 + true + Platform Developer I Certification Calculator + Salesforce Platform Developer I Certification Score Checker helps to understand Certification results. + + lightning__AppPage + + \ No newline at end of file From 440bbcc97843e57024e1bea7f47c4b385d8178e5 Mon Sep 17 00:00:00 2001 From: Oxana Date: Thu, 23 May 2024 22:04:58 -0400 Subject: [PATCH 4/5] Created child component scoreInformation. Added field value validation --- .../platformDevCertCalculator.html | 31 +++++++---- .../platformDevCertCalculator.js | 52 +++++++++++-------- .../__tests__/scoreInformation.test.js | 25 +++++++++ .../scoreInformation/scoreInformation.html | 33 ++++++++++++ .../lwc/scoreInformation/scoreInformation.js | 23 ++++++++ .../scoreInformation.js-meta.xml | 5 ++ 6 files changed, 138 insertions(+), 31 deletions(-) create mode 100644 force-app/main/default/lwc/scoreInformation/__tests__/scoreInformation.test.js create mode 100644 force-app/main/default/lwc/scoreInformation/scoreInformation.html create mode 100644 force-app/main/default/lwc/scoreInformation/scoreInformation.js create mode 100644 force-app/main/default/lwc/scoreInformation/scoreInformation.js-meta.xml diff --git a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html index 9c9c023..f36b50e 100644 --- a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html +++ b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html @@ -39,16 +39,30 @@
-

Certification Exam Results

-

Certification Score: {certificationScore}%

+

Certification Exam Result

+
Certification Score: {certificationScore}%
+ +
-

Previous Attempts

-
    -
  • Attempt: {attempt.Id}, Score: {attempt.Score}%
  • -
+

Previous Attempt

+ + +
- diff --git a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js index 9cb2577..02ad1e5 100644 --- a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js +++ b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js @@ -8,23 +8,22 @@ const passingScore = 68; export default class PlatformDevCertCalculator extends LightningElement { maxFieldValue = 100; + isFieldValueTooHigh = false; devFundamentalsScore = 50; processAutomationScore = 50; userInterfaceScore = 50; testDebugDeployScore = 50; certificationScore = 90; + numberOfQuestions = 60; showResources = false; passExam = false; - attemptHistory = [ - {Id: 1, Score: 50}, - {Id: 2, Score: 60}, - {Id: 3, Score: 70} - ]; + attemptHistory = []; + currentHistoryId = 0; handleChange(event) { - // TODO: Add Validity checking let value = Number(event.target.value); + this.isFieldValueTooHigh = value > this.maxFieldValue; switch (event.target.name) { case 'devFundamentals': this.devFundamentalsScore = value; @@ -42,13 +41,15 @@ export default class PlatformDevCertCalculator extends LightningElement { } calculateScore() { - let devFundWeightedScore = this.devFundamentalsScore * devFundamentalsWeight; - let procAutomWeightedScore = this.processAutomationScore * processAutomationWeight; - let userIntWeightedScore = this.userInterfaceScore * userInterfaceWeight; - let testDebWeightedScore = this.testDebugDeployScore * testDebugDeployWeight; - this.certificationScore = devFundWeightedScore + procAutomWeightedScore + userIntWeightedScore + testDebWeightedScore; - this.showResourcesIfFailed(); - this.addAttemptHistory(); + if (!this.isFieldValueTooHigh) { + let devFundWeightedScore = this.devFundamentalsScore * devFundamentalsWeight; + let procAutomWeightedScore = this.processAutomationScore * processAutomationWeight; + let userIntWeightedScore = this.userInterfaceScore * userInterfaceWeight; + let testDebWeightedScore = this.testDebugDeployScore * testDebugDeployWeight; + this.certificationScore = Math.round(devFundWeightedScore + procAutomWeightedScore + userIntWeightedScore + testDebWeightedScore); + this.showResourcesIfFailed(); + this.addAttemptHistory(this.certificationScore); + } } showResourcesIfFailed() { @@ -56,16 +57,25 @@ export default class PlatformDevCertCalculator extends LightningElement { this.showResources = true; } else { this.showResources = false; - this.passExam = true; } + this.passExam = !this.showResources; + } + + addAttemptHistory(Score) { + this.currentHistoryId++; + const attempt = { + Id: this.currentHistoryId, + Score + }; + this.attemptHistory = [...this.attemptHistory, attempt]; + } + + deleteAttemptHandler(event) { + let attemptId = event.detail; + this.attemptHistory = this.attemptHistory.filter(attempt => attempt.Id != attemptId); } - addAttemptHistory() { - this.attemptHistory.push( - { - Id: 4, - Score: this.certificationScore - } - ); + connectedCallback() { + this.currentHistoryId = this.attemptHistory.length; } } \ No newline at end of file diff --git a/force-app/main/default/lwc/scoreInformation/__tests__/scoreInformation.test.js b/force-app/main/default/lwc/scoreInformation/__tests__/scoreInformation.test.js new file mode 100644 index 0000000..35e0c19 --- /dev/null +++ b/force-app/main/default/lwc/scoreInformation/__tests__/scoreInformation.test.js @@ -0,0 +1,25 @@ +import { createElement } from 'lwc'; +import ScoreInformation from 'c/scoreInformation'; + +describe('c-score-information', () => { + 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('TODO: test case generated by CLI command, please fill in test logic', () => { + // Arrange + const element = createElement('c-score-information', { + is: ScoreInformation + }); + + // Act + document.body.appendChild(element); + + // Assert + // const div = element.shadowRoot.querySelector('div'); + expect(1).toBe(1); + }); +}); \ No newline at end of file diff --git a/force-app/main/default/lwc/scoreInformation/scoreInformation.html b/force-app/main/default/lwc/scoreInformation/scoreInformation.html new file mode 100644 index 0000000..f200192 --- /dev/null +++ b/force-app/main/default/lwc/scoreInformation/scoreInformation.html @@ -0,0 +1,33 @@ + \ No newline at end of file diff --git a/force-app/main/default/lwc/scoreInformation/scoreInformation.js b/force-app/main/default/lwc/scoreInformation/scoreInformation.js new file mode 100644 index 0000000..339b5ae --- /dev/null +++ b/force-app/main/default/lwc/scoreInformation/scoreInformation.js @@ -0,0 +1,23 @@ +import { LightningElement, api } from 'lwc'; + +export default class ScoreInformation extends LightningElement { + + @api score; + @api attemptId; + @api numberOfQuestions; + + get numberOfQuestionsCorrect() { + return Math.floor((this.score / 100) * this.numberOfQuestions); + } + + get numberOfQuestionsIncorrect() { + return this.numberOfQuestions - this.numberOfQuestionsCorrect; + } + + handleDeleteAttempt() { + const deleteEvent = new CustomEvent('deleteattempt', { + detail: this.attemptId + }); + this.dispatchEvent(deleteEvent); + } +} \ No newline at end of file diff --git a/force-app/main/default/lwc/scoreInformation/scoreInformation.js-meta.xml b/force-app/main/default/lwc/scoreInformation/scoreInformation.js-meta.xml new file mode 100644 index 0000000..6127d85 --- /dev/null +++ b/force-app/main/default/lwc/scoreInformation/scoreInformation.js-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + false + \ No newline at end of file From ace291c71ea0e6263020864bf91e4514e257a844 Mon Sep 17 00:00:00 2001 From: Oxana Date: Fri, 24 May 2024 21:44:00 -0400 Subject: [PATCH 5/5] Fixed field value validation. Add deactivation button. Add conditional score color --- .../platformDevCertCalculator.css | 7 +++++++ .../platformDevCertCalculator.html | 13 +++++++----- .../platformDevCertCalculator.js | 20 +++++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.css diff --git a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.css b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.css new file mode 100644 index 0000000..fc59076 --- /dev/null +++ b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.css @@ -0,0 +1,7 @@ +.green-text { + color: green; +} + +.red-text { + color: rgb(142, 3, 15); +} \ No newline at end of file diff --git a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html index f36b50e..51afa10 100644 --- a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html +++ b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html @@ -1,7 +1,12 @@ - +

Press Calculate to see your score. Max field value: {maxFieldValue}

\ No newline at end of file diff --git a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js index 02ad1e5..7de31d8 100644 --- a/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js +++ b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js @@ -13,7 +13,7 @@ export default class PlatformDevCertCalculator extends LightningElement { processAutomationScore = 50; userInterfaceScore = 50; testDebugDeployScore = 50; - certificationScore = 90; + certificationScore = 50; numberOfQuestions = 60; showResources = false; @@ -21,9 +21,12 @@ export default class PlatformDevCertCalculator extends LightningElement { attemptHistory = []; currentHistoryId = 0; + get scoreClass() { + return this.passExam ? 'green-text' : 'red-text'; + } + handleChange(event) { let value = Number(event.target.value); - this.isFieldValueTooHigh = value > this.maxFieldValue; switch (event.target.name) { case 'devFundamentals': this.devFundamentalsScore = value; @@ -38,6 +41,7 @@ export default class PlatformDevCertCalculator extends LightningElement { this.testDebugDeployScore = value; break; } + this.valudateFieldValues(); } calculateScore() { @@ -78,4 +82,16 @@ export default class PlatformDevCertCalculator extends LightningElement { connectedCallback() { this.currentHistoryId = this.attemptHistory.length; } + + valudateFieldValues() { + if (this.devFundamentalsScore > this.maxFieldValue || + this.processAutomationScore > this.maxFieldValue || + this.userInterfaceScore > this.maxFieldValue || + this.testDebugDeployScore > this.maxFieldValue + ) { + this.isFieldValueTooHigh = true; + } else { + this.isFieldValueTooHigh = false; + } + } } \ No newline at end of file