Maintenance: improves "Article ID URL / link" test performance

This commit is contained in:
Mantas Masalskis 2021-09-06 16:56:07 +02:00 committed by Martin Gruner
parent c976a07557
commit 380aa01643

View file

@ -1435,77 +1435,85 @@ RSpec.describe 'Ticket zoom', type: :system do
describe 'Article ID URL / link' do describe 'Article ID URL / link' do
let(:ticket) { create(:ticket, group: Group.first) } let(:ticket) { create(:ticket, group: Group.first) }
let!(:article) { create(:'ticket/article', ticket: ticket) } let!(:article) { create(:'ticket/article', ticket: ticket) }
let(:url) { "#{Setting.get('http_type')}://#{Setting.get('fqdn')}/#ticket/zoom/#{ticket.id}/#{article.id}" }
it 'shows Article direct link' do it 'shows Article direct link' do
ensure_websocket do ensure_websocket do
visit "ticket/zoom/#{ticket.id}" visit "ticket/zoom/#{ticket.id}"
end
within :active_ticket_article, article do url = "#{Setting.get('http_type')}://#{Setting.get('fqdn')}/#ticket/zoom/#{ticket.id}/#{article.id}"
expect(page).to have_css(%(a[href="#{url}"]))
end within :active_ticket_article, article do
expect(page).to have_css(%(a[href="#{url}"]))
end end
end end
context 'when multiple Articles are present' do context 'when multiple Articles are present' do
let(:article_count) { 20 } let(:article_count) { 20 }
let(:article_at_the_top) { ticket.articles.first } let(:article_top) { ticket.articles.second }
let(:article_in_the_middle) { ticket.articles[ article_count / 2 ] } let(:article_middle) { ticket.articles[ article_count / 2 ] }
let(:article_at_the_bottom) { ticket.articles.last } let(:article_bottom) { ticket.articles.last }
before do before do
article_count.times do article_count.times do
create(:'ticket/article', ticket: ticket, body: SecureRandom.uuid) create(:'ticket/article', ticket: ticket, body: SecureRandom.uuid)
end end
visit "ticket/zoom/#{ticket.id}"
end end
def check_obscured(top: true, middle: true, bottom: true, scroll_y: 0) def wait_for_scroll
expect(page).to have_text(ticket.title, wait: 10) wait(5, interval: 0.2).until_constant do
wait(5, interval: 0.2).until do find('.ticketZoom').native.location.y
scroll_y != find('.ticketZoom').native.location.y
end end
expect(page).to have_css("div#article-content-#{article_at_the_top.id}", obscured: top, wait: 10)
expect(page).to have_css("div#article-content-#{article_in_the_middle.id}", obscured: middle, wait: 10)
expect(page).to have_css("div#article-content-#{article_at_the_bottom.id}", obscured: bottom, wait: 10)
find('.ticketZoom').native.location.y
end end
it 'scrolls to given Article ID' do def check_shown(top: false, middle: false, bottom: false)
ensure_websocket do wait_for_scroll
visit "ticket/zoom/#{ticket.id}"
y = check_obscured(bottom: false)
# scroll to article in the middle of the page expect(page).to have_css("div#article-content-#{article_top.id} .richtext-content", obscured: !top)
visit "ticket/zoom/#{ticket.id}/#{article_in_the_middle.id}" .and(have_css("div#article-content-#{article_middle.id} .richtext-content", obscured: !middle, wait: 0))
y = check_obscured(middle: false, scroll_y: y) .and(have_css("div#article-content-#{article_bottom.id} .richtext-content", obscured: !bottom, wait: 0))
end
# scroll to article at the top of the page it 'scrolls to top article ID' do
visit "ticket/zoom/#{ticket.id}/#{article_at_the_top.id}" visit "ticket/zoom/#{ticket.id}/#{article_top.id}"
y = check_obscured(top: false, scroll_y: y) check_shown(top: true)
end
# scroll to article at the bottom of the page it 'scrolls to middle article ID' do
visit "ticket/zoom/#{ticket.id}/#{article_at_the_bottom.id}" visit "ticket/zoom/#{ticket.id}/#{article_middle.id}"
check_obscured(bottom: false, scroll_y: y) check_shown(middle: true)
end end
it 'scrolls to bottom article ID' do
visit "ticket/zoom/#{ticket.id}/#{article_top.id}"
wait_for_scroll
visit "ticket/zoom/#{ticket.id}/#{article_bottom.id}"
check_shown(bottom: true)
end end
end end
context 'when long articles are present' do context 'when long articles are present' do
it 'will properly show the "See more" link if you switch between the ticket and the dashboard on new articles' do it 'will properly show the "See more" link if you switch between the ticket and the dashboard on new articles' do
ensure_websocket do ensure_websocket do
# prerender ticket
visit "ticket/zoom/#{ticket.id}" visit "ticket/zoom/#{ticket.id}"
# ticket tab becomes background
visit 'dashboard' visit 'dashboard'
expect(page).to have_css("a.js-dashboardMenuItem[data-key='Dashboard'].is-active", wait: 10) end
article_id = create(:'ticket/article', ticket: ticket, body: "#{SecureRandom.uuid} #{"lorem ipsum\n" * 200}")
expect(page).to have_css('div.tasks a.is-modified', wait: 30)
visit "ticket/zoom/#{ticket.id}" # create a new article
within :active_content do article_id = create(:'ticket/article', ticket: ticket, body: "#{SecureRandom.uuid} #{"lorem ipsum\n" * 200}")
expect(find("div#article-content-#{article_id.id}")).to have_text('See more')
end wait(30).until { has_css?('div.tasks a.is-modified') }
visit "ticket/zoom/#{ticket.id}"
within :active_content do
expect(find("div#article-content-#{article_id.id}")).to have_text('See more')
end end
end end
end end