Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct UUID processing state #1691

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 99 additions & 42 deletions src/landscape/components/LandscapeView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
import { act, fireEvent, render, screen, waitFor, within } from 'tests/utils';
import React from 'react';
import { when } from 'jest-when';
import _ from 'lodash/fp';
import { useParams } from 'react-router-dom';
import * as terrasoApi from 'terraso-client-shared/terrasoApi/api';
Expand Down Expand Up @@ -129,28 +130,12 @@
})),
};

terrasoApi.requestGraphQL
.mockResolvedValueOnce({
landscapes: {
edges: [
{
node: {
name: 'Landscape Name',
description: 'Landscape Description',
website: 'https://www.landscape.org',
location: 'EC',
membershipList: {
memberships,
accountMembership,
membershipsCount: 6,
},
sharedResources,
},
},
],
},
})
.mockResolvedValueOnce({
when(terrasoApi.requestGraphQL)
.calledWith(
expect.stringContaining('query landscapesToView'),
expect.anything()
)
.mockResolvedValue({
landscapes: {
edges: [
{
Expand Down Expand Up @@ -267,29 +252,66 @@
test('LandscapeView: Update Shared Data', async () => {
await baseViewTest();

terrasoApi.requestGraphQL.mockResolvedValueOnce(
_.set(
'updateDataEntry.dataEntry',
{
id: `de-3`,
createdAt: '2022-05-20T16:25:21.536679+00:00',
name: `Data Entry 3`,
createdBy: { id: 'user-id', firstName: 'First', lastName: 'Last' },
size: 3456,
entryType: 'FILE',
},
{}
when(terrasoApi.requestGraphQL)
.calledWith(
expect.stringContaining('mutation updateSharedData'),
expect.objectContaining({
input: {
id: `de-3`,
name: 'Data Entry 3 updated',
description: 'Description 3',
},
})
)
);
terrasoApi.requestGraphQL.mockResolvedValueOnce({});
.mockResolvedValueOnce(
_.set(
'updateDataEntry.dataEntry',
{
id: `de-3`,
createdAt: '2022-05-20T16:25:21.536679+00:00',
name: `Data Entry 3 updated`,
description: 'Description 3',
createdBy: { id: 'user-id', firstName: 'First', lastName: 'Last' },
size: 3456,
entryType: 'FILE',
},
{}
)
);
when(terrasoApi.requestGraphQL)
.calledWith(
expect.stringContaining('mutation updateSharedData'),
expect.objectContaining({
input: {
id: 'de-3',
name: 'Data Entry 3 revised',
description: 'Description 3'

Check failure on line 288 in src/landscape/components/LandscapeView.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
},
})
)
.mockResolvedValueOnce(
_.set(
'updateDataEntry.dataEntry',
{
id: `de-3`,
createdAt: '2022-05-20T16:25:21.536679+00:00',
name: `Data Entry 3 revised`,
description: 'Description 3',
createdBy: { id: 'user-id', firstName: 'First', lastName: 'Last' },
size: 3456,
entryType: 'FILE',
},
{}
)
);

const sharedDataRegion = within(
screen.getByRole('region', { name: 'Shared files and Links' })
);
const entriesList = within(sharedDataRegion.getByRole('list'));
const items = entriesList.getAllByRole('listitem');

const nameField = within(items[3]).getByRole('button', {
let nameField = within(items[3]).getByRole('button', {
name: 'Data Entry 3',
});
expect(nameField).toBeInTheDocument();
Expand All @@ -303,7 +325,7 @@
).toBeInTheDocument()
);

const name = within(items[3]).getByRole('textbox', {
let name = within(items[3]).getByRole('textbox', {
name: 'Update name',
});
fireEvent.change(name, { target: { value: 'Data Entry 3 updated' } });
Expand All @@ -314,13 +336,48 @@
})
)
);
const saveCall = terrasoApi.requestGraphQL.mock.calls[2];

expect(saveCall[1].input).toEqual({
id: 'de-3',
expect(terrasoApi.requestGraphQL).toHaveBeenCalledWith(
expect.stringContaining('mutation updateSharedData'),
{
input: {
id: 'de-3',
name: 'Data Entry 3 updated',
description: 'Description 3',
},
}
);

// Rename a second time to ensure state is reset
nameField = within(items[3]).getByRole('button', {
name: 'Data Entry 3 updated',
description: 'Description 3',
});
expect(nameField).toBeInTheDocument();
await act(async () => fireEvent.click(nameField));

await waitFor(() =>
expect(
within(items[3]).getByRole('textbox', {
name: 'Update name',
})
).toBeInTheDocument()
);

name = within(items[3]).getByRole('textbox', {
name: 'Update name',
});
fireEvent.change(name, { target: { value: 'Data Entry 3 revised' } });
await act(async () =>
fireEvent.click(
within(items[3]).getByRole('button', {
name: 'Save',
})
)
);
expect(terrasoApi.requestGraphQL).toHaveBeenCalledWith(
expect.stringContaining('mutation updateSharedData'),
{ input: { id: 'de-3', name: 'Data Entry 3 revised', description: 'Description 3' } }

Check failure on line 379 in src/landscape/components/LandscapeView.test.js

View workflow job for this annotation

GitHub Actions / lint

Replace `·input:·{·id:·'de-3',·name:·'Data·Entry·3·revised',·description:·'Description·3'·}` with `⏎······input:·{⏎········id:·'de-3',⏎········name:·'Data·Entry·3·revised',⏎········description:·'Description·3',⏎······},⏎···`
);
});

test('LandscapeView: Refresh profile on leave', async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/sharedData/components/SharedDataEntryBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const SharedDataEntryBase = props => {
},
});
}
dispatch(resetProcessing(dataEntry.id));
dispatch(resetProcessing(sharedResource.id));
});
}, [
dataEntry,
Expand Down Expand Up @@ -112,7 +112,7 @@ const SharedDataEntryBase = props => {
props: { [entityType]: owner.slug },
});
}
dispatch(resetProcessing(dataEntry.id));
dispatch(resetProcessing(sharedResource.id));
});
},
[
Expand Down Expand Up @@ -146,11 +146,11 @@ const SharedDataEntryBase = props => {
props: { [entityType]: owner.slug },
});
}
dispatch(resetProcessing(dataEntry.id));
dispatch(resetProcessing(sharedResource.id));
return data;
});
},
[dataEntry, dispatch, owner.slug, trackEvent, updateOwner, entityType]
[dispatch, owner.slug, trackEvent, updateOwner, entityType]
);

const description = useMemo(
Expand Down
Loading