mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-21 12:11:25 +10:00
Dashboard page: added more unit tests for rename resume interaction
This commit is contained in:
@ -102,8 +102,9 @@ describe('Builder', () => {
|
|||||||
|
|
||||||
if (waitForDatabaseUpdateToHaveCompleted) {
|
if (waitForDatabaseUpdateToHaveCompleted) {
|
||||||
await fnWaitForDatabaseUpdateToHaveCompleted();
|
await fnWaitForDatabaseUpdateToHaveCompleted();
|
||||||
mockDatabaseUpdateFunction.mockClear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mockDatabaseUpdateFunction.mockClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('handles errors', () => {
|
describe('handles errors', () => {
|
||||||
|
|||||||
@ -374,12 +374,11 @@ describe('Dashboard', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('when resume is renamed', () => {
|
describe('when resume is renamed', () => {
|
||||||
// const mockDatabaseUpdateFunction = null;
|
let mockDatabaseUpdateFunction = null;
|
||||||
let resumeToRename = null;
|
let resumeToRename = null;
|
||||||
let resumeToRenameId = null;
|
let resumeToRenameId = null;
|
||||||
let nameTextBox = null;
|
let nameTextBox = null;
|
||||||
|
|
||||||
/*
|
|
||||||
const waitForDatabaseUpdateToHaveCompleted = async () => {
|
const waitForDatabaseUpdateToHaveCompleted = async () => {
|
||||||
await waitFor(() => mockDatabaseUpdateFunction.mock.calls[0][0]);
|
await waitFor(() => mockDatabaseUpdateFunction.mock.calls[0][0]);
|
||||||
await waitFor(() => mockDatabaseUpdateFunction.mock.results[0].value);
|
await waitFor(() => mockDatabaseUpdateFunction.mock.results[0].value);
|
||||||
@ -395,7 +394,6 @@ describe('Dashboard', () => {
|
|||||||
).resolves.toBeUndefined(),
|
).resolves.toBeUndefined(),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await setup();
|
await setup();
|
||||||
@ -405,14 +403,13 @@ describe('Dashboard', () => {
|
|||||||
);
|
);
|
||||||
resumeToRenameId = resumeToRename.id;
|
resumeToRenameId = resumeToRename.id;
|
||||||
|
|
||||||
/*
|
|
||||||
mockDatabaseUpdateFunction = jest.spyOn(
|
mockDatabaseUpdateFunction = jest.spyOn(
|
||||||
FirebaseStub.database().ref(
|
FirebaseStub.database().ref(
|
||||||
`${DatabaseConstants.resumesPath}/${resumeToRenameId}`,
|
`${DatabaseConstants.resumesPath}/${resumeToRenameId}`,
|
||||||
),
|
),
|
||||||
'update',
|
'update',
|
||||||
);
|
);
|
||||||
*/
|
mockDatabaseUpdateFunction.mockClear();
|
||||||
|
|
||||||
const resumeToRenameMenuToggle = await screen.findByTestId(
|
const resumeToRenameMenuToggle = await screen.findByTestId(
|
||||||
`${resumePreviewMenuToggleDataTestIdPrefix}${resumeToRenameId}`,
|
`${resumePreviewMenuToggleDataTestIdPrefix}${resumeToRenameId}`,
|
||||||
@ -432,6 +429,10 @@ describe('Dashboard', () => {
|
|||||||
nameTextBox = screen.getByRole('textbox', { name: /name/i });
|
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', () => {
|
describe('with name shorter than 5 characters', () => {
|
||||||
it('displays validation error and notification', async () => {
|
it('displays validation error and notification', async () => {
|
||||||
fireEvent.change(nameTextBox, { target: { value: 'CV 2' } });
|
fireEvent.change(nameTextBox, { target: { value: 'CV 2' } });
|
||||||
@ -462,6 +463,81 @@ describe('Dashboard', () => {
|
|||||||
dismissNotification(notification);
|
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', () => {
|
describe('while loading', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user