mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-14 16:51:33 +10:00
Builder.test: modified draft version of test for data update
This commit is contained in:
@ -8,6 +8,7 @@ const __testUser = {
|
|||||||
};
|
};
|
||||||
let __onAuthStateChangedObservers = [];
|
let __onAuthStateChangedObservers = [];
|
||||||
let __resumesDictionary = {};
|
let __resumesDictionary = {};
|
||||||
|
let __databaseRefUpdateCalls = [];
|
||||||
|
|
||||||
const auth = () => {
|
const auth = () => {
|
||||||
const __init = () => {
|
const __init = () => {
|
||||||
@ -44,6 +45,7 @@ const database = () => {
|
|||||||
|
|
||||||
const __init = () => {
|
const __init = () => {
|
||||||
__resumesDictionary = {};
|
__resumesDictionary = {};
|
||||||
|
__databaseRefUpdateCalls = [];
|
||||||
|
|
||||||
const demoResume = __readFile('../src/data/demoState.json');
|
const demoResume = __readFile('../src/data/demoState.json');
|
||||||
__resumesDictionary[__demoResumeId] = demoResume;
|
__resumesDictionary[__demoResumeId] = demoResume;
|
||||||
@ -134,6 +136,8 @@ const database = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__databaseRefUpdateCalls.push(value);
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -141,6 +145,7 @@ const database = () => {
|
|||||||
once,
|
once,
|
||||||
set,
|
set,
|
||||||
update,
|
update,
|
||||||
|
__updateCalls: __databaseRefUpdateCalls,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -74,6 +74,7 @@ describe('builder', () => {
|
|||||||
resume.profile.address.line1 = newInputValue;
|
resume.profile.address.line1 = newInputValue;
|
||||||
const ref = firebaseMock.database().ref(`resumes/${resumeId}`);
|
const ref = firebaseMock.database().ref(`resumes/${resumeId}`);
|
||||||
const firebaseMockUpdateFunction = jest.spyOn(ref, 'update');
|
const firebaseMockUpdateFunction = jest.spyOn(ref, 'update');
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
await ref.update({
|
await ref.update({
|
||||||
...resume,
|
...resume,
|
||||||
@ -87,26 +88,29 @@ describe('builder', () => {
|
|||||||
firebaseMockUpdateFunction.mock.calls[0][0];
|
firebaseMockUpdateFunction.mock.calls[0][0];
|
||||||
expect(firebaseMockUpdateFunctionCallArgument.id).toBe(resume.id);
|
expect(firebaseMockUpdateFunctionCallArgument.id).toBe(resume.id);
|
||||||
expect(firebaseMockUpdateFunctionCallArgument.profile.address.line1).toBe(newInputValue);
|
expect(firebaseMockUpdateFunctionCallArgument.profile.address.line1).toBe(newInputValue);
|
||||||
|
expect(firebaseMockUpdateFunctionCallArgument.updatedAt).toBeGreaterThanOrEqual(now);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const input = screen.getByLabelText(new RegExp('address line 1', 'i'));
|
const input = screen.getByLabelText(new RegExp('address line 1', 'i'));
|
||||||
const newInputValue = 'test street 123';
|
const newInputValue = 'test street 123';
|
||||||
const ref = firebaseMock.database().ref(`resumes/${resumeId}`);
|
const now = Date.now();
|
||||||
const firebaseMockUpdateFunction = jest.spyOn(ref, 'update');
|
|
||||||
|
|
||||||
fireEvent.change(input, { target: { value: newInputValue } });
|
fireEvent.change(input, { target: { value: newInputValue } });
|
||||||
|
|
||||||
expect(input.value).toBe(newInputValue);
|
expect(input.value).toBe(newInputValue);
|
||||||
|
|
||||||
await waitFor(() =>
|
const databaseRef = firebaseMock.database().ref(`resumes/${resume.id}`);
|
||||||
expect(firebaseMockUpdateFunction).toHaveBeenCalledTimes(1),
|
await waitFor(() => expect(databaseRef.__updateCalls.length).toBe(1), {
|
||||||
);
|
timeout: 4000,
|
||||||
const firebaseMockUpdateFunctionCallArgument =
|
});
|
||||||
firebaseMockUpdateFunction.mock.calls[0][0];
|
const databaseRefUpdateCallArgument = databaseRef.__updateCalls[0];
|
||||||
expect(firebaseMockUpdateFunctionCallArgument.id).toBe(resume.id);
|
expect(databaseRefUpdateCallArgument.id).toBe(resume.id);
|
||||||
expect(firebaseMockUpdateFunctionCallArgument.profile.address.line1).toBe(
|
expect(databaseRefUpdateCallArgument.profile.address.line1).toBe(
|
||||||
newInputValue,
|
newInputValue,
|
||||||
);
|
);
|
||||||
|
expect(databaseRefUpdateCallArgument.updatedAt).toBeGreaterThanOrEqual(
|
||||||
|
now,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user