-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Story Map collaboration events
- Loading branch information
Showing
6 changed files
with
213 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,27 @@ | |
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
*/ | ||
import { render, screen, within } from 'tests/utils'; | ||
import { act, fireEvent, render, screen, within } from 'tests/utils'; | ||
import * as terrasoApi from 'terraso-client-shared/terrasoApi/api'; | ||
import { mockTerrasoAPIrequestGraphQL } from 'tests/apiUtils'; | ||
|
||
import { useAnalytics } from 'monitoring/analytics'; | ||
|
||
import StoryMapsToolsHome from './StoryMapsToolHome'; | ||
|
||
jest.mock('terraso-client-shared/terrasoApi/api'); | ||
|
||
jest.mock('monitoring/analytics', () => ({ | ||
...jest.requireActual('monitoring/analytics'), | ||
useAnalytics: jest.fn(), | ||
})); | ||
|
||
beforeEach(() => { | ||
useAnalytics.mockReturnValue({ | ||
trackEvent: jest.fn(), | ||
}); | ||
}); | ||
|
||
test('StoryMapsToolHome: samples renders correctly', async () => { | ||
terrasoApi.requestGraphQL.mockReturnValue( | ||
Promise.resolve({ | ||
|
@@ -158,3 +172,134 @@ test('StoryMapsToolHome: user story maps render correctly', async () => { | |
const link1 = within(items[1]).getByRole('link', { name: 'Story 1' }); | ||
expect(link1).toHaveAttribute('href', '/tools/story-maps/46h36we/id-1/edit'); | ||
}); | ||
|
||
test('StoryMapsToolHome: accept story map invite', async () => { | ||
const trackEvent = jest.fn(); | ||
useAnalytics.mockReturnValue({ | ||
trackEvent, | ||
}); | ||
mockTerrasoAPIrequestGraphQL({ | ||
'query storyMapsHome': Promise.resolve({ | ||
userStoryMaps: { | ||
edges: [ | ||
{ | ||
node: { | ||
id: 'id-1', | ||
slug: 'id-1', | ||
storyMapId: '46h36we', | ||
title: 'Story 1', | ||
isPublished: false, | ||
updatedAt: '2023-01-31T22:25:42.916303+00:00', | ||
createdBy: { | ||
userId: 'other-user-id', | ||
firstName: 'Pablo', | ||
lastName: 'Perez', | ||
}, | ||
membershipList: { | ||
membershipsCount: 0, | ||
accountMembership: { | ||
id: '12eb041f-e847-4f78-89ec-46a6a6b7c5c6', | ||
userRole: 'editor', | ||
membershipStatus: 'PENDING', | ||
}, | ||
// memberships: { | ||
// edges: [ | ||
// { | ||
// node: { | ||
// id: '92a116e3-65f8-4cf5-a564-de390928c87e', | ||
// userRole: 'editor', | ||
// membershipStatus: 'PENDING', | ||
// pendingEmail: '[email protected]', | ||
// user: null, | ||
// }, | ||
// }, | ||
// ], | ||
// }, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}), | ||
'mutation approveMembership': Promise.resolve({ | ||
approveStoryMapMembership: { | ||
membership: { | ||
id: 'membership-id-1', | ||
}, | ||
storyMap: { | ||
id: 'story-map-id-1', | ||
title: 'Hello world', | ||
storyMapId: 'story-map-id-1', | ||
slug: 'hello-world', | ||
}, | ||
}, | ||
}), | ||
}); | ||
// terrasoApi.requestGraphQL.mockReturnValue( | ||
// Promise.resolve({ | ||
// userStoryMaps: { | ||
// edges: [ | ||
// { | ||
// node: { | ||
// id: 'id-1', | ||
// slug: 'id-1', | ||
// storyMapId: '46h36we', | ||
// title: 'Story 1', | ||
// isPublished: false, | ||
// updatedAt: '2023-01-31T22:25:42.916303+00:00', | ||
// createdBy: { | ||
// userId: 'other-user-id', | ||
// firstName: 'Pablo', | ||
// lastName: 'Perez', | ||
// }, | ||
// membershipList: { | ||
// membershipsCount: 0, | ||
// accountMembership: { | ||
// id: '12eb041f-e847-4f78-89ec-46a6a6b7c5c6', | ||
// userRole: 'editor', | ||
// membershipStatus: 'PENDING', | ||
// }, | ||
// // memberships: { | ||
// // edges: [ | ||
// // { | ||
// // node: { | ||
// // id: '92a116e3-65f8-4cf5-a564-de390928c87e', | ||
// // userRole: 'editor', | ||
// // membershipStatus: 'PENDING', | ||
// // pendingEmail: '[email protected]', | ||
// // user: null, | ||
// // }, | ||
// // }, | ||
// // ], | ||
// // }, | ||
// }, | ||
// }, | ||
// }, | ||
// ], | ||
// }, | ||
// }) | ||
// ); | ||
|
||
await render(<StoryMapsToolsHome />, { | ||
account: { | ||
currentUser: { | ||
data: { | ||
email: '[email protected]', | ||
firstName: 'Jodies', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const storyMapItem = screen.getByRole('listitem', { name: 'Story 1' }); | ||
|
||
const acceptButton = within(storyMapItem).getByRole('button', { | ||
name: 'Accept', | ||
}); | ||
|
||
await act(async () => { | ||
fireEvent.click(acceptButton); | ||
}); | ||
|
||
expect(trackEvent).toHaveBeenCalledWith('storymap.share.accept'); | ||
}); |