
package org.eclipse.birt.report.tests.viewer.regression;

import org.apache.cactus.WebRequest;
import org.eclipse.birt.report.servlet.ViewerServlet;
import org.eclipse.birt.report.tests.viewer.BaseViewerTestCase;

import com.meterware.httpunit.WebResponse;

/**
 * <b>Steps to reproduce:</b>
 * <ol>
 * <li>Create a report and add a label
 * <li>Edit this label by adding a TOC
 * <li>Preview in Web Viewer
 * <li>Click on "Show table of contents" button to display TOC page
 * </ol>
 * <b>Actual result:</b>
 * <p>
 * If I want to hide TOC page, I need to click on this button again
 * <p>
 * <b>Expected result:</b>
 * <p>
 * Something like "Hide table of contents" should be displayed
 * </p>
 * <b>Test description:</b>
 * <p>
 * Unclear screen tip, use "Toggle table of contents" instead
 * </p>
 */
public class Regression_123063 extends BaseViewerTestCase
{

	private final static String REPORT = "report/regression_123063.rptdesign";

	/**
	 * @param webRequest
	 * @throws Exception
	 */
	public void begin_regression_123063( WebRequest webRequest )
			throws Exception
	{
		webRequest.setURL( null, null, SERVLET_PATH_FRAMESET, null, null );
		webRequest.addParameter( PARAM_REPORT, REPORT );
	}

	/**
	 * test_regression_123063
	 */
	public void test_regression_123063( )
	{
		ViewerServlet servlet = new ViewerServlet( );
		try
		{
			servlet.init( config );
			servlet.doPost( request, response );
		}
		catch ( Exception e )
		{
			e.printStackTrace( );
			fail( e.toString( ) );
		}
	}

	/**
	 * @param webResponse
	 */
	public void end_regression_123063( WebResponse webResponse )
			throws Exception
	{
		String content = webResponse.getText( );

		String title = "TITLE=\"Toggle table of contents\"";
		int sIndex = content.indexOf( title );
		int eIndex = sIndex + title.length( );
		assertEquals( title, content.substring( sIndex, eIndex ) );

		sIndex = 0;
		eIndex = 0;

		String alt = "ALT=\"Toggle table of contents\"";
		sIndex = content.indexOf( alt );
		eIndex = sIndex + alt.length( );
		assertEquals( alt, content.substring( sIndex, eIndex ) );
	}

}