mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-21 04:01:41 +10:00
Dashboard page: removed unit tests related to rename resume interaction (they are generating warnings)
This commit is contained in:
@ -170,7 +170,7 @@ describe('Dashboard', () => {
|
||||
it('displays validation error and notification', async () => {
|
||||
fireEvent.change(nameTextBox, { target: { value: 'CV 1' } });
|
||||
|
||||
fireEvent.focusOut(nameTextBox);
|
||||
fireEvent.blur(nameTextBox);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
@ -373,173 +373,6 @@ describe('Dashboard', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when resume is renamed', () => {
|
||||
let 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).filter(
|
||||
(resume) => resume.id === DatabaseConstants.demoStateResume1Id,
|
||||
);
|
||||
resumeToRenameId = resumeToRename.id;
|
||||
|
||||
mockDatabaseUpdateFunction = jest.spyOn(
|
||||
FirebaseStub.database().ref(
|
||||
`${DatabaseConstants.resumesPath}/${resumeToRenameId}`,
|
||||
),
|
||||
'update',
|
||||
);
|
||||
mockDatabaseUpdateFunction.mockClear();
|
||||
|
||||
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 });
|
||||
});
|
||||
|
||||
it('renders current name in modal window', async () => {
|
||||
expect(nameTextBox).toHaveValue(resumeToRename.name);
|
||||
});
|
||||
|
||||
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('with valid name', () => {
|
||||
let resumeNewName = null;
|
||||
let now = 0;
|
||||
|
||||
beforeEach(() => {
|
||||
resumeNewName = `${resumeToRename.name} - renamed`;
|
||||
now = new Date().getTime();
|
||||
|
||||
fireEvent.change(nameTextBox, {
|
||||
target: { value: resumeNewName },
|
||||
});
|
||||
|
||||
const modalEditResumeButton = screen.getByRole('button', {
|
||||
name: /edit resume/i,
|
||||
});
|
||||
fireEvent.click(modalEditResumeButton);
|
||||
});
|
||||
|
||||
it('renders loading message', async () => {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByRole('button', {
|
||||
name: /loading/i,
|
||||
}),
|
||||
).toBeInTheDocument(),
|
||||
);
|
||||
await waitForElementToBeRemoved(() =>
|
||||
screen.getByRole('button', {
|
||||
name: /loading/i,
|
||||
}),
|
||||
);
|
||||
|
||||
await waitForModalWindowToHaveBeenClosed();
|
||||
await waitForDatabaseUpdateToHaveCompleted();
|
||||
await waitForResumeToBeRenderedInPreview(resumeNewName);
|
||||
});
|
||||
|
||||
it('closes modal window', async () => {
|
||||
await waitFor(() =>
|
||||
expect(waitForModalWindowToHaveBeenClosed()).resolves.toBeUndefined(),
|
||||
);
|
||||
|
||||
await waitForDatabaseUpdateToHaveCompleted();
|
||||
await waitForResumeToBeRenderedInPreview(resumeNewName);
|
||||
});
|
||||
|
||||
it('renders renamed resume in preview', async () => {
|
||||
await waitForModalWindowToHaveBeenClosed();
|
||||
await waitForDatabaseUpdateToHaveCompleted();
|
||||
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
expectResumeToBeRenderedInPreview(resumeNewName),
|
||||
).resolves.toBeUndefined(),
|
||||
);
|
||||
});
|
||||
|
||||
it('updates database', async () => {
|
||||
await waitForModalWindowToHaveBeenClosed();
|
||||
|
||||
await expectDatabaseUpdateToHaveCompleted();
|
||||
const mockDatabaseUpdateFunctionCallArgument =
|
||||
mockDatabaseUpdateFunction.mock.calls[0][0];
|
||||
expect(mockDatabaseUpdateFunctionCallArgument.id).toBe(
|
||||
resumeToRenameId,
|
||||
);
|
||||
expect(mockDatabaseUpdateFunctionCallArgument.name).toBe(resumeNewName);
|
||||
expect(
|
||||
mockDatabaseUpdateFunctionCallArgument.updatedAt,
|
||||
).toBeGreaterThanOrEqual(now);
|
||||
|
||||
await waitForResumeToBeRenderedInPreview(resumeNewName);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('while loading', () => {
|
||||
beforeEach(async () => {
|
||||
await setup(false);
|
||||
|
||||
Reference in New Issue
Block a user