<commit_before>/* Copyright 2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package geb

import geb.test.util.*

class ModulesSpec extends GebSpecWithServer {

	def setupSpec() {
		server.get = { req, res ->
			res.outputStream << """
			<html>
			<body>
				<div class="a"><p>a</p></div>
				<div class="b"><p>a</p></div>
				<div class="c"><div class="d"><p>d</p></div></div>
			</body>
			</html>"""
		}
	}
	
	def "modules"() {
		when:
		to ModulesSpecPage
		then:
		divNoBase("a").p.text() == "a"
		divWithBase("a").p.text() == "a"
		divWithBaseAndSpecificBaseAndParam.p.text() == "d"
		divWithBaseAndSpecificBaseAndParam.p.text() == "d"
		divA.p.text() == "a"
		divC.innerDiv.p.text() == "d"
		divCWithRelativeInner.innerDiv.p.text() == "d"
	}
	
	def "call in mixed in method from TextMatchingSupport"() {
		when:
		to ModulesSpecPage
		then:
		"abc" ==~ divA.contains("b")
	}
}

class ModulesSpecPage extends Page {
	static content = {
		// A module that doesn't define a locator, given one at construction
		divNoBase { module ModulesSpecDivModuleNoLocator, $("div.$it") }
		
		// A module that defines a locator, given a param at construction
		divWithBase { module ModulesSpecDivModuleWithLocator, className: it }
		
		// A module that defines a location, and uses a param given at construction in the locator
		divWithBaseAndSpecificBaseAndParam { module ModulesSpecDivModuleWithLocator, $("div.c"), className: "d" }
		
		// A module that defines a location, and is contructed with no base or params
		divA { module ModulesSpecSpecificDivModule }
		
		// A module that itself has a module
		divC { module ModulesSpecDivModuleWithNestedDiv }
		
		// A module whose inner module is defined by the owner module's base
		divCWithRelativeInner { module ModulesSpecDivModuleWithNestedDivRelativeToModuleBase }
	}
}

class ModulesSpecDivModuleNoLocator extends Module {
	static content = {
		p { $("p") }
	}
}

class ModulesSpecDivModuleWithLocator extends Module {
	def className
	static base = { $("div.$className") }
	static content = {
		p { $("p") }
	}
}

class ModulesSpecSpecificDivModule extends Module {
	static base = { $("div.a") }
	static content = {
		p { $("p") }
	}
}

class ModulesSpecDivModuleWithNestedDiv extends Module {
	static base = { $("div.c") }
	static content = {
		innerDiv { module ModulesSpecDivModuleWithLocator, className: "d" }
	}
}

class ModulesSpecDivModuleWithNestedDivRelativeToModuleBase extends Module {
	static base = { $("div.c") }
	static content = {
		innerDiv { module ModulesSpecDivModuleWithLocator, $(), className: "d" }
	}
}<commit_msg>Test for a bad module base definition.<commit_after>/* Copyright 2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package geb

import geb.test.util.*
import geb.error.InvalidPageContent

class ModulesSpec extends GebSpecWithServer {

	def setupSpec() {
		server.get = { req, res ->
			res.outputStream << """
			<html>
			<body>
				<div class="a"><p>a</p></div>
				<div class="b"><p>a</p></div>
				<div class="c"><div class="d"><p>d</p></div></div>
			</body>
			</html>"""
		}
	}
	
	def "modules"() {
		when:
		to ModulesSpecPage
		then:
		divNoBase("a").p.text() == "a"
		divWithBase("a").p.text() == "a"
		divWithBaseAndSpecificBaseAndParam.p.text() == "d"
		divWithBaseAndSpecificBaseAndParam.p.text() == "d"
		divA.p.text() == "a"
		divC.innerDiv.p.text() == "d"
		divCWithRelativeInner.innerDiv.p.text() == "d"
	}
	
	def "call in mixed in method from TextMatchingSupport"() {
		when:
		to ModulesSpecPage
		then:
		"abc" ==~ divA.contains("b")
	}
	
	def "module base must return a navigator"() {
		when:
		to ModulesSpecPage
		badBase
		then:
		thrown(InvalidPageContent)
	}
}

class ModulesSpecPage extends Page {
	static content = {
		// A module that doesn't define a locator, given one at construction
		divNoBase { module ModulesSpecDivModuleNoLocator, $("div.$it") }
		
		// A module that defines a locator, given a param at construction
		divWithBase { module ModulesSpecDivModuleWithLocator, className: it }
		
		// A module that defines a location, and uses a param given at construction in the locator
		divWithBaseAndSpecificBaseAndParam { module ModulesSpecDivModuleWithLocator, $("div.c"), className: "d" }
		
		// A module that defines a location, and is contructed with no base or params
		divA { module ModulesSpecSpecificDivModule }
		
		// A module that itself has a module
		divC { module ModulesSpecDivModuleWithNestedDiv }
		
		// A module whose inner module is defined by the owner module's base
		divCWithRelativeInner { module ModulesSpecDivModuleWithNestedDivRelativeToModuleBase }
		
		badBase { module ModulesSpecBadBase }
	}
}

class ModulesSpecDivModuleNoLocator extends Module {
	static content = {
		p { $("p") }
	}
}

class ModulesSpecDivModuleWithLocator extends Module {
	def className
	static base = { $("div.$className") }
	static content = {
		p { $("p") }
	}
}

class ModulesSpecSpecificDivModule extends Module {
	static base = { $("div.a") }
	static content = {
		p { $("p") }
	}
}

class ModulesSpecDivModuleWithNestedDiv extends Module {
	static base = { $("div.c") }
	static content = {
		innerDiv { module ModulesSpecDivModuleWithLocator, className: "d" }
	}
}

class ModulesSpecDivModuleWithNestedDivRelativeToModuleBase extends Module {
	static base = { $("div.c") }
	static content = {
		innerDiv { module ModulesSpecDivModuleWithLocator, $(), className: "d" }
	}
}

class ModulesSpecBadBase extends Module {
	static base = { 1 }
}
{'fraction_non_alphanumeric': 0.11675281240498632, 'fraction_numerical': 0.002584372149589541, 'mean_word_length': 3.9060402684563758, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3859494', 'n_tokens_mistral': 2238, 'n_tokens_neox': 2058, 'n_words': 643}