You need to sign in to do that
Don't have an account?
angela mullen-smith 18
trailhead challenge - build a conference app - writing a test class for the Controller extension
I have build the app, written the controller and visualforce page and mapped the hotels onto a google map.
I need to write a test class for the HotelRemoter extension and I am getting myself confused as I am not sure how to write it
This is the Test class
1
2
3
4
5
6
7
global with sharing class HotelRemoter {
@RemoteAction
global static List<Hotel__c> findAll() {
return [SELECT Id, Name, Location__Latitude__s, Location__Longitude__s
FROM Hotel__c];
}
}
This is the Visualforce page
<apex:page sidebar="false" showheader="false" controller="HotelRemoter">
<head>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script src="https://maps.googleapis.com/maps/api/js?key= AIzaSyC3GwkxsiGHfc0y5sheupDf7QzKtbFI4jg&sensor=false">
</script>
<script>
var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(37.784173, -122.401557),
zoom: 15
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
loadHotels();
}
function loadHotels() {
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.HotelRemoter.findAll}',
function(result, event){
if (event.status) {
for (var i=0; i<result.length; i++) {
var id = result[i].Id;
var name = result[i].Name;
var lat = result[i].Location__Latitude__s;
var lng = result[i].Location__Longitude__s;
addMarker(id, name, lat, lng);
}
} else {
alert(event.message);
}
},
{escape: true}
);
}
function addMarker(id, name, lat, lng) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: map,
title: name
});
google.maps.event.addListener(marker, 'click', function(event) {
window.top.location = '/' + id;
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"/>
</body>
</apex:page>
I don't quite understand how to write a test this controller.
I need to write a test class for the HotelRemoter extension and I am getting myself confused as I am not sure how to write it
This is the Test class
1
2
3
4
5
6
7
global with sharing class HotelRemoter {
@RemoteAction
global static List<Hotel__c> findAll() {
return [SELECT Id, Name, Location__Latitude__s, Location__Longitude__s
FROM Hotel__c];
}
}
This is the Visualforce page
<apex:page sidebar="false" showheader="false" controller="HotelRemoter">
<head>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script src="https://maps.googleapis.com/maps/api/js?key= AIzaSyC3GwkxsiGHfc0y5sheupDf7QzKtbFI4jg&sensor=false">
</script>
<script>
var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(37.784173, -122.401557),
zoom: 15
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
loadHotels();
}
function loadHotels() {
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.HotelRemoter.findAll}',
function(result, event){
if (event.status) {
for (var i=0; i<result.length; i++) {
var id = result[i].Id;
var name = result[i].Name;
var lat = result[i].Location__Latitude__s;
var lng = result[i].Location__Longitude__s;
addMarker(id, name, lat, lng);
}
} else {
alert(event.message);
}
},
{escape: true}
);
}
function addMarker(id, name, lat, lng) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: map,
title: name
});
google.maps.event.addListener(marker, 'click', function(event) {
window.top.location = '/' + id;
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"/>
</body>
</apex:page>
I don't quite understand how to write a test this controller.
https://salesforce.stackexchange.com/questions/103732/how-to-call-create-test-class-for-a-remoteaction