Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
KaneFreeman committed Oct 3, 2023
1 parent c434a76 commit 7ed2422
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 371 deletions.

This file was deleted.

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();
});
});
Loading

0 comments on commit 7ed2422

Please sign in to comment.