* Rework context usage (& move most to react-hooks)
* Move use{Accounts, Addresses} to use contexts
* Cleanups
* Global alignment renames
* Combine keyring subjects into KeyringCtx
* Cleanups to contexts
* Small adjustment to window size usage
* Popup test via data-testid
* Fix Bounties tests
* Move getStats to correct location
* Adjust ApiStats
* Do add unsubs (although unneeded)
85 lines
2.0 KiB
TypeScript
85 lines
2.0 KiB
TypeScript
// Copyright 2017-2023 @polkadot/react-components authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
import React, { Suspense } from 'react';
|
|
import { ThemeProvider } from 'styled-components';
|
|
|
|
import { lightTheme } from '@polkadot/apps/themes';
|
|
import { Popup } from '@polkadot/react-components';
|
|
import i18next from '@polkadot/react-components/i18n';
|
|
|
|
function TestPopup () {
|
|
return (
|
|
<>
|
|
<h1>Test outside text</h1>
|
|
<Popup
|
|
value={
|
|
<div>
|
|
Test popup content
|
|
</div>
|
|
}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
|
|
function renderPopup () {
|
|
return render(
|
|
<Suspense fallback='...'>
|
|
<ThemeProvider theme={lightTheme}>
|
|
<TestPopup />
|
|
</ThemeProvider>
|
|
</Suspense>
|
|
);
|
|
}
|
|
|
|
describe('Popup Component', () => {
|
|
beforeAll(async () => {
|
|
await i18next.changeLanguage('en');
|
|
});
|
|
|
|
it('opens and closes', async () => {
|
|
renderPopup();
|
|
|
|
await waitFor(async () => {
|
|
await expectPopupToBeClosed();
|
|
await togglePopup();
|
|
await expectPopupToBeOpen();
|
|
await togglePopup();
|
|
await expectPopupToBeClosed();
|
|
});
|
|
});
|
|
|
|
it('closes popup with outside click', async () => {
|
|
renderPopup();
|
|
|
|
await waitFor(async () => {
|
|
await expectPopupToBeClosed();
|
|
await togglePopup();
|
|
await expectPopupToBeOpen();
|
|
await clickOutside();
|
|
await expectPopupToBeClosed();
|
|
});
|
|
});
|
|
});
|
|
|
|
async function expectPopupToBeClosed () {
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
await screen.findByRole('button');
|
|
expect(screen.queryAllByText('Test popup content')).toHaveLength(0);
|
|
}
|
|
|
|
async function expectPopupToBeOpen () {
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
await screen.findByText('Test popup content');
|
|
}
|
|
|
|
async function togglePopup () {
|
|
fireEvent.click(await screen.findByTestId('popup-open'));
|
|
}
|
|
|
|
async function clickOutside () {
|
|
fireEvent.click(await screen.findByText('Test outside text'));
|
|
}
|