Skip to content

Commit

Permalink
test: Fixed revised case test
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed Mar 27, 2024
1 parent 2a9bb57 commit 5a352b1
Showing 1 changed file with 69 additions and 49 deletions.
118 changes: 69 additions & 49 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 @@ const baseViewTest = async (
})),
};

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,21 +252,55 @@ test('LandscapeView: Managers do not see warning', async () => {
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`,
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',
},
})
)
.mockResolvedValueOnce(
_.set(
'updateDataEntry.dataEntry',
{
id: `de-3`,
createdAt: '2022-05-20T16:25:21.536679+00:00',
name: `Data Entry 3 revised`,
createdBy: { id: 'user-id', firstName: 'First', lastName: 'Last' },
size: 3456,
entryType: 'FILE',
},
{}
)
);

const sharedDataRegion = within(
screen.getByRole('region', { name: 'Shared files and Links' })
Expand Down Expand Up @@ -314,13 +333,17 @@ test('LandscapeView: Update Shared Data', async () => {
})
)
);
let saveCall = terrasoApi.requestGraphQL.mock.calls[2];

expect(saveCall[1].input).toEqual({
id: 'de-3',
name: 'Data Entry 3 updated',
description: 'Description 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', {
Expand Down Expand Up @@ -348,13 +371,10 @@ test('LandscapeView: Update Shared Data', async () => {
})
)
);
saveCall = terrasoApi.requestGraphQL.mock.calls[2];

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

test('LandscapeView: Refresh profile on leave', async () => {
Expand Down

0 comments on commit 5a352b1

Please sign in to comment.