summaryrefslogtreecommitdiff
path: root/tests/unit-tests/searchbar/searchbar-tests.js
blob: 27f5752d3c9a9663ff0198f06c032a99b7a77dc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Unit Test: Searchbar list
 *
 * Wongi Lee <wongi11.lee@samsung.com>
 */

$( document ).ready( function () {

	module( "Searchbar" );

	// trigger pagecreate
	$( "#searchbar-unit-test" ).page();

	asyncTest( "Searchbar", function () {
		/* Initialize */
		var $divSearchbar = $( "div.input-search-bar" ),
			$input = $( "input" );

		equal( $divSearchbar.length, 1, "initialized" );
		equal( $divSearchbar.find( "div.ui-input-search" ).length, 1 );
		equal( $divSearchbar.find( "div.ui-input-search input.ui-input-text" ).length, 1 );
		equal( $divSearchbar.find( "div.ui-input-search a.ui-input-clear" ).hasClass( "ui-input-clear-hidden" ), true );
		equal( $divSearchbar.find( "div.ui-input-search div.ui-image-search" ).length, 1 );
		equal( $divSearchbar.find( "a.ui-input-cancel" ).hasClass( "ui-btn" ), true );
		equal( $divSearchbar.find( "a.ui-input-cancel" ).hasClass( "ui-btn-icon-cancel" ), true );
		equal( $("#searchbar-content p").filter( function ( index ) {
			return $( this ).css( "display" ) != "none";
		} ).length, 30 );

		/* Public Method */
		/* disable */
		$( "#searchInput" ).searchbar( "disable" );
		equal( $( "div.ui-input-search" ).hasClass( "ui-disabled" ), true, "disable" );
		equal( $( "#searchInput" ).attr( "disabled" ), "disabled" );

		/* enable */
		$( "#searchInput" ).searchbar( "enable" );
		equal( $( "div.ui-input-search" ).hasClass( "ui-disabled" ), false, "enable" );
		equal( $( "#searchInput" ).attr( "disabled" ), undefined );

		/* Event */
		/* Search : Input and trigger change */
		$input.focus();
		equal( $( "div.ui-image-search" ).css( "display" ), "none", "Input and trigger change" );

		$input.val( "a" ).trigger( "change" );

		equal( $("#searchbar-content p").filter( function ( index ) {
			return $( this ).css( "display" ) != "none";
		} ).length, 24 );

		$input.val( "ar" ).trigger( "change" );
		equal( $("#searchbar-content p").filter( function ( index ) {
			return $( this ).css( "display" ) != "none";
		} ).length, 10 );

		$input.val( "are" ).trigger( "change" );
		equal( $("#searchbar-content p").filter( function ( index ) {
			return $( this ).css( "display" ) != "none";
		} ).length, 1 );

		/* Clear button preesed. */
		$( "a.ui-input-clear" ).trigger( "click" );
		equal( $("#searchbar-content p").filter( function ( index ) {
			return $( this ).css( "display" ) != "none";
		} ).length, 30 );

		equal( $divSearchbar.find( "div.ui-input-search a.ui-input-clear" ).hasClass( "ui-input-clear-hidden" ), true, "Clear button pressed" );
		equal( $divSearchbar.find( "a.ui-input-cancel" ).hasClass( "ui-btn" ), true );
		equal( $divSearchbar.find( "a.ui-input-cancel" ).hasClass( "ui-btn-icon-cancel" ), true );

		/* Cancel button pressed. */
		$( "a.ui-btn-icon-cancel" ).trigger( "click" );
		notEqual( $( "div.ui-image-search" ).css( "display" ), "none" );

		start();
	} );
} );