From 3872fd66cf74f25e9a06b1983296c1edab05dffd Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Tue, 21 Mar 2023 04:59:00 -0400 Subject: [PATCH] [CM] Fix flaky test in the example app (#153310) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary close https://github.com/elastic/kibana/issues/152852 🤞 https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2010 --- .../public/examples/todos/todos.tsx | 101 ++++++++++-------- test/examples/content_management/todo_app.ts | 18 ++-- 2 files changed, 70 insertions(+), 49 deletions(-) diff --git a/examples/content_management_examples/public/examples/todos/todos.tsx b/examples/content_management_examples/public/examples/todos/todos.tsx index 84c48aa24c88..5c3bcfd4880e 100644 --- a/examples/content_management_examples/public/examples/todos/todos.tsx +++ b/examples/content_management_examples/public/examples/todos/todos.tsx @@ -6,7 +6,14 @@ * Side Public License, v 1. */ import React from 'react'; -import { EuiButtonGroup, EuiButtonIcon, EuiCheckbox, EuiFieldText, EuiSpacer } from '@elastic/eui'; +import { + EuiButtonGroup, + EuiButtonIcon, + EuiCheckbox, + EuiFieldText, + EuiSpacer, + EuiLoadingSpinner, +} from '@elastic/eui'; import { useCreateContentMutation, useDeleteContentMutation, @@ -55,7 +62,7 @@ const filters = [ export const Todos = () => { const [filterIdSelected, setFilterIdSelected] = React.useState('all'); - const { data, isLoading, isError, error } = useSearchTodosQuery({ + const { data, isError, error, isFetching, isLoading } = useSearchTodosQuery({ filter: filterIdSelected === 'all' ? undefined : filterIdSelected, }); @@ -63,7 +70,13 @@ export const Todos = () => { const deleteTodoMutation = useDeleteTodoMutation(); const updateTodoMutation = useUpdateTodoMutation(); - if (isLoading) return

Loading...

; + const isPending = + isFetching || + isLoading || + createTodoMutation.isLoading || + deleteTodoMutation.isLoading || + updateTodoMutation.isLoading; + if (isError) return

Error: {error}

; return ( @@ -77,46 +90,50 @@ export const Todos = () => { }} /> -
    - {data.hits.map((todo: Todo) => ( - -
  • - { - updateTodoMutation.mutate({ - contentTypeId: TODO_CONTENT_ID, - id: todo.id, - data: { - completed: e.target.checked, - }, - }); - }} - label={todo.title} - data-test-subj={`todoCheckbox todoCheckbox-${todo.id}`} - /> + {!isLoading && ( +
      + {data.hits.map((todo: Todo) => ( + +
    • + { + updateTodoMutation.mutate({ + contentTypeId: TODO_CONTENT_ID, + id: todo.id, + data: { + completed: e.target.checked, + }, + }); + }} + label={todo.title} + data-test-subj={`todoCheckbox todoCheckbox-${todo.id}`} + /> - { - deleteTodoMutation.mutate({ contentTypeId: TODO_CONTENT_ID, id: todo.id }); - }} - /> -
    • - -
      - ))} -
    - + { + deleteTodoMutation.mutate({ contentTypeId: TODO_CONTENT_ID, id: todo.id }); + }} + /> +
  • + +
    + ))} +
+ )} +
+ {isPending && } +
{ const inputRef = (e.target as HTMLFormElement).elements.namedItem( diff --git a/test/examples/content_management/todo_app.ts b/test/examples/content_management/todo_app.ts index fa5eb8e393d8..5c5739c962e2 100644 --- a/test/examples/content_management/todo_app.ts +++ b/test/examples/content_management/todo_app.ts @@ -15,14 +15,13 @@ import { PluginFunctionalProviderContext } from '../../plugin_functional/service export default function ({ getService, getPageObjects }: PluginFunctionalProviderContext) { const testSubjects = getService('testSubjects'); const find = getService('find'); - const retry = getService('retry'); const PageObjects = getPageObjects(['common']); - // FLAKY: https://github.com/elastic/kibana/issues/152852 - describe.skip('Todo app', () => { + describe('Todo app', () => { it('Todo app works', async () => { const appId = 'contentManagementExamples'; await PageObjects.common.navigateToApp(appId); + await testSubjects.missingOrFail(`todoPending`); // check that initial state is correct let todos = await testSubjects.findAll(`~todoItem`); @@ -30,24 +29,26 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide // check that filters work await (await find.byCssSelector('label[title="Completed"]')).click(); + await testSubjects.missingOrFail(`todoPending`); todos = await testSubjects.findAll(`~todoItem`); expect(todos.length).to.be(1); await (await find.byCssSelector('label[title="Todo"]')).click(); + await testSubjects.missingOrFail(`todoPending`); todos = await testSubjects.findAll(`~todoItem`); expect(todos.length).to.be(1); await (await find.byCssSelector('label[title="All"]')).click(); + await testSubjects.missingOrFail(`todoPending`); todos = await testSubjects.findAll(`~todoItem`); expect(todos.length).to.be(2); // check that adding new todo works await testSubjects.setValue('newTodo', 'New todo'); await (await testSubjects.find('newTodo')).pressKeys(Key.ENTER); - await retry.tryForTime(1000, async () => { - todos = await testSubjects.findAll(`~todoItem`); - expect(todos.length).to.be(3); - }); + await testSubjects.missingOrFail(`todoPending`); + todos = await testSubjects.findAll(`~todoItem`); + expect(todos.length).to.be(3); // check that updating todo works let newTodo = todos[2]; @@ -55,8 +56,10 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide let newTodoCheckbox = await newTodo.findByTestSubject('~todoCheckbox'); expect(await newTodoCheckbox.isSelected()).to.be(false); await (await newTodo.findByTagName('label')).click(); + await testSubjects.missingOrFail(`todoPending`); await (await find.byCssSelector('label[title="Completed"]')).click(); + await testSubjects.missingOrFail(`todoPending`); todos = await testSubjects.findAll(`~todoItem`); expect(todos.length).to.be(2); newTodo = todos[1]; @@ -66,6 +69,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide // check that deleting todo works await (await newTodo.findByCssSelector('[aria-label="Delete"]')).click(); + await testSubjects.missingOrFail(`todoPending`); todos = await testSubjects.findAll(`~todoItem`); expect(todos.length).to.be(1); });