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. 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.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 new file mode 100644 index 0000000..51afa10 --- /dev/null +++ b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.html @@ -0,0 +1,92 @@ + \ 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..7de31d8 --- /dev/null +++ b/force-app/main/default/lwc/platformDevCertCalculator/platformDevCertCalculator.js @@ -0,0 +1,97 @@ +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; + isFieldValueTooHigh = false; + devFundamentalsScore = 50; + processAutomationScore = 50; + userInterfaceScore = 50; + testDebugDeployScore = 50; + certificationScore = 50; + numberOfQuestions = 60; + + showResources = false; + passExam = false; + attemptHistory = []; + currentHistoryId = 0; + + get scoreClass() { + return this.passExam ? 'green-text' : 'red-text'; + } + + handleChange(event) { + 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; + } + this.valudateFieldValues(); + } + + calculateScore() { + 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() { + if (this.certificationScore < passingScore) { + this.showResources = true; + } else { + this.showResources = false; + } + 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); + } + + 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 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 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