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 __resumesDictionary = {};
|
||||
let __databaseRefUpdateCalls = [];
|
||||
|
||||
const auth = () => {
|
||||
const __init = () => {
|
||||
@ -44,6 +45,7 @@ const database = () => {
|
||||
|
||||
const __init = () => {
|
||||
__resumesDictionary = {};
|
||||
__databaseRefUpdateCalls = [];
|
||||
|
||||
const demoResume = __readFile('../src/data/demoState.json');
|
||||
__resumesDictionary[__demoResumeId] = demoResume;
|
||||
@ -134,6 +136,8 @@ const database = () => {
|
||||
}
|
||||
}
|
||||
|
||||
__databaseRefUpdateCalls.push(value);
|
||||
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
@ -141,6 +145,7 @@ const database = () => {
|
||||
once,
|
||||
set,
|
||||
update,
|
||||
__updateCalls: __databaseRefUpdateCalls,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -74,6 +74,7 @@ describe('builder', () => {
|
||||
resume.profile.address.line1 = newInputValue;
|
||||
const ref = firebaseMock.database().ref(`resumes/${resumeId}`);
|
||||
const firebaseMockUpdateFunction = jest.spyOn(ref, 'update');
|
||||
const now = Date.now();
|
||||
|
||||
await ref.update({
|
||||
...resume,
|
||||
@ -87,26 +88,29 @@ describe('builder', () => {
|
||||
firebaseMockUpdateFunction.mock.calls[0][0];
|
||||
expect(firebaseMockUpdateFunctionCallArgument.id).toBe(resume.id);
|
||||
expect(firebaseMockUpdateFunctionCallArgument.profile.address.line1).toBe(newInputValue);
|
||||
expect(firebaseMockUpdateFunctionCallArgument.updatedAt).toBeGreaterThanOrEqual(now);
|
||||
*/
|
||||
|
||||
const input = screen.getByLabelText(new RegExp('address line 1', 'i'));
|
||||
const newInputValue = 'test street 123';
|
||||
const ref = firebaseMock.database().ref(`resumes/${resumeId}`);
|
||||
const firebaseMockUpdateFunction = jest.spyOn(ref, 'update');
|
||||
const now = Date.now();
|
||||
|
||||
fireEvent.change(input, { target: { value: newInputValue } });
|
||||
|
||||
expect(input.value).toBe(newInputValue);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(firebaseMockUpdateFunction).toHaveBeenCalledTimes(1),
|
||||
);
|
||||
const firebaseMockUpdateFunctionCallArgument =
|
||||
firebaseMockUpdateFunction.mock.calls[0][0];
|
||||
expect(firebaseMockUpdateFunctionCallArgument.id).toBe(resume.id);
|
||||
expect(firebaseMockUpdateFunctionCallArgument.profile.address.line1).toBe(
|
||||
const databaseRef = firebaseMock.database().ref(`resumes/${resume.id}`);
|
||||
await waitFor(() => expect(databaseRef.__updateCalls.length).toBe(1), {
|
||||
timeout: 4000,
|
||||
});
|
||||
const databaseRefUpdateCallArgument = databaseRef.__updateCalls[0];
|
||||
expect(databaseRefUpdateCallArgument.id).toBe(resume.id);
|
||||
expect(databaseRefUpdateCallArgument.profile.address.line1).toBe(
|
||||
newInputValue,
|
||||
);
|
||||
expect(databaseRefUpdateCallArgument.updatedAt).toBeGreaterThanOrEqual(
|
||||
now,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user