-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dierk Koenig
committed
Nov 21, 2023
1 parent
01d7db6
commit cca228b
Showing
3 changed files
with
111 additions
and
0 deletions.
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
41 changes: 41 additions & 0 deletions
41
src/integration-test/groovy/rooms/JSTempConverterSpec.groovy
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,41 @@ | ||
package rooms | ||
|
||
import geb.spock.GebSpec | ||
import grails.testing.mixin.integration.Integration | ||
|
||
/** | ||
* See http://www.gebish.org/manual/current/ for more instructions | ||
*/ | ||
@Integration | ||
class JSTempConverterSpec extends GebSpec { | ||
|
||
void "From celsius to fahrenheit with JavaScript"() { | ||
when: | ||
go '/static/Temperatures.html' | ||
then: | ||
title == "Temperature Converter with JavaScript" | ||
|
||
when: "set celsius without button clicking" | ||
$("form").celsius = "10" | ||
$("form").fahrenheit().click() | ||
|
||
then: "the other field is updated immediately" | ||
$("form").fahrenheit == "50" | ||
} | ||
|
||
void "From fahrenheit to celsius with JavaScript"() { | ||
when: | ||
go '/static/Temperatures.html' | ||
then: | ||
title == "Temperature Converter with JavaScript" | ||
|
||
when: "set fahrenheit without button clicking" | ||
$("form").fahrenheit = "16" | ||
$("form").celsius().click() | ||
|
||
then: "the other field is updated immediately" | ||
$("form").celsius == "-9" | ||
} | ||
|
||
|
||
} |
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,69 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<title> | ||
Temperature Converter with JavaScript | ||
</title> | ||
<style> | ||
main { | ||
margin: 2rem; | ||
font-family: "Helvetica Neue Light", sans-serif; | ||
letter-spacing: .05em; | ||
} | ||
h2 { | ||
color: hsl(240 60% 60% ); | ||
} | ||
.converter-grid { | ||
display: grid; | ||
grid-template-columns: max-content 6ch; | ||
gap: 0.5em 2em; | ||
margin-left: 2rem; | ||
} | ||
input[type=number] { | ||
text-align: right; | ||
border: 1px solid lightgray; | ||
} | ||
</style> | ||
<script> | ||
function celsiusToFahrenheit(celsius) { | ||
return Math.floor(celsius * 1.8 + 32); | ||
} | ||
function fahrenheitToCelsius(fahrenheit) { | ||
return Math.floor((fahrenheit - 32) / 1.8); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<main> | ||
<h2> | ||
Temperature Converter with JavaScript | ||
</h2> | ||
|
||
<form class="converter-grid"> | ||
|
||
<label for='celsius'>Celsius</label> | ||
<input | ||
autofocus | ||
id = "celsius" | ||
name = "celsius" | ||
type = "number" | ||
step = "1" | ||
value = "0" | ||
onchange= "document.getElementById('fahrenheit').value = celsiusToFahrenheit(value);" | ||
> | ||
|
||
<label for='fahrenheit'>Fahrenheit</label> | ||
<input | ||
id = "fahrenheit" | ||
name = "fahrenheit" | ||
type = "number" | ||
step = "1" | ||
value = "32" | ||
onchange= "document.getElementById('celsius').value = fahrenheitToCelsius(value);" | ||
> | ||
|
||
</form> | ||
</main> | ||
</body> | ||
</html> |