|
| 1 | +/* |
| 2 | + * Copyright Strimzi authors. |
| 3 | + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). |
| 4 | + */ |
| 5 | +import { |
| 6 | + And, |
| 7 | + Given, |
| 8 | + When, |
| 9 | + Then, |
| 10 | + Fusion, |
| 11 | + Before, |
| 12 | + After, |
| 13 | +} from 'jest-cucumber-fusion'; |
| 14 | +import { |
| 15 | + fireEvent, |
| 16 | + render, |
| 17 | + RenderResult, |
| 18 | + waitFor, |
| 19 | +} from '@testing-library/react'; |
| 20 | +import { Topics } from '.'; |
| 21 | +import React, { ReactElement } from 'react'; |
| 22 | +import { withApolloProviderReturning } from 'utils/test'; |
| 23 | +import { |
| 24 | + mockGetTopicsRequests, |
| 25 | + mockGetTopicsResponses, |
| 26 | +} from './useTopicsModel.assets'; |
| 27 | + |
| 28 | +let renderResult: RenderResult; |
| 29 | +let component: ReactElement; |
| 30 | + |
| 31 | +Before(() => { |
| 32 | + jest.useFakeTimers(); |
| 33 | +}); |
| 34 | + |
| 35 | +After(() => { |
| 36 | + jest.useRealTimers(); |
| 37 | +}); |
| 38 | + |
| 39 | +Given('a Topics panel component', () => { |
| 40 | + component = <Topics />; |
| 41 | +}); |
| 42 | + |
| 43 | +When('it is rendered', () => { |
| 44 | + renderResult = render( |
| 45 | + withApolloProviderReturning( |
| 46 | + [ |
| 47 | + mockGetTopicsRequests.successRequest, |
| 48 | + mockGetTopicsRequests.successFilteredRequest, |
| 49 | + ], |
| 50 | + component |
| 51 | + ) |
| 52 | + ); |
| 53 | + jest.runAllTimers(); |
| 54 | +}); |
| 55 | + |
| 56 | +And(/^I filter for topic '(.+)'$/, async (filter) => { |
| 57 | + fireEvent.change(renderResult.getByPlaceholderText('filter'), { |
| 58 | + target: { value: filter }, |
| 59 | + }); |
| 60 | + await waitFor(() => { |
| 61 | + jest.runAllTimers(); |
| 62 | + }); |
| 63 | +}); |
| 64 | + |
| 65 | +Then('I see all topics', async () => { |
| 66 | + const { findByText } = renderResult; |
| 67 | + expect( |
| 68 | + await findByText(JSON.stringify(mockGetTopicsResponses.successResponse), { |
| 69 | + exact: false, |
| 70 | + }) |
| 71 | + ).toBeInTheDocument(); |
| 72 | +}); |
| 73 | + |
| 74 | +Then(/^I see topic '(.+)' in the topic list$/, async (topicName) => { |
| 75 | + const { findByText } = renderResult; |
| 76 | + expect( |
| 77 | + await findByText( |
| 78 | + JSON.stringify(mockGetTopicsResponses.successFilteredResponse), |
| 79 | + { exact: false } |
| 80 | + ) |
| 81 | + ).toBeInTheDocument(); |
| 82 | + expect( |
| 83 | + await findByText(topicName as string, { exact: false }) |
| 84 | + ).toBeInTheDocument(); |
| 85 | +}); |
| 86 | + |
| 87 | +Fusion('Topics.feature'); |
0 commit comments