Skip to content

Commit

Permalink
unit tests wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leanneeliatra committed Sep 26, 2023
1 parent 7f7a251 commit 8a43b03
Showing 1 changed file with 41 additions and 40 deletions.
81 changes: 41 additions & 40 deletions public/apps/customerror/test/custom-error.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,11 @@ import React from 'react';
import { CustomErrorPage } from '../custom-error';
import { cleanup } from '@testing-library/react';
import '@testing-library/jest-dom';
import { ClientConfigType } from '../../../types';

// afterEach function runs after each test suite is executed
afterEach(() => {
cleanup();
});

// describe("Error page ", () => {
// it('renders', () => {
// const logout = shallow(
// <button>
// Logout
// </button>
// );
// const button = screen.getByTestId("button");

// // Test 1
// test("Button Rendering", () => {
// expect(button).toBeInTheDocument();
// })

// // Test 2
// test("Button Text", () => {
// expect(button).toHaveTextContent("Logout");
// })
// })
// });

const configUiDefault = {
basicauth: {
login: {
Expand All @@ -53,9 +30,13 @@ const configUiDefault = {
},
};

const mockLogout = jest.fn();


Check failure on line 35 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Delete `⏎⏎`

Check failure on line 35 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Delete `⏎⏎`

Check failure on line 35 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Delete `␍⏎␍⏎`

describe('Custom error test', () => {
it('renders the button on the error page', () => {
const component = shallow(
it('renders and clicks the button on the error page', () => {

Check failure on line 38 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Delete `····`

Check failure on line 38 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Delete `····`

Check failure on line 38 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Delete `····`
const wrapper = shallow(
<CustomErrorPage
title="Title"
subtitle="Sub Title"
Expand All @@ -71,21 +52,41 @@ describe('Custom error test', () => {
/>
);

expect(component).toMatchSnapshot();
// jest.mock('../custom-error.tsx', () => {
// logout: mockLogout

Check failure on line 56 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Delete `·`

Check failure on line 56 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Delete `·`

Check failure on line 56 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Delete `·`
// });

// const logoutButton = wrapper.find(`[data-testid="error-logout-button"]`).hostNodes();
// logoutButton.simulate("onClick")
// expect(mockLogout).toHaveBeenCalled();

Check failure on line 61 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Delete `···`

Check failure on line 61 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Delete `···`

Check failure on line 61 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Delete `···`

Check failure on line 62 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Delete `····`

Check failure on line 62 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Delete `····`

Check failure on line 62 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Delete `····`
expect(wrapper).toMatchSnapshot();

// describe('event trigger testing', () => {
// const setState = jest.fn();
// const useState = jest.spyOn(React, 'useState');
// const config: ClientConfigType = {
// ui: configUiDefault,
// auth: {
// type: 'basicauth',
// },
// };
// beforeEach(() => {
// useState.mockImplementation((initialValue) => [initialValue, setState]);
// // add addtional funtionality to test the logout button click and its reroute
// });
// });

describe('event trigger testing', () => {
const setState = jest.fn();
const useState = jest.spyOn(React, 'useState');
const config: ClientConfigType = {
ui: configUiDefault,
auth: {
type: 'basicauth',
},
};
beforeEach(() => {
useState.mockImplementation((initialValue) => [initialValue, setState]);
// add addtional funtionality to test the logout button click and its reroute
});
});
// describe("should call logout function", () => {
// const logOutUser = jest.fn();

Check failure on line 82 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Delete `····`

Check failure on line 82 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Delete `····`

Check failure on line 82 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Delete `····`
// const { getByTestId } = render(
// <CustomErrorPage logout={logout} />
// );

Check failure on line 86 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Delete `····`

Check failure on line 86 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Delete `····`

Check failure on line 86 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Delete `····`
// fireEvent.click(getByTestId('error-logout-button'));

Check failure on line 88 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Delete `····`

Check failure on line 88 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Delete `····`

Check failure on line 88 in public/apps/customerror/test/custom-error.test.tsx

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Delete `····`
// expect(logOutUser).toHaveBeenCalled();
// });
});
});

0 comments on commit 8a43b03

Please sign in to comment.