-
Notifications
You must be signed in to change notification settings - Fork 1
SOC implemented #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const SPACE = /\s+/; | ||
export const TEMPERATURE_INPUT = 'temperatures'; | ||
export const CONVERT_TEMPERATURE_CONTAINER = 'convertedTemperatures'; | ||
export const MESSAGE_ERROR_NOT_INTEGER = | ||
"The '%S' contains values different of integer numbers"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
SPACE, | ||
TEMPERATURE_INPUT, | ||
CONVERT_TEMPERATURE_CONTAINER, | ||
MESSAGE_ERROR_NOT_INTEGER, | ||
} from './constants.js'; | ||
import convertedTemperature from './utils/utils.js'; | ||
|
||
const handlers = (event) => { | ||
debugger; // each time the user changes the 'temperatures' input | ||
|
||
const convertedTemperaturesContainer = document.getElementById( | ||
CONVERT_TEMPERATURE_CONTAINER, | ||
); | ||
|
||
// Erase previous content | ||
convertedTemperaturesContainer.innerHTML = ''; | ||
|
||
// Get the text input | ||
const fahrenheitTextList = event.target.value; | ||
|
||
let convertedTemp = convertedTemperaturesContainer.innerHTML; | ||
|
||
// Validate it | ||
if (fahrenheitTextList) { | ||
var convertedTempTextList = convertedTemperature(fahrenheitTextList); | ||
const convertedTemperaturesLst = ''; | ||
|
||
const convertedTempList = convertedTempTextList.trim().split(SPACE); | ||
|
||
convertedTempList.forEach((celsius) => { | ||
// Render the result | ||
const liString = `<li class="number-item">${celsius}</li>`; | ||
|
||
convertedTemp = convertedTemp + liString; | ||
}); | ||
|
||
convertedTemperaturesContainer.innerHTML = convertedTemp; | ||
} | ||
}; | ||
|
||
export default handlers; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,41 @@ | ||
debugger; // once when the program is initialized | ||
import listener from './listener.js'; | ||
|
||
document.getElementById('temperatures').addEventListener('change', (event) => { | ||
debugger; // each time the user changes the 'temperatures' input | ||
listener(); | ||
|
||
const convertedTemperaturesContainer = document.getElementById( | ||
'convertedTemperatures', | ||
); | ||
// document.getElementById(TEMPERATURE_INPUT).addEventListener('change', (event) => { | ||
// debugger; // each time the user changes the 'temperatures' input | ||
|
||
// Erase previous content | ||
convertedTemperaturesContainer.innerHTML = ''; | ||
// const convertedTemperaturesContainer = document.getElementById( | ||
// CONVERT_TEMPERATURE_CONTAINER | ||
// ); | ||
|
||
// Get the text input | ||
const fahrenheitTextList = event.target.value; | ||
// // Erase previous content | ||
// convertedTemperaturesContainer.innerHTML = ''; | ||
|
||
// Validade it | ||
if (fahrenheitTextList) { | ||
if (!/^[0-9\s]*$/.test(fahrenheitTextList)) { | ||
window.alert( | ||
`The '${fahrenheitTextList}' contains values different of integer numbers`, | ||
); | ||
} | ||
// // Get the text input | ||
// const fahrenheitTextList = event.target.value; | ||
|
||
// Sanitize it | ||
const fahrenheitList = fahrenheitTextList.trim().split(/\s+/); | ||
// // Validate it | ||
// if (fahrenheitTextList) { | ||
// if (!/^[0-9\s]*$/.test(fahrenheitTextList)) { | ||
// window.alert( | ||
// MESSAGE_ERROR_NOT_INTEGER, | ||
// ); | ||
// } | ||
|
||
fahrenheitList.forEach((fahrenheit) => { | ||
// Do the math | ||
const celsius = ((fahrenheit - 32) * 5) / 9; | ||
// // Sanitize it | ||
// const fahrenheitList = fahrenheitTextList.trim().split(SPACE); | ||
|
||
// Render the result | ||
const liString = `<li class="number-item">${celsius.toFixed(2)}</li>`; | ||
// fahrenheitList.forEach((fahrenheit) => { | ||
// // Do the math | ||
// const celsius = ((fahrenheit - 32) * 5) / 9; | ||
|
||
convertedTemperaturesContainer.innerHTML = | ||
convertedTemperaturesContainer.innerHTML + liString; | ||
}); | ||
} | ||
}); | ||
// // Render the result | ||
// const liString = `<li class="number-item">${celsius.toFixed(2)}</li>`; | ||
|
||
// convertedTemperaturesContainer.innerHTML = | ||
// convertedTemperaturesContainer.innerHTML + liString; | ||
// }); | ||
// } | ||
// }); |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,16 @@ | ||||||||||||
import handlers from './handlers.js'; | ||||||||||||
|
||||||||||||
import { | ||||||||||||
SPACE, | ||||||||||||
TEMPERATURE_INPUT, | ||||||||||||
CONVERT_TEMPERATURE_CONTAINER, | ||||||||||||
MESSAGE_ERROR_NOT_INTEGER, | ||||||||||||
Comment on lines
+4
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this file, only the
Suggested change
|
||||||||||||
} from './constants.js'; | ||||||||||||
|
||||||||||||
const listener = () => { | ||||||||||||
document | ||||||||||||
.getElementById(TEMPERATURE_INPUT) | ||||||||||||
.addEventListener('change', handlers); | ||||||||||||
}; | ||||||||||||
|
||||||||||||
export default listener; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,24 @@ | ||||||||||||||||||||||||
import { | ||||||||||||||||||||||||
SPACE, | ||||||||||||||||||||||||
TEMPERATURE_INPUT, | ||||||||||||||||||||||||
CONVERT_TEMPERATURE_CONTAINER, | ||||||||||||||||||||||||
MESSAGE_ERROR_NOT_INTEGER, | ||||||||||||||||||||||||
} from '../constants.js'; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export const convertedTemperature = (fahrenheitTextList) => { | ||||||||||||||||||||||||
if (!/^[0-9\s]*$/.test(fahrenheitTextList)) { | ||||||||||||||||||||||||
window.alert(MESSAGE_ERROR_NOT_INTEGER); | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You defined So, in the window.alert(MESSAGE_ERROR_NOT_INTEGER.replace('%S', fahrenheitTextList)); |
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
// Sanitize it | ||||||||||||||||||||||||
const fahrenheitList = fahrenheitTextList.trim().split(SPACE); | ||||||||||||||||||||||||
var convertedTemperatures = ''; | ||||||||||||||||||||||||
fahrenheitList.forEach((fahrenheit) => { | ||||||||||||||||||||||||
// Do the math | ||||||||||||||||||||||||
const celsius = ((fahrenheit - 32) * 5) / 9; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
convertedTemperatures = convertedTemperatures + ' ' + celsius.toFixed(2); | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
Comment on lines
+15
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use var. It is not recommeded anymore. Use let or const. Tip: use
Suggested change
|
||||||||||||||||||||||||
return convertedTemperatures; | ||||||||||||||||||||||||
}; | ||||||||||||||||||||||||
export default convertedTemperature; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { convertedTemperature } from './utils.js'; | ||
|
||
describe('convertedTemperature: fahrenheit converts into celsius', () => { | ||
it('should handle input with only spaces', () => { | ||
const returned = convertedTemperature('32'); | ||
expect(returned).toEqual(' 0.00'); | ||
}); | ||
|
||
it('should handle input with only spaces', () => { | ||
const returned = convertedTemperature('32 64 128'); | ||
expect(returned).toEqual(' 0.00 17.78 53.33'); | ||
}); | ||
}); |
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.
Don't use
var
. It is not recommeded anymore. Uselet
orconst
.