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:
@ -126,8 +126,6 @@ const database = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const update = async (value) => {
|
const update = async (value) => {
|
||||||
console.log('update');
|
|
||||||
console.log(value);
|
|
||||||
if (resumesPath) {
|
if (resumesPath) {
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
delete __resumesDictionary[databaseLocationId];
|
delete __resumesDictionary[databaseLocationId];
|
||||||
|
|||||||
@ -69,28 +69,44 @@ describe('builder', () => {
|
|||||||
|
|
||||||
describe('updates data', () => {
|
describe('updates data', () => {
|
||||||
it('when input value is changed', async () => {
|
it('when input value is changed', async () => {
|
||||||
|
/*
|
||||||
|
const newInputValue = 'test street 123';
|
||||||
|
resume.profile.address.line1 = newInputValue;
|
||||||
|
const ref = firebaseMock.database().ref(`resumes/${resumeId}`);
|
||||||
|
const firebaseMockUpdateFunction = jest.spyOn(ref, 'update');
|
||||||
|
|
||||||
|
await ref.update({
|
||||||
|
...resume,
|
||||||
|
updatedAt: firebaseMock.database().ServerValue.TIMESTAMP,
|
||||||
|
});
|
||||||
|
|
||||||
|
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(newInputValue);
|
||||||
|
*/
|
||||||
|
|
||||||
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 spy = jest.spyOn(
|
const ref = firebaseMock.database().ref(`resumes/${resumeId}`);
|
||||||
firebaseMock.database().ref(`resumes/${resumeId}`),
|
const firebaseMockUpdateFunction = jest.spyOn(ref, 'update');
|
||||||
'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(() => expect(spy).toHaveBeenCalledTimes(1), {
|
await waitFor(() =>
|
||||||
timeout: 4000,
|
expect(firebaseMockUpdateFunction).toHaveBeenCalledTimes(1),
|
||||||
});
|
);
|
||||||
//const promise = spy.mock.results[0].value;
|
const firebaseMockUpdateFunctionCallArgument =
|
||||||
//await spy();
|
firebaseMockUpdateFunction.mock.calls[0][0];
|
||||||
//expect(spy).toHaveBeenCalledTimes(1);
|
expect(firebaseMockUpdateFunctionCallArgument.id).toBe(resume.id);
|
||||||
|
expect(firebaseMockUpdateFunctionCallArgument.profile.address.line1).toBe(
|
||||||
resume = (
|
newInputValue,
|
||||||
await firebaseMock.database().ref(`resumes/${resumeId}`).once('value')
|
);
|
||||||
).val();
|
|
||||||
expect(resume.profile.address.line1).toBe(newInputValue);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user