2024-03-10 12:22:01 +00:00
|
|
|
import { render } from '@testing-library/react';
|
2024-03-01 02:36:09 +00:00
|
|
|
|
2021-12-30 15:46:12 +00:00
|
|
|
import { UserViewModel } from '@/portainer/models/user';
|
2024-03-10 12:22:01 +00:00
|
|
|
import { withUserProvider } from '@/react/test-utils/withUserProvider';
|
|
|
|
import { withTestRouter } from '@/react/test-utils/withRouter';
|
|
|
|
import { withTestQueryProvider } from '@/react/test-utils/withTestQuery';
|
2021-12-30 15:46:12 +00:00
|
|
|
|
|
|
|
import { HeaderContainer } from './HeaderContainer';
|
|
|
|
import { HeaderTitle } from './HeaderTitle';
|
|
|
|
|
|
|
|
test('should not render without a wrapping HeaderContainer', async () => {
|
2024-01-23 06:42:52 +00:00
|
|
|
const consoleErrorFn = vi
|
2022-03-08 12:14:23 +00:00
|
|
|
.spyOn(console, 'error')
|
2024-01-23 06:42:52 +00:00
|
|
|
.mockImplementation(() => vi.fn());
|
2022-03-08 12:14:23 +00:00
|
|
|
|
2021-12-30 15:46:12 +00:00
|
|
|
const title = 'title';
|
|
|
|
function renderComponent() {
|
2024-03-10 12:22:01 +00:00
|
|
|
const Wrapped = withTestQueryProvider(HeaderTitle);
|
|
|
|
return render(<Wrapped title={title} />);
|
2021-12-30 15:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expect(renderComponent).toThrowErrorMatchingSnapshot();
|
2022-03-08 12:14:23 +00:00
|
|
|
|
|
|
|
consoleErrorFn.mockRestore();
|
2021-12-30 15:46:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should display a HeaderTitle', async () => {
|
|
|
|
const username = 'username';
|
|
|
|
const user = new UserViewModel({ Username: username });
|
|
|
|
|
|
|
|
const title = 'title';
|
2024-03-10 12:22:01 +00:00
|
|
|
|
|
|
|
const Wrapped = withTestQueryProvider(
|
|
|
|
withUserProvider(
|
|
|
|
withTestRouter(() => (
|
2024-03-01 02:36:09 +00:00
|
|
|
<HeaderContainer>
|
|
|
|
<HeaderTitle title={title} />
|
|
|
|
</HeaderContainer>
|
2024-03-10 12:22:01 +00:00
|
|
|
)),
|
|
|
|
user
|
|
|
|
)
|
2021-12-30 15:46:12 +00:00
|
|
|
);
|
|
|
|
|
2024-03-10 12:22:01 +00:00
|
|
|
const { queryByText } = render(<Wrapped />);
|
|
|
|
|
2021-12-30 15:46:12 +00:00
|
|
|
const heading = queryByText(title);
|
|
|
|
expect(heading).toBeVisible();
|
|
|
|
|
|
|
|
expect(queryByText(username)).toBeVisible();
|
|
|
|
});
|