diff --git a/.gitignore b/.gitignore index b02282f5..8059c686 100644 --- a/.gitignore +++ b/.gitignore @@ -444,4 +444,3 @@ target/test-reports/plain/TEST-functional-cucumber-orientations-out.txt target/test-reports/plain/TEST-functional-cucumber-orientations.txt - diff --git a/chromedrivers/chromedriver b/chromedrivers/chromedriver new file mode 100755 index 00000000..70151ce7 Binary files /dev/null and b/chromedrivers/chromedriver differ diff --git a/chromedrivers/chromedriverwindowsx86.exe b/chromedrivers/chromedriverwindowsx86.exe new file mode 100644 index 00000000..c6c7761c Binary files /dev/null and b/chromedrivers/chromedriverwindowsx86.exe differ diff --git a/grails-app/controllers/rgms/news/NewsController.groovy b/grails-app/controllers/rgms/news/NewsController.groovy index 9b20923b..6c439bc4 100644 --- a/grails-app/controllers/rgms/news/NewsController.groovy +++ b/grails-app/controllers/rgms/news/NewsController.groovy @@ -36,7 +36,7 @@ class NewsController { flash.message = message(code: 'default.deleted.message', args: [message(code: 'news.label', default: 'News'), params.id]) redirect(action: "list") } - catch (DataIntegrityViolationException e) { + catch (DataIntegrityViolationException ignored) { flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'news.label', default: 'News'), params.id]) redirect(action: "show", id: params.id) } @@ -44,7 +44,7 @@ class NewsController { def save = { if (!grailsApplication.config.grails.mail.username) { - throw new RuntimeException(message(code: 'mail.plugin.not.configured', 'default': 'Mail plugin not configured')) + throw new RuntimeException(message(code: 'mail.plugin.not.configured', 'default': 'Mail plugin not configured') as Throwable) } def newsInstance = new News(params) @@ -81,7 +81,6 @@ class NewsController { if (!newsInstance.save(flush: true)) { render(view: "create", model: [newsInstance: newsInstance]) - return } } diff --git a/test/cucumber/News.feature b/test/cucumber/News.feature index ad2afbf3..2474f55c 100644 --- a/test/cucumber/News.feature +++ b/test/cucumber/News.feature @@ -38,4 +38,35 @@ Feature: news Given the research group "SPG" in the system has a Twitter account "@HumanBrainProj" associated And twitter account associated with "SPG" research group has been updated once When I request to update the news from Twitter to research group "SPG" - Then there is no duplicated news in Twitter account associated with research group "SPG" \ No newline at end of file + Then there is no duplicated news in Twitter account associated with research group "SPG" + + + Scenario: new news web + Given I am at the publications menu + When I select the "News" option at the publications menu + And I select the novo noticias option at the news page + Then I can fill the news details + + + Scenario: new invalid news (Description blank) + Given the system has no news with description "" and date "17-12-2013" for "SPG" research group + When I create a news with description "" and date "17-12-2013" for "SPG" research group + Then the news with description "", date "17-12-2013" and "SPG" research group is not stored by the system because it is invalid + + + Scenario: edit existing news + Given the system has a news with description "noticiaTeste" and date "07-04-2012" for "SPG" research group + When I edit the news with description "noticiaTeste" to "newDescription", date "07-04-2012" and "SPG" research group + Then the news "newDescription", date "07-04-2012" and "SPG" research group is properly updated by the system + + Scenario: remove existing news web + Given I am at the publications menu + When I select the news page and the new "Noticia1" is stored in the system + And I select to view new "Noticia1" in resulting list + And I select the option to remove in news show page + Then the new "Noticia1" is properly removed by the system + + Scenario: new invalid news (invalid date) + Given the system has no news with description "teste" and date "31-02-2013" for "SPG" research group + When I create a news with description "teste" and date "31-02-2013" for "SPG" research group + Then the news with description "teste", date "31-02-2013" and "SPG" research group is not stored by the system because it is invalid diff --git a/test/cucumber/steps/NewsSteps.groovy b/test/cucumber/steps/NewsSteps.groovy index 59893ce9..f851afea 100644 --- a/test/cucumber/steps/NewsSteps.groovy +++ b/test/cucumber/steps/NewsSteps.groovy @@ -1,3 +1,4 @@ +import pages.LoginPage import pages.PublicationsPage import pages.ResearchGroup.ResearchGroupCreatePage import pages.news.NewsCreatePage @@ -6,6 +7,7 @@ import rgms.member.ResearchGroup import rgms.news.News import steps.TestDataAndOperations import steps.NewsTestDataAndOperations +import pages.news.NewsShowPage import static cucumber.api.groovy.EN.* @@ -14,9 +16,11 @@ Given(~'^the system has no news with description "([^"]*)" and date "([^"]*)" fo } When(~'^I create a news with description "([^"]*)" and date "([^"]*)" for "([^"]*)" research group$') { String description, String date, String group -> - Date dateAsDateObj = Date.parse("dd-MM-yyyy", date) - def researchGroup = ResearchGroup.findByName(group) - NewsTestDataAndOperations.createNews(description, dateAsDateObj, researchGroup) + if(NewsTestDataAndOperations.checkValidDate(date)) { + Date dateAsDateObj = Date.parse("dd-MM-yyyy", date) + def researchGroup = ResearchGroup.findByName(group) + NewsTestDataAndOperations.createNews(description, dateAsDateObj, researchGroup) + } } Then(~'^the news with description "([^"]*)", date "([^"]*)" and "([^"]*)" research group is properly stored by the system$') { String description, String date, String group -> @@ -151,4 +155,66 @@ Then(~'^The system generate a HTML report with the news "([^"]*)" in it$'){ Stri Then(~'^I can not select the option Export to HTML at the News list page$'){ -> assert !page.canSelectExportHTMLReport() } -//#end \ No newline at end of file +//#end + + +When(~'^I select the novo noticias option at the news page$') {-> + selectNovoNoticiasInNewsPage() +} + +def selectNovoNoticiasInNewsPage(){ + + at NewsPage + page.selectCreateNews() + at NewsCreatePage + +} + +Then(~'^I can fill the news details$') { -> + at NewsCreatePage + page.fillNewDetails("essa eh a descricao") +} + +Then(~'^the news with description "([^"]*)", date "([^"]*)" and "([^"]*)" research group is not stored by the system because it is invalid$') { String description, String date, String group -> + Date dateAsDateObj = Date.parse("dd-MM-yyyy", date) + def researchGroup = ResearchGroup.findByName(group) + news = News.findByDescriptionAndDateAndResearchGroup(description, dateAsDateObj, researchGroup) + assert news == null +} + +When(~'^I edit the news with description "([^"]*)" to "([^"]*)", date "([^"]*)" and "([^"]*)" research group$') { String description, String newDescr, String date, String group -> + Date dateAsDateObj = Date.parse("dd-MM-yyyy", date) + def researchGroup = ResearchGroup.findByName(group) + NewsTestDataAndOperations.editNewsDescription(description, newDescr, dateAsDateObj, researchGroup) +} + +Then(~'^the news "([^"]*)", date "([^"]*)" and "([^"]*)" research group is properly updated by the system$') { String description, String date, String group -> + assert NewsTestDataAndOperations.checkExistingNews(description,date,group) +} + + +Given(~'^I select the news page and the new "([^"]*)" is stored in the system$') { String description -> + page.select("News") + selectNovoNoticiasInNewsPage() + + at NewsCreatePage + page.fillNewDetails(description) + page.clickOnCreate(); + + to NewsPage + at NewsPage +} + +When(~'^I select to view new "([^"]*)" in resulting list$') { String title -> + page.selectViewNew(title) + to NewsShowPage +} + +And(~'I select the option to remove in news show page$') {-> + to NewsShowPage + page.select('input', 'remove') +} + +Then(~'^the new "([^"]*)" is properly removed by the system$') { String description -> + assert !NewsTestDataAndOperations.checkExistingNewsByDescription(description) +} \ No newline at end of file diff --git a/test/functional/pages/news/NewsPage.groovy b/test/functional/pages/news/NewsPage.groovy index 01023879..a71e5e9a 100644 --- a/test/functional/pages/news/NewsPage.groovy +++ b/test/functional/pages/news/NewsPage.groovy @@ -32,4 +32,10 @@ class NewsPage extends Page { $("p span", text: desc).size() == 1 } //#end + + def selectViewNew(title) { + getRow() + def showLink = getRow().find('td').find([text:title]) + showLink.click() + } } diff --git a/test/functional/pages/news/NewsShowPage.groovy b/test/functional/pages/news/NewsShowPage.groovy new file mode 100644 index 00000000..b8cef890 --- /dev/null +++ b/test/functional/pages/news/NewsShowPage.groovy @@ -0,0 +1,36 @@ +package pages.news + +/** + * Created with IntelliJ IDEA. + * User: dyego + * Date: 09/01/14 + * Time: 18:30 + * To change this template use File | Settings | File Templates. + */ + +import geb.Page +import pages.GetPageTitle + +class NewsShowPage extends Page { + static url = "news/show/1" + + static at = { + //title ==~ /Ver News/ + GetPageTitle gp = new GetPageTitle() + def currentNews = gp.msg("default.news.label") + def currentTitle = gp.msg("default.show.label", [currentNews]) + + title ==~ currentTitle + } + + static content = { + } + + def select(String e, v) { + if (v == 'delete') { + assert withConfirm(true) { $("form").find(e, class: v).click() } + } else { + $("form").find(e, class: v).click() + } + } +} \ No newline at end of file diff --git a/test/functional/steps/NewsTestDataAndOperations.groovy b/test/functional/steps/NewsTestDataAndOperations.groovy index 19687e27..e3a5c729 100644 --- a/test/functional/steps/NewsTestDataAndOperations.groovy +++ b/test/functional/steps/NewsTestDataAndOperations.groovy @@ -30,4 +30,44 @@ class NewsTestDataAndOperations { def news = News.findByDescriptionAndDateAndResearchGroup(description, dateAsDateObj, researchGroup) return news != null } + + static public boolean checkExistingNewsByDescription(String description) { + def news = News.findByDescription(description) + return news != null + } + + static public void editNewsDescription(String description, String newDescription, Date date, ResearchGroup researchGroup) { + def cont = new NewsController() + def news = News.findByDescriptionAndDateAndResearchGroup(description, date, researchGroup) + news.setDescription(newDescription) + cont.params << news.properties + cont.update(news.id) + cont.response.reset() + } + + static public boolean checkValidDate(String date) { + + boolean retorno + + String diaStr = "" + date.charAt(0) + date.charAt(1) + String mesStr = "" + date.charAt(3) + date.charAt(4) + int dia = Integer.valueOf(diaStr) + int mes = Integer.valueOf(mesStr) + + if( (dia > 28) && (mes == 2) ) { // fevereiro + retorno = false + } + else if ( (dia > 30) && (mes == 4) ) { // abril + retorno = false + } + else if ( (dia > 30) && (mes == 6) ) { // junho + retorno = false + } + else if ( (dia > 30) && (mes == 7) ) { // setembro + retorno = false + } + else retorno = !((dia > 30) && (mes == 11)) + + return retorno + } }