mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-21 12:11:25 +10:00
Dashboard page: added unit test for delete resume interaction
This commit is contained in:
@ -9,6 +9,8 @@ import {
|
|||||||
waitForElementToBeRemoved,
|
waitForElementToBeRemoved,
|
||||||
} from '@testing-library/react';
|
} from '@testing-library/react';
|
||||||
|
|
||||||
|
import fetchMock from 'jest-fetch-mock';
|
||||||
|
|
||||||
import FirebaseStub, { DatabaseConstants } from 'gatsby-plugin-firebase';
|
import FirebaseStub, { DatabaseConstants } from 'gatsby-plugin-firebase';
|
||||||
|
|
||||||
import '../../../i18n/index';
|
import '../../../i18n/index';
|
||||||
@ -40,6 +42,18 @@ describe('Dashboard', () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const waitForModalWindowToHaveBeenClosed = async () => {
|
||||||
|
await waitFor(() =>
|
||||||
|
screen.queryByRole('textbox', { name: /name/i })
|
||||||
|
? Promise.reject()
|
||||||
|
: Promise.resolve(),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const dismissNotification = (notification) => {
|
||||||
|
fireEvent.click(notification);
|
||||||
|
};
|
||||||
|
|
||||||
async function setup(waitForLoadingScreenToDisappear = true) {
|
async function setup(waitForLoadingScreenToDisappear = true) {
|
||||||
FirebaseStub.database().initializeData();
|
FirebaseStub.database().initializeData();
|
||||||
|
|
||||||
@ -117,9 +131,9 @@ describe('Dashboard', () => {
|
|||||||
let nameTextBox = null;
|
let nameTextBox = null;
|
||||||
|
|
||||||
const setupFetchMock = () => {
|
const setupFetchMock = () => {
|
||||||
fetch.resetMocks();
|
fetchMock.resetMocks();
|
||||||
|
|
||||||
fetch.mockImplementationOnce(async (input) => {
|
fetchMock.mockImplementationOnce(async (input) => {
|
||||||
await delay(100);
|
await delay(100);
|
||||||
|
|
||||||
if (input === unsplashPhotoRequestUrl) {
|
if (input === unsplashPhotoRequestUrl) {
|
||||||
@ -132,14 +146,6 @@ describe('Dashboard', () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const waitForModalWindowToHaveBeenClosed = async () => {
|
|
||||||
await waitFor(() =>
|
|
||||||
screen.queryByRole('textbox', { name: /name/i })
|
|
||||||
? Promise.reject()
|
|
||||||
: Promise.resolve(),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
setupFetchMock();
|
setupFetchMock();
|
||||||
|
|
||||||
@ -177,7 +183,7 @@ describe('Dashboard', () => {
|
|||||||
/You might need to fill up all the required fields/i,
|
/You might need to fill up all the required fields/i,
|
||||||
),
|
),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
fireEvent.click(notification);
|
dismissNotification(notification);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -329,7 +335,7 @@ describe('Dashboard', () => {
|
|||||||
new RegExp(`${resumeToDelete.name} was deleted successfully`, 'i'),
|
new RegExp(`${resumeToDelete.name} was deleted successfully`, 'i'),
|
||||||
),
|
),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
fireEvent.click(notification);
|
dismissNotification(notification);
|
||||||
|
|
||||||
await waitForDatabaseRemoveToHaveCompleted();
|
await waitForDatabaseRemoveToHaveCompleted();
|
||||||
});
|
});
|
||||||
@ -342,6 +348,95 @@ describe('Dashboard', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when resume is renamed', () => {
|
||||||
|
// const mockDatabaseUpdateFunction = null;
|
||||||
|
let resumeToRename = null;
|
||||||
|
let resumeToRenameId = null;
|
||||||
|
let nameTextBox = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
const waitForDatabaseUpdateToHaveCompleted = async () => {
|
||||||
|
await waitFor(() => mockDatabaseUpdateFunction.mock.calls[0][0]);
|
||||||
|
await waitFor(() => mockDatabaseUpdateFunction.mock.results[0].value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const expectDatabaseUpdateToHaveCompleted = async () => {
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(mockDatabaseUpdateFunction).toHaveBeenCalledTimes(1),
|
||||||
|
);
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(
|
||||||
|
mockDatabaseUpdateFunction.mock.results[0].value,
|
||||||
|
).resolves.toBeUndefined(),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await setup();
|
||||||
|
|
||||||
|
[resumeToRename] = Object.values(userResumes);
|
||||||
|
resumeToRenameId = resumeToRename.id;
|
||||||
|
|
||||||
|
/*
|
||||||
|
mockDatabaseUpdateFunction = jest.spyOn(
|
||||||
|
FirebaseStub.database().ref(
|
||||||
|
`${DatabaseConstants.resumesPath}/${resumeToRenameId}`,
|
||||||
|
),
|
||||||
|
'update',
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
const resumeToRenameMenuToggle = await screen.findByTestId(
|
||||||
|
`${resumePreviewMenuToggleDataTestIdPrefix}${resumeToRenameId}`,
|
||||||
|
);
|
||||||
|
fireEvent.click(resumeToRenameMenuToggle);
|
||||||
|
|
||||||
|
const menuItems = screen.getAllByRole('menuitem');
|
||||||
|
let renameMenuItem = null;
|
||||||
|
for (let index = 0; index < menuItems.length; index++) {
|
||||||
|
if (queryByText(menuItems[index], /rename/i)) {
|
||||||
|
renameMenuItem = menuItems[index];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fireEvent.click(renameMenuItem);
|
||||||
|
|
||||||
|
nameTextBox = screen.getByRole('textbox', { name: /name/i });
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with name shorter than 5 characters', () => {
|
||||||
|
it('displays validation error and notification', async () => {
|
||||||
|
fireEvent.change(nameTextBox, { target: { value: 'CV 2' } });
|
||||||
|
|
||||||
|
fireEvent.focusOut(nameTextBox);
|
||||||
|
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(
|
||||||
|
screen.getByText(/Please enter at least 5 characters/i),
|
||||||
|
).toBeInTheDocument(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const modalEditResumeButton = screen.getByRole('button', {
|
||||||
|
name: /edit resume/i,
|
||||||
|
});
|
||||||
|
fireEvent.click(modalEditResumeButton);
|
||||||
|
|
||||||
|
// const notification = await screen.findByRole('alert');
|
||||||
|
const notification = await screen.findByText(
|
||||||
|
/You might need to fill up all the required fields/i,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
getByText(
|
||||||
|
notification,
|
||||||
|
/You might need to fill up all the required fields/i,
|
||||||
|
),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
dismissNotification(notification);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('while loading', () => {
|
describe('while loading', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await setup(false);
|
await setup(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user