adds banner creation/edition/deletion specs

refactors admin banners specs
This commit is contained in:
Juanjo Bazán
2016-05-23 20:03:11 +02:00
parent 7c22c9d6fa
commit 1f1034a147
3 changed files with 147 additions and 98 deletions

View File

@@ -11,14 +11,14 @@ en:
unmark_featured: Unmark featured unmark_featured: Unmark featured
banners: banners:
index: index:
title: Post banners title: Banners
create: Create a banner create: Create banner
edit: Edit a banner edit: Edit banner
delete: Delete a banner delete: Delete banner
filters: filters:
all: Todos all: All
with_active: Actives with_active: Active
with_inactive: Inactives with_inactive: Inactive
banner: banner:
title: Title title: Title
description: Description description: Description
@@ -92,7 +92,7 @@ en:
user_not_found: User not found user_not_found: User not found
menu: menu:
activity: Moderator activity activity: Moderator activity
banner: Publish banner banner: Manage banners
debate_topics: Debate topics debate_topics: Debate topics
hidden_comments: Hidden comments hidden_comments: Hidden comments
hidden_debates: Hidden debates hidden_debates: Hidden debates

View File

@@ -11,7 +11,7 @@ es:
unmark_featured: Quitar destacado unmark_featured: Quitar destacado
banners: banners:
index: index:
title: Publicar anuncios title: Anuncios
create: Crear un banner create: Crear un banner
edit: Editar banner edit: Editar banner
delete: Eliminar banner delete: Eliminar banner
@@ -90,7 +90,7 @@ es:
user_not_found: Usuario no encontrado user_not_found: Usuario no encontrado
menu: menu:
activity: Actividad de moderadores activity: Actividad de moderadores
banner: Publicar banner banner: Gestionar banners
debate_topics: Temas de debate debate_topics: Temas de debate
hidden_comments: Comentarios ocultos hidden_comments: Comentarios ocultos
hidden_debates: Debates ocultos hidden_debates: Debates ocultos

View File

@@ -1,7 +1,11 @@
require 'rails_helper' require 'rails_helper'
feature 'Admin add banners' do feature 'Admin banners magement' do
background do
login_as(create(:administrator).user)
end
context "Index" do
background do background do
@banner1 = create(:banner, title: "Banner number one", @banner1 = create(:banner, title: "Banner number one",
description: "This is the text of banner number one and is not active yet", description: "This is the text of banner number one and is not active yet",
@@ -42,64 +46,109 @@ feature 'Admin add banners' do
image: "banner-img.banner-one", image: "banner-img.banner-one",
post_started_at: (DateTime.now - 10.days), post_started_at: (DateTime.now - 10.days),
post_ended_at: (DateTime.now + 10.days)) post_ended_at: (DateTime.now + 10.days))
login_as(create(:administrator).user)
end end
scenario 'option publish banners is listed on admin menu' do scenario 'Index show active banners' do
visit admin_root_path
within('#admin_menu') do
expect(page).to have_link "Publish banner"
end
end
scenario 'index show active banners' do
visit admin_banners_path(filter: 'with_active') visit admin_banners_path(filter: 'with_active')
expect(page).to have_content("There are 3 banners") expect(page).to have_content("There are 3 banners")
end end
scenario 'index show inactive banners' do scenario 'Index show inactive banners' do
visit admin_banners_path(filter: 'with_inactive') visit admin_banners_path(filter: 'with_inactive')
expect(page).to have_content("There are 2 banners") expect(page).to have_content("There are 2 banners")
end end
scenario 'index show all banners' do scenario 'Index show all banners' do
visit admin_banners_path visit admin_banners_path
expect(page).to have_content("There are 5 banners") expect(page).to have_content("There are 5 banners")
end end
scenario 'refresh changes on edit banner', :js do
visit edit_admin_banner_path(@banner1)
fill_in 'banner_title', with: 'Titulo modificado'
fill_in 'banner_description', with: 'Texto modificado'
within('div#js-banner-style') do
expect(page).to have_selector('h2', :text => 'Titulo modificado')
expect(page).to have_selector('h3', :text => 'Texto modificado')
end
end end
scenario 'refresh changes on edit banner', :js do scenario 'Banners publication is listed on admin menu' do
visit edit_admin_banner_path(@banner1) visit admin_root_path
fill_in 'banner_title', with: 'Titulo modificado'
fill_in 'banner_description', with: 'Texto modificado'
within('div#js-banner-style') do
expect(page).to have_selector('h2', :text => 'Titulo modificado')
expect(page).to have_selector('h3', :text => 'Texto modificado')
end
end
scenario 'option Publish banners is listed on admin menu' do
visit admin_banners_path
within('#admin_menu') do within('#admin_menu') do
expect(page).to have_link "Publish banner" expect(page).to have_link "Manage banners"
end end
end end
scenario 'Publish a banner' do
visit admin_root_path
click_link "Manage banners"
click_link "Create banner"
select 'Banner style 1', from: 'banner_style'
select 'Banner image 2', from: 'banner_image'
fill_in 'banner_title', with: 'Such banner'
fill_in 'banner_description', with: 'many text wow link'
fill_in 'banner_target_url', with: 'https://decide.madrid.es'
last_week = Time.now - 7.days
next_week = Time.now + 7.days
fill_in 'post_started_at', with: last_week.strftime("%d/%m/%Y")
fill_in 'post_ended_at', with: next_week.strftime("%d/%m/%Y")
click_button 'Save changes'
expect(page).to have_content 'Such banner'
visit proposals_path
expect(page).to have_content 'Such banner'
expect(page).to have_link 'Such banner many text wow link', href: 'https://decide.madrid.es'
end
scenario 'Edit banner with live refresh', :js do
banner1 = create(:banner, title: 'Hello',
description: 'Wrong text',
target_url: 'http://www.url.com',
style: 'banner-style.banner-one',
image: 'banner-img.banner-one',
post_started_at: (Time.now + 4.days),
post_ended_at: (Time.now + 10.days))
visit admin_root_path
click_link "Manage banners"
click_link "Edit banner"
select 'Banner style 1', from: 'banner_style'
select 'Banner image 2', from: 'banner_image'
fill_in 'banner_title', with: 'Modified title'
fill_in 'banner_description', with: 'Edited text'
within('div#js-banner-style') do
expect(page).to have_selector('h2', :text => 'Modified title')
expect(page).to have_selector('h3', :text => 'Edited text')
end
click_button 'Save changes'
visit admin_banners_path
expect(page).to have_content 'Modified title'
expect(page).to have_content 'Edited text'
expect(page).to_not have_content 'Hello'
expect(page).to_not have_content 'Wrong text'
end
scenario 'Delete a banner' do
banner1 = create(:banner, title: 'Ugly banner',
description: 'Bad text',
target_url: 'http://www.url.com',
style: 'banner-style.banner-one',
image: 'banner-img.banner-one',
post_started_at: (Time.now + 4.days),
post_ended_at: (Time.now + 10.days))
visit admin_root_path
click_link "Manage banners"
expect(page).to have_content 'Ugly banner'
click_link "Delete banner"
visit admin_root_path
expect(page).to_not have_content 'Ugly banner'
end
end end