Skip to content

Commit

Permalink
test: attempts to fix tests #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Tedzury committed Dec 27, 2023
1 parent d404f79 commit b198e12
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 204 deletions.
35 changes: 16 additions & 19 deletions src/test/EditorTools.test.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
// import { screen } from '@testing-library/react';
import { screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';

// import renderWithRouter from '@/test/helpers/RenderWithRouter';
// import MainPage from '@pages/MainPage/MainPage';
import renderWithRouter from '@/test/helpers/RenderWithRouter';
import MainPage from '@pages/MainPage/MainPage';

describe('Editor tools', () => {
// it('should render the editor tools', () => {
// renderWithRouter(<MainPage />);
it('should render the editor tools', () => {
renderWithRouter(<MainPage />);

// expect(screen.getByTestId('editor-tools-variables')).toBeInTheDocument();
// expect(screen.getByTestId('editor-tools-headers')).toBeInTheDocument();
// expect(screen.getByTestId('editor-tools-tabs')).toBeInTheDocument();
// expect(screen.getByTestId('editor-tools-expand')).toBeInTheDocument();
// });
expect(screen.getByTestId('editor-tools-variables')).toBeInTheDocument();
expect(screen.getByTestId('editor-tools-headers')).toBeInTheDocument();
expect(screen.getByTestId('editor-tools-tabs')).toBeInTheDocument();
expect(screen.getByTestId('editor-tools-expand')).toBeInTheDocument();
});

// it('should change the tabs', async () => {
// renderWithRouter(<MainPage />);
it('should change the tabs', async () => {
renderWithRouter(<MainPage />);

// const editorToolsTabs = screen.getByTestId('editor-tools-tabs');
// Object.defineProperty(editorToolsTabs, 'activeTabIndex', { value: 0 });
const editorToolsTabs = screen.getByTestId('editor-tools-tabs');
Object.defineProperty(editorToolsTabs, 'activeTabIndex', { value: 0 });

// expect(screen.getByTestId('editor-tools-variables')).toHaveAttribute('active', 'true');
// expect(screen.getByTestId('editor-tools-headers')).toHaveAttribute('active', 'true');
// });
it('fake', () => {
expect(1).toBe(1);
expect(screen.getByTestId('editor-tools-variables')).toHaveAttribute('active', 'true');
expect(screen.getByTestId('editor-tools-headers')).toHaveAttribute('active', 'true');
});
});
86 changes: 41 additions & 45 deletions src/test/RequestEditor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,55 @@
// import { screen } from '@testing-library/react';
// import userEvent from '@testing-library/user-event';
// import { afterEach, describe, expect, it, vi } from 'vitest';
import { describe, expect, it } from 'vitest';

// import renderWithRouter from '@/test/helpers/RenderWithRouter';
// import * as useEditorUrlState from '@components/Editor/lib/hooks/useEditorUrlState';
// import MainPage from '@pages/MainPage/MainPage';
// import * as useUrl from '@shared/lib/hooks/useUrl';

// const mockWriteText = vi.fn();
// const mockEditorText = 'test text';
// const mockedUseEditorUrlState = vi.spyOn(useEditorUrlState, 'default');
// const mockedReadUrl = vi.spyOn(useUrl, 'default');

// Object.assign(navigator, {
// clipboard: {
// writeText: mockWriteText,
// },
// });
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterEach, describe, expect, it, vi } from 'vitest';

import renderWithRouter from '@/test/helpers/RenderWithRouter';
import * as useEditorUrlState from '@components/Editor/lib/hooks/useEditorUrlState';
import MainPage from '@pages/MainPage/MainPage';
import * as useUrl from '@shared/lib/hooks/useUrl';

const mockWriteText = vi.fn();
const mockEditorText = 'test text';
const mockedUseEditorUrlState = vi.spyOn(useEditorUrlState, 'default');
const mockedReadUrl = vi.spyOn(useUrl, 'default');

Object.assign(navigator, {
clipboard: {
writeText: mockWriteText,
},
});

// const mockedClipboard = vi.spyOn(navigator.clipboard, 'writeText');
const mockedClipboard = vi.spyOn(navigator.clipboard, 'writeText');

describe('Request editor', () => {
// afterEach(() => {
// vi.clearAllMocks();
// });
afterEach(() => {
vi.clearAllMocks();
});

// it('should render the request editor', () => {
// renderWithRouter(<MainPage />);
it('should render the request editor', () => {
renderWithRouter(<MainPage />);

// const controls = screen.getByTestId('controls');
// const editor = screen.getByTestId('editor-request');
const controls = screen.getByTestId('controls');
const editor = screen.getByTestId('editor-request');

// expect(controls).toBeInTheDocument();
// expect(editor).toBeInTheDocument();
// });
expect(controls).toBeInTheDocument();
expect(editor).toBeInTheDocument();
});

// it('should copy the entered text', async () => {
// mockedUseEditorUrlState.mockReturnValue([mockEditorText, vi.fn()]);
// mockedReadUrl.mockReturnValue({
// readUrl: () => mockEditorText,
// setUrl: () => {},
// });
it('should copy the entered text', async () => {
mockedUseEditorUrlState.mockReturnValue([mockEditorText, vi.fn()]);
mockedReadUrl.mockReturnValue({
readUrl: () => mockEditorText,
setUrl: () => {},
});

// renderWithRouter(<MainPage />);
renderWithRouter(<MainPage />);

// const copyText = screen.getByTestId('copy-text');
const copyText = screen.getByTestId('copy-text');

// expect(copyText).toBeInTheDocument();
expect(copyText).toBeInTheDocument();

// await userEvent.click(copyText);
await userEvent.click(copyText);

// expect(mockedClipboard).toHaveBeenCalledWith(mockEditorText);
// });
it('fake', () => {
expect(1).toBe(1);
expect(mockedClipboard).toHaveBeenCalledWith(mockEditorText);
});
});
83 changes: 40 additions & 43 deletions src/test/docsComponent/separateTestPartOne.test.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
// import { act, fireEvent, render, screen, waitForElementToBeRemoved } from '@testing-library/react';
import { act, fireEvent, render, screen, waitForElementToBeRemoved } from '@testing-library/react';
import { describe, expect, it } from 'vitest';

// import App from '@/app/App';
import App from '@/app/App';

describe('Testing for docs component', () => {
// it('Should render docs components after clicking on show docs btn', async () => {
// render(<App />);
// const showDocsBtn = screen.getByText('show docs');
// expect(screen.queryByTestId('overlay')).toBeNull();
// expect(screen.queryByText('Docs')).toBeNull();
// expect(screen.queryByText('A GraphQL schema provides a root type for each kind of operation')).toBeNull();
// await act(async () => {
// fireEvent.click(showDocsBtn);
// });
// expect(await screen.findByTestId('overlay')).toBeInTheDocument();
// expect(await screen.findByText('Docs')).toBeInTheDocument();
// expect(
// await screen.findByText('A GraphQL schema provides a root type for each kind of operation.'),
// ).toBeInTheDocument();
// });
// it('Should close docs section after clicking on overlay', async () => {
// render(<App />);
// const showDocsBtn = screen.getByText('show docs');
// expect(screen.queryByTestId('overlay')).toBeNull();
// expect(screen.queryByText('Docs')).toBeNull();
// expect(screen.queryByText('A GraphQL schema provides a root type for each kind of operation')).toBeNull();
// await act(async () => {
// fireEvent.click(showDocsBtn);
// });
// const overlay = await screen.findByTestId('overlay');
// expect(overlay).toBeInTheDocument();
// expect(await screen.findByText('Docs')).toBeInTheDocument();
// expect(
// await screen.findByText('A GraphQL schema provides a root type for each kind of operation.'),
// ).toBeInTheDocument();
// await act(async () => {
// fireEvent.click(overlay);
// });
// waitForElementToBeRemoved(() => {
// expect(overlay).toBeNull();
// expect(screen.queryByText('Docs')).toBeNull();
// expect(screen.queryByText('A GraphQL schema provides a root type for each kind of operation.')).toBeNull();
// }).catch(() => {});
// });
it('fake', () => {
expect(1).toBe(1);
it('Should render docs components after clicking on show docs btn', async () => {
render(<App />);
const showDocsBtn = screen.getByText('show docs');
expect(screen.queryByTestId('overlay')).toBeNull();
expect(screen.queryByText('Docs')).toBeNull();
expect(screen.queryByText('A GraphQL schema provides a root type for each kind of operation')).toBeNull();
await act(async () => {
fireEvent.click(showDocsBtn);
});
expect(await screen.findByTestId('overlay')).toBeInTheDocument();
expect(await screen.findByText('Docs')).toBeInTheDocument();
expect(
await screen.findByText('A GraphQL schema provides a root type for each kind of operation.'),
).toBeInTheDocument();
});
it('Should close docs section after clicking on overlay', async () => {
render(<App />);
const showDocsBtn = screen.getByText('show docs');
expect(screen.queryByTestId('overlay')).toBeNull();
expect(screen.queryByText('Docs')).toBeNull();
expect(screen.queryByText('A GraphQL schema provides a root type for each kind of operation')).toBeNull();
await act(async () => {
fireEvent.click(showDocsBtn);
});
const overlay = await screen.findByTestId('overlay');
expect(overlay).toBeInTheDocument();
expect(await screen.findByText('Docs')).toBeInTheDocument();
expect(
await screen.findByText('A GraphQL schema provides a root type for each kind of operation.'),
).toBeInTheDocument();
await act(async () => {
fireEvent.click(overlay);
});
waitForElementToBeRemoved(() => {
expect(overlay).toBeNull();
expect(screen.queryByText('Docs')).toBeNull();
expect(screen.queryByText('A GraphQL schema provides a root type for each kind of operation.')).toBeNull();
}).catch(() => {});
});
});
109 changes: 53 additions & 56 deletions src/test/docsComponent/separateTestPartThree.test.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,59 @@
// import { act, fireEvent, render, screen } from '@testing-library/react';
import { act, fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';

// import App from '@/app/App';
import App from '@/app/App';

describe('Testing for docs component', () => {
// it('Should navigate and display info about proper info about root type after cliking on that type', async () => {
// render(<App />);
// const showDocsBtn = screen.getByText('show docs');
// await act(async () => {
// fireEvent.click(showDocsBtn);
// });
// const RootTypeLink = await screen.findByText('Root');
// await act(async () => {
// fireEvent.click(RootTypeLink);
// });
// expect(await screen.findByText('Fields:')).toBeInTheDocument();
// });
// it('Should navigate and display info about proper info about root type after cliking on that type and all following clicked types as well as navigating back', async () => {
// render(<App />);
// const showDocsBtn = screen.getByText('show docs');
// await act(async () => {
// fireEvent.click(showDocsBtn);
// });
// const RootTypeLink = await screen.findByText('Root');
// await act(async () => {
// fireEvent.click(RootTypeLink);
// });
// expect(await screen.findByText('Fields:')).toBeInTheDocument();
// const filmsLink = await screen.findByText('Film');
// expect(filmsLink).toBeInTheDocument();
// await act(async () => {
// fireEvent.click(filmsLink);
// });
// expect(await screen.findByText('Implements:')).toBeInTheDocument();
// const nodeTypeLink = await screen.findByText('Node');
// expect(nodeTypeLink).toBeInTheDocument();
// await act(async () => {
// fireEvent.click(nodeTypeLink);
// });
// expect(await screen.findByText('Implementations')).toBeInTheDocument();
// const backToFilmBtn = await screen.findByRole('button', { name: 'Film' });
// await act(async () => {
// fireEvent.click(backToFilmBtn);
// });
// const backToRootBtn = await screen.findByRole('button', { name: 'Root' });
// await act(async () => {
// fireEvent.click(backToRootBtn);
// });
// const backToDocsBtn = await screen.findByRole('button', { name: 'Docs' });
// await act(async () => {
// fireEvent.click(backToDocsBtn);
// });
// expect(await screen.findByText('Docs')).toBeInTheDocument();
// expect(
// await screen.findByText('A GraphQL schema provides a root type for each kind of operation.'),
// ).toBeInTheDocument();
// });
it('fake', () => {
expect(1).toBe(1);
it('Should navigate and display info about proper info about root type after cliking on that type', async () => {
render(<App />);
const showDocsBtn = screen.getByText('show docs');
await act(async () => {
fireEvent.click(showDocsBtn);
});
const RootTypeLink = await screen.findByText('Root');
await act(async () => {
fireEvent.click(RootTypeLink);
});
expect(await screen.findByText('Fields:')).toBeInTheDocument();
});
it('Should navigate and display info about proper info about root type after cliking on that type and all following clicked types as well as navigating back', async () => {
render(<App />);
const showDocsBtn = screen.getByText('show docs');
await act(async () => {
fireEvent.click(showDocsBtn);
});
const RootTypeLink = await screen.findByText('Root');
await act(async () => {
fireEvent.click(RootTypeLink);
});
expect(await screen.findByText('Fields:')).toBeInTheDocument();
const filmsLink = await screen.findByText('Film');
expect(filmsLink).toBeInTheDocument();
await act(async () => {
fireEvent.click(filmsLink);
});
expect(await screen.findByText('Implements:')).toBeInTheDocument();
const nodeTypeLink = await screen.findByText('Node');
expect(nodeTypeLink).toBeInTheDocument();
await act(async () => {
fireEvent.click(nodeTypeLink);
});
expect(await screen.findByText('Implementations')).toBeInTheDocument();
const backToFilmBtn = await screen.findByRole('button', { name: 'Film' });
await act(async () => {
fireEvent.click(backToFilmBtn);
});
const backToRootBtn = await screen.findByRole('button', { name: 'Root' });
await act(async () => {
fireEvent.click(backToRootBtn);
});
const backToDocsBtn = await screen.findByRole('button', { name: 'Docs' });
await act(async () => {
fireEvent.click(backToDocsBtn);
});
expect(await screen.findByText('Docs')).toBeInTheDocument();
expect(
await screen.findByText('A GraphQL schema provides a root type for each kind of operation.'),
).toBeInTheDocument();
});
});
Loading

0 comments on commit b198e12

Please sign in to comment.