This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c434a76
commit 7ed2422
Showing
4 changed files
with
65 additions
and
371 deletions.
There are no files selected for viewing
41 changes: 0 additions & 41 deletions
41
packages/core/src/backends/git-gateway/__tests__/AuthenticationPage.spec.js
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
packages/core/src/backends/git-gateway/__tests__/AuthenticationPage.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import '@testing-library/jest-dom'; | ||
import { act } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { resolveBackend } from '@staticcms/core/backend'; | ||
import { createMockConfig } from '@staticcms/test/data/config.mock'; | ||
import { renderWithProviders } from '@staticcms/test/test-utils'; | ||
import GitGatewayAuthenticationPage from '../AuthenticationPage'; | ||
|
||
import type { GitGatewayAuthenticationPageProps } from '../AuthenticationPage'; | ||
|
||
jest.mock('@staticcms/core/backend'); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(window as any).netlifyIdentity = { | ||
currentUser: jest.fn(), | ||
on: jest.fn(), | ||
close: jest.fn(), | ||
}; | ||
|
||
describe('GitGatewayAuthenticationPage', () => { | ||
const props: GitGatewayAuthenticationPageProps = { | ||
onLogin: jest.fn(), | ||
inProgress: false, | ||
config: createMockConfig({ logo_url: 'logo_url', collections: [] }), | ||
handleAuth: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
(resolveBackend as jest.Mock).mockResolvedValue(null); | ||
|
||
jest.clearAllMocks(); | ||
jest.resetModules(); | ||
}); | ||
|
||
it('should render with identity error', () => { | ||
const { queryByTestId } = renderWithProviders(<GitGatewayAuthenticationPage {...props} />); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const errorCallback = (window as any).netlifyIdentity.on.mock.calls.find( | ||
(call: string[]) => call[0] === 'error', | ||
)[1]; | ||
|
||
act(() => { | ||
errorCallback( | ||
new Error('Failed to load settings from https://site.netlify.com/.netlify/identity'), | ||
); | ||
}); | ||
|
||
expect(queryByTestId('login-button')).toBeInTheDocument(); | ||
expect(queryByTestId('login-error')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render with no identity error', () => { | ||
const { queryByTestId } = renderWithProviders(<GitGatewayAuthenticationPage {...props} />); | ||
|
||
expect(queryByTestId('login-button')).toBeInTheDocument(); | ||
expect(queryByTestId('login-error')).not.toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.