/**
* This file is part of JSurveyLib.
*
* JSurveyLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JSurveyLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JSurveyLib. If not, see <http://www.gnu.org/licenses/>.
**/
package org.jsurveylib.model;
import org.jsurveylib.Survey;
import org.jsurveylib.model.listeners.LinkListener;
import org.jsurveylib.io.XMLSurveyReader;
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.File;
/**
* User: tieTYT
*/
public class LabelTest implements LinkListener {
private String url;
@Test
public void cdata() throws Exception {
Survey m = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\labelfiles\\cdata.xml")));
Label l = (Label) m.getCurrentPage().getSurveyElements().get(0);
assertEquals("There is a \"visibility script\" on this page that is making a checkbox invisible right now. To make the checkbox visible, type the magic word into this text field. The magic word is <b>please</b>", l.getText());
}
@Test
public void linkClicked() throws Exception {
Survey m = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\labelfiles\\linkclicked.xml")));
Label l = (Label) m.getCurrentPage().getSurveyElements().get(0);
l.addLinkListener(this);
assertNull(url);
l.linkClicked("blah");
assertEquals("blah", url);
assertEquals(0, m.getCurrentPageNumber());
l.linkClicked("page://1");
assertEquals("page://1", url);
assertEquals(1, m.getCurrentPageNumber());
assertFalse(m.isLastPageAndComplete()); //a mandatory question is not answered
l.linkClicked("page://0");
assertEquals("page://0", url);
assertEquals(0, m.getCurrentPageNumber());
m.getQuestionByID("pageJump").getLabel().linkClicked("page://1");
l.linkClicked("page://1");
assertEquals("page://1", url);
}
@Test(expected = java.lang.IndexOutOfBoundsException.class)
public void badPageLink() throws Exception {
Survey m = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\labelfiles\\badpagelink.xml")));
Label l = (Label) m.getCurrentPage().getSurveyElements().get(0);
l.linkClicked("page://2");
}
public void onClick(String url) {
this.url = url;
}
}