forked from HackYourFutureBelgium/separation-of-concerns
-
Notifications
You must be signed in to change notification settings - Fork 1
test code for review #3
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
Open
Smita81
wants to merge
5
commits into
master
Choose a base branch
from
flip-book
base: master
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
5 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 hidden or 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"liveServer.settings.port": 5501 | ||
"liveServer.settings.port": 5501, | ||
"cSpell.words": [ | ||
"nums" | ||
] | ||
} |
This file contains hidden or 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,14 @@ | ||
export const INITIAL_STATE = { | ||
currentNumber: 0, | ||
allNumbers: [], | ||
}; | ||
|
||
export const EVENTS = { | ||
NEXT_NUMBER_CHANGE: 'next-number', | ||
MOUSE_OVER_HISTORY: 'number-history', | ||
}; | ||
|
||
export const HTML_CLASSES = { | ||
NUMBER_ITEM: 'number-item', | ||
}; | ||
|
This file contains hidden or 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,6 @@ | ||
|
||
const state = { | ||
currentNumber: 0, | ||
allNumbers: [], | ||
}; | ||
export default state; |
This file contains hidden or 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,25 @@ | ||
import { INITIAL_STATE, EVENTS, HTML_CLASSES } from './data/constants.js'; | ||
const handlers = (event) => { | ||
const backwardsContainer = document.getElementById(EVENTS.MOUSE_OVER_HISTORY); | ||
|
||
/*const eventsNextNumberChange = document.getElementById(EVENTS.NEXT_NUMBER_CHANGE,); | ||
// Handler logic for when the user changes the 'next-number' input | ||
|
||
const eventsMouseOverHistory = document.getElementById(EVENTS.MOUSE_OVER_HISTORY,); | ||
// Handler logic for when the user moves the mouse over 'number-history' | ||
*/ | ||
const nextNumber = Number(inputValue); | ||
|
||
// --- update state --- | ||
state.allNumbers.push(nextNumber); | ||
state.currentNumber = state.allNumbers.at(-1); | ||
const targetText = event.target.innerText; | ||
|
||
backwardsContainer.innerHTML = liString + backwardsContainer.innerHTML; | ||
|
||
if (event.target.nodeName !== 'LI') { | ||
return; | ||
}; | ||
|
||
const liString = `<li class="number-item">${state.currentNumber}</li>`; | ||
}; |
This file contains hidden or 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
This file contains hidden or 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 @@ | ||
import handlers from './handlers.js' | ||
import { INITIAL_STATE, EVENTS, HTML_CLASSES } from './data/constants.js'; | ||
|
||
const listener = () => { | ||
document.getElementById(EVENTS.NEXT_NUMBER_CHANGE).addEventListener('change', handlers); | ||
}; | ||
|
||
export default listener; | ||
|
This file contains hidden or 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,7 @@ | ||
import { INITIAL_STATE, EVENTS, HTML_CLASSES } from './data/constants.js'; | ||
|
||
|
||
// --- read the user's input --- | ||
const inputValue = event.target.value; | ||
const nextNumber = Number(inputValue); | ||
|
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,3 @@ | ||
export const REVERSE_INPUT = 'input'; | ||
export const REVERSED_OUTPUT = 'output'; | ||
export const KEY_UP = 'key-up'; |
Empty file.
17 changes: 15 additions & 2 deletions
17
6-refactoring/exercises/dom-and-events/flip-book/src/handler.js
This file contains hidden or 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 |
---|---|---|
@@ -1,3 +1,16 @@ | ||
// import { reverseAndUpper } from './utils.js'; | ||
import { reverseAndUpper } from './util.js'; | ||
|
||
export const reverseAndUpperHandler = _; | ||
export const reverseAndUpperHandler = (event) => { | ||
|
||
debugger; | ||
// read and process user input | ||
const input = event.target.value; | ||
|
||
const reversedUppercase = reverseAndUpper(input); | ||
document.getElementById(REVERSED_OUTPUT).innerHTML = reversedUppercase; | ||
|
||
// log result for developers | ||
console.log('\n --- user action ---'); | ||
console.log('REVERSE_INPUT', input); | ||
console.log('reversedUppercase:', reversedUppercase); | ||
}; |
24 changes: 14 additions & 10 deletions
24
6-refactoring/exercises/dom-and-events/flip-book/src/init.js
This file contains hidden or 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 |
---|---|---|
@@ -1,19 +1,23 @@ | ||
document.getElementById('input').addEventListener('keyup', (event) => { | ||
import { REVERSE_INPUT, KEY_UP, REVERSED_OUTPUT} from '../data/constants.js'; | ||
|
||
|
||
import './listener.js'; | ||
// listener | ||
//document.getElementById(REVERSE_INPUT).addEventListener('keyup', | ||
|
||
/* handler | ||
|
||
(event) => { | ||
debugger; | ||
// read and process user input | ||
const input = event.target.value; | ||
|
||
// execute core logic | ||
|
||
// util | ||
const upperCased = input.toUpperCase(); | ||
const splitted = upperCased.split(''); | ||
const reversed = splitted.reverse(); | ||
const reversedUppercase = reversed.join(''); | ||
|
||
const reversedUppercase = reversed.join('');*/ | ||
// | ||
// render result for user | ||
document.getElementById('output').innerHTML = reversedUppercase; | ||
|
||
// log result for developers | ||
console.log('\n --- user action ---'); | ||
console.log('input:', input); | ||
console.log('reversedUppercase:', reversedUppercase); | ||
}); |
5 changes: 4 additions & 1 deletion
5
6-refactoring/exercises/dom-and-events/flip-book/src/listener.js
This file contains hidden or 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 |
---|---|---|
@@ -1 +1,4 @@ | ||
// import { reverseAndUpperHandler } from './handler.js'; | ||
import { reverseAndUpperHandler } from './handler.js'; | ||
|
||
|
||
document.getElementById(REVERSE_INPUT).addEventListener(KEY_UP, reverseAndUpperHandler); |
13 changes: 9 additions & 4 deletions
13
6-refactoring/exercises/dom-and-events/flip-book/src/util.js
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,9 @@ | ||
/** | ||
* | ||
*/ | ||
export const reverseAndUpper = () => {}; | ||
|
||
|
||
export const reverseAndUpper = (input) => { | ||
const upperCased = input.toUpperCase(); | ||
const splitted = upperCased.split(''); | ||
const reversed = splitted.reverse(); | ||
const reversedUppercase = reversed.join(''); | ||
return reversedUppercase; | ||
}; |
2 changes: 1 addition & 1 deletion
2
6-refactoring/exercises/dom-and-events/flip-book/src/util.spec.js
This file contains hidden or 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
This file contains hidden or 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,4 @@ | ||
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'; |
This file contains hidden or 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,31 @@ | ||
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; |
This file contains hidden or 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 |
---|---|---|
@@ -1,38 +1,3 @@ | ||
debugger; // once when the program is initialized | ||
|
||
document.getElementById('temperatures').addEventListener('change', (event) => { | ||
debugger; // each time the user changes the 'temperatures' input | ||
|
||
const convertedTemperaturesContainer = document.getElementById( | ||
'convertedTemperatures', | ||
); | ||
|
||
// Erase previous content | ||
convertedTemperaturesContainer.innerHTML = ''; | ||
|
||
// Get the text input | ||
const fahrenheitTextList = event.target.value; | ||
|
||
// Validade it | ||
if (fahrenheitTextList) { | ||
if (!/^[0-9\s]*$/.test(fahrenheitTextList)) { | ||
window.alert( | ||
`The '${fahrenheitTextList}' contains values different of integer numbers`, | ||
); | ||
} | ||
|
||
// Sanitize it | ||
const fahrenheitList = fahrenheitTextList.trim().split(/\s+/); | ||
|
||
fahrenheitList.forEach((fahrenheit) => { | ||
// Do the math | ||
const celsius = ((fahrenheit - 32) * 5) / 9; | ||
|
||
// Render the result | ||
const liString = `<li class="number-item">${celsius.toFixed(2)}</li>`; | ||
|
||
convertedTemperaturesContainer.innerHTML = | ||
convertedTemperaturesContainer.innerHTML + liString; | ||
}); | ||
} | ||
}); | ||
import listener from './listener.js'; | ||
listener(); |
This file contains hidden or 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 @@ | ||
import handlers from './handlers.js'; | ||
import {SPACE,TEMPERATURE_INPUT,CONVERT_TEMPERATURE_CONTAINER,MESSAGE_ERROR_NOT_INTEGER, | ||
} from './constants.js'; | ||
const listener = () => { | ||
document | ||
.getElementById(TEMPERATURE_INPUT) | ||
.addEventListener('change', handlers); | ||
}; | ||
export default listener; |
This file contains hidden or 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,21 @@ | ||
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.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); | ||
}); | ||
return convertedTemperatures; | ||
}; | ||
export default convertedTemperature; |
This file contains hidden or 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,11 @@ | ||
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'); | ||
}); | ||
}); |
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.
Don't use var. It is not recommeded anymore. Use let or const.
Tip: use
map
andjoin
functions. This will avoid the empty space at the beginning of the returned convertedTemperatures.