Skip to content

Commit

Permalink
Maintenance: Mobile - Stabilize ticket article list subscription test.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvuckovic committed May 2, 2023
1 parent bd52b4e commit 509f04d
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions spec/system/apps/mobile/tickets/articles/list_subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,38 @@ def create_articles(count)
end
end

def visit_ticket
visit "/tickets/#{ticket.id}"

wait_for_form_to_settle('form-ticket-edit')
end

def wait_for_ticket_article_updates(number: 1)
wait_for_gql('apps/mobile/pages/ticket/graphql/subscriptions/ticketArticlesUpdates.graphql', number: number)
end

def wait_for_ticket_articles(number: 1)
wait_for_gql('apps/mobile/pages/ticket/graphql/queries/ticket/articles.graphql', number: number)
end

it 'shows a newly created article' do
create_list(:ticket_article, 3, ticket: ticket)

visit "/tickets/#{ticket.id}"
visit_ticket

expect(page).to have_selector('[role="comment"]', count: 3)

article = create(:ticket_article, body: 'New Article', ticket: ticket)

wait_for_gql('apps/mobile/pages/ticket/graphql/subscriptions/ticketArticlesUpdates.graphql')
wait_for_ticket_articles(number: 2)

expect(page).to have_text(article.body)
end

it 'updates the list after a former visible article is deleted' do
articles = create_articles(3)

visit "/tickets/#{ticket.id}"
visit_ticket

expect(page).to have_selector('[role="comment"]', count: 3)

Expand All @@ -42,7 +56,7 @@ def create_articles(count)

remove_article.destroy!

wait_for_gql('apps/mobile/pages/ticket/graphql/subscriptions/ticketArticlesUpdates.graphql')
wait_for_ticket_articles(number: 2)

expect(page).to have_selector('[role="comment"]', count: 2)
expect(page).to have_no_text(remove_article_body)
Expand All @@ -51,7 +65,7 @@ def create_articles(count)
it 'updates the list after a non-visible article is deleted' do
articles = create_articles(7)

visit "/tickets/#{ticket.id}"
visit_ticket

not_visible_article = articles.second

Expand All @@ -60,7 +74,7 @@ def create_articles(count)

not_visible_article.destroy!

wait_for_gql('apps/mobile/pages/ticket/graphql/subscriptions/ticketArticlesUpdates.graphql')
wait_for_ticket_article_updates

expect(page).to have_no_text('load 1 more')
expect(page).to have_no_text(not_visible_article.body)
Expand All @@ -72,14 +86,14 @@ def create_articles(count)
article = articles.last
article.update!(internal: true)

visit "/tickets/#{ticket.id}"
visit_ticket

expect(page).to have_selector('[role="comment"]', count: 2)

article = articles.last
article.update!(internal: false)

wait_for_gql('apps/mobile/pages/ticket/graphql/subscriptions/ticketArticlesUpdates.graphql')
wait_for_ticket_articles(number: 2)

expect(page).to have_selector('[role="comment"]', count: 3)
expect(page).to have_text(article.body)
Expand All @@ -88,14 +102,14 @@ def create_articles(count)
it 'updates the list after a former visible article at the end of the list is switched to internal' do
articles = create_articles(3)

visit "/tickets/#{ticket.id}"
visit_ticket

expect(page).to have_selector('[role="comment"]', count: 3)

article = articles.last
article.update!(internal: true)

wait_for_gql('apps/mobile/pages/ticket/graphql/subscriptions/ticketArticlesUpdates.graphql')
wait_for_ticket_articles(number: 2)

expect(page).to have_selector('[role="comment"]', count: 2)
expect(page).to have_no_text(article.body)
Expand All @@ -106,14 +120,14 @@ def create_articles(count)
article = articles.second
article.update!(internal: true)

visit "/tickets/#{ticket.id}"
visit_ticket

expect(page).to have_no_text('load 1 more')
expect(page).to have_selector('[role="comment"]', count: 6)

article.update!(internal: false)

wait_for_gql('apps/mobile/pages/ticket/graphql/subscriptions/ticketArticlesUpdates.graphql')
wait_for_ticket_articles(number: 2)

expect(page).to have_no_text('load 1 more')
expect(page).to have_selector('[role="comment"]', count: 7)
Expand All @@ -123,14 +137,14 @@ def create_articles(count)
it 'updates the list after a former visible article in between is switched to internal' do
articles = create_articles(6)

visit "/tickets/#{ticket.id}"
visit_ticket

expect(page).to have_no_text('load 1 more')
expect(page).to have_selector('[role="comment"]', count: 6)

articles.second.update!(internal: true)

wait_for_gql('apps/mobile/pages/ticket/graphql/subscriptions/ticketArticlesUpdates.graphql')
wait_for_ticket_article_updates

expect(page).to have_no_text('load 1 more')
expect(page).to have_selector('[role="comment"]', count: 5)
Expand All @@ -142,14 +156,14 @@ def create_articles(count)
article = articles.second
article.update!(internal: true)

visit "/tickets/#{ticket.id}"
visit_ticket

expect(page).to have_text('load 1 more')
expect(page).to have_selector('[role="comment"]', count: 6)

article.update!(internal: false)

wait_for_gql('apps/mobile/pages/ticket/graphql/subscriptions/ticketArticlesUpdates.graphql')
wait_for_ticket_articles(number: 2)

expect(page).to have_no_text('load 1 more')
expect(page).to have_selector('[role="comment"]', count: 8)
Expand All @@ -158,14 +172,14 @@ def create_articles(count)
it 'updates the list after a non-visible article in between is switched to internal' do
articles = create_articles(7)

visit "/tickets/#{ticket.id}"
visit_ticket

expect(page).to have_text('load 1 more')
expect(page).to have_selector('[role="comment"]', count: 6)

articles.second.update!(internal: true)

wait_for_gql('apps/mobile/pages/ticket/graphql/subscriptions/ticketArticlesUpdates.graphql')
wait_for_ticket_article_updates

expect(page).to have_no_text('load 1 more')
expect(page).to have_selector('[role="comment"]', count: 6)
Expand Down

0 comments on commit 509f04d

Please sign in to comment.