<commit_before>package grails.plugins.selenium.test.pageobjects

import grails.plugins.selenium.test.Song
import grails.plugins.selenium.pageobjects.GrailsEditPage
import org.junit.Before
import org.junit.Before
import org.junit.Test
import static org.junit.Assert.*
import static org.hamcrest.CoreMatchers.*
import static org.junit.matchers.JUnitMatchers.*
import org.junit.After
import org.junit.AfterClass
import org.hamcrest.Matcher

class EditSongTests {

	def id

	@Before void setUp() {
		Song.withTransaction {
			Song.withSession {session ->
				def song = Song.build(title: "Rockers To Swallow", artist: "Yeah Yeah Yeahs")
				id = song.id
				session.clear()
			}
		}
	}

	@After void tearDown() {
		Song.withTransaction {
			Song.list()*.delete()
		}
	}

	@Test void cannotRemoveTitleOrArtist() {
		GrailsEditPage editPage = GrailsEditPage.open("/song/edit/$id")
		editPage.title = ""
		editPage.artist = ""

		editPage = editPage.saveExpectingFailure()

		assertThat editPage.errorMessages, hasItem("Title cannot be blank")
		assertThat editPage.errorMessages, hasItem("Artist cannot be blank")

		assertTrue "title field should be highlighted", editPage.hasFieldErrors("title")
		assertTrue "artist field should be highlighted", editPage.hasFieldErrors("artist")
	}

	@Test void addAlbumAndDurationToSong() {
		GrailsEditPage editPage = GrailsEditPage.open("/song/edit/$id")
		editPage.album = "Is Is (EP)"
		editPage.durationSeconds = "193"

		def showPage = editPage.save()

		assertThat showPage.flashMessage, equalTo("Song $id updated")
		def song = Song.read(id)
		assertThat song.album, equalTo("Is Is (EP)")
		assertThat song.durationSeconds, equalTo(193)
	}

	@Test void deleteSong() {
		GrailsEditPage editPage = GrailsEditPage.open("/song/edit/$id")

		def listPage = editPage.delete()

		assertThat listPage.flashMessage, equalTo("Song $id deleted")
		assertThat "Song list is not empty", listPage.rowCount, equalTo(0)
		assertThat "Song has not been deleted from the database", Song.count(), equalTo(0)
	}

	static Matcher<String> equalTo(GString expected) {
		equalTo(expected as String)
	}
}<commit_msg>workaround fact that equalTo(GString) does not work on a String target<commit_after>package grails.plugins.selenium.test.pageobjects

import grails.plugins.selenium.test.Song
import grails.plugins.selenium.pageobjects.GrailsEditPage
import org.junit.Before
import org.junit.Before
import org.junit.Test
import static org.junit.Assert.*
import static org.hamcrest.CoreMatchers.*
import static org.junit.matchers.JUnitMatchers.*
import org.junit.After
import org.junit.AfterClass
import org.hamcrest.Matcher
import org.hamcrest.BaseMatcher
import org.hamcrest.Description
import grails.plugins.selenium.pageobjects.GrailsPage

class EditSongTests {

	def id

	@Before
	void setUp() {
		Song.withTransaction {
			Song.withSession {session ->
				def song = Song.build(title: "Rockers To Swallow", artist: "Yeah Yeah Yeahs")
				id = song.id
				session.clear()
			}
		}
	}

	@After
	void tearDown() {
		Song.withTransaction {
			Song.list()*.delete()
		}
	}

	@Test
	void cannotRemoveTitleOrArtist() {
		GrailsEditPage editPage = GrailsEditPage.open("/song/edit/$id")
		editPage.title = ""
		editPage.artist = ""

		editPage = editPage.saveExpectingFailure()

		assertThat "Error messages", editPage.errorMessages, hasItems("Title cannot be blank", "Artist cannot be blank")

		assertTrue "Title field should be highlighted", editPage.hasFieldErrors("title")
		assertTrue "Artist field should be highlighted", editPage.hasFieldErrors("artist")
	}

	@Test
	void addAlbumAndDurationToSong() {
		GrailsEditPage editPage = GrailsEditPage.open("/song/edit/$id")
		editPage.album = "Is Is (EP)"
		editPage.durationSeconds = "193"

		def showPage = editPage.save()

		assertThat "Flash message", showPage.flashMessage, equalTo("Song $id updated" as String)
		def song = Song.read(id)
		assertThat "Song album name", song.album, equalTo("Is Is (EP)")
		assertThat "Song duration", song.durationSeconds, equalTo(193)
	}

	@Test
	void deleteSong() {
		GrailsEditPage editPage = GrailsEditPage.open("/song/edit/$id")

		def listPage = editPage.delete()

		assertThat "Flash message", listPage.flashMessage, equalTo("Song $id deleted" as String)
		assertThat "Song list size", listPage.rowCount, equalTo(0)
		assertThat "Song entity count", Song.count(), equalTo(0)
	}
}
{'fraction_non_alphanumeric': 0.11399908800729594, 'fraction_numerical': 0.00364797081623347, 'mean_word_length': 4.764783180026281, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6653272', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1374, 'n_words': 343}