-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Grant followers modal (#3505)
* replace computed flag * add followers modal * add/update tests * merge testing setup * adjustments * update date display * fix test * include current user in results * update event type * use luxon * replace order by pagination
- Loading branch information
1 parent
9488946
commit 647dacf
Showing
8 changed files
with
423 additions
and
79 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
90 changes: 90 additions & 0 deletions
90
packages/client/src/components/Modals/GrantFollowers.spec.js
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { | ||
describe, beforeEach, it, expect, vi, | ||
} from 'vitest'; | ||
import { mount, flushPromises } from '@vue/test-utils'; | ||
import { createStore } from 'vuex'; | ||
import GrantFollowers from '@/components/Modals/GrantFollowers.vue'; | ||
|
||
const mockStore = { | ||
getters: { | ||
'grants/currentGrant': () => ({ | ||
grant_id: 55, | ||
}), | ||
}, | ||
actions: { | ||
'grants/getFollowersForGrant': vi.fn(), | ||
}, | ||
}; | ||
|
||
const store = createStore(mockStore); | ||
|
||
const getMockFollowers = (count, hasMoreCursor = null) => ({ | ||
followers: Array.from(Array(count), () => ({ | ||
id: Math.random(), | ||
user: { | ||
id: Math.random(), | ||
name: 'Follower', | ||
email: 'name@email', | ||
team: { | ||
name: 'Team', | ||
}, | ||
}, | ||
})), | ||
pagination: { | ||
next: hasMoreCursor, | ||
}, | ||
}); | ||
|
||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(GrantFollowers, { | ||
global: { | ||
plugins: [store], | ||
}, | ||
props: { | ||
modalId: 'followers-modal', | ||
}, | ||
}); | ||
}); | ||
|
||
describe('GrantFollowers.vue', () => { | ||
it('should fetch the followers when loaded', async () => { | ||
mockStore.actions['grants/getFollowersForGrant'].mockResolvedValue(getMockFollowers(20)); | ||
|
||
const modal = wrapper.findComponent({ name: 'b-modal' }); | ||
modal.trigger('show'); | ||
|
||
await flushPromises(); | ||
|
||
const followers = wrapper.findAll('[data-test-follower]'); | ||
|
||
expect(followers).toHaveLength(20); | ||
}); | ||
|
||
it('should load re-fetch followers when user clicks Show More', async () => { | ||
// Mock first batch of records | ||
mockStore.actions['grants/getFollowersForGrant'].mockResolvedValue(getMockFollowers(20, 'id-x')); | ||
|
||
const modal = wrapper.findComponent({ name: 'b-modal' }); | ||
modal.trigger('show'); | ||
|
||
await flushPromises(); | ||
expect(mockStore.actions['grants/getFollowersForGrant'].mock.lastCall[1].paginateFrom).toBeUndefined(); | ||
|
||
const showMoreBtn = wrapper.findComponent('[data-test-show-more-btn]'); | ||
|
||
// Mock second batch of records | ||
mockStore.actions['grants/getFollowersForGrant'].mockResolvedValue(getMockFollowers(20)); | ||
|
||
showMoreBtn.trigger('click'); | ||
|
||
await flushPromises(); | ||
expect(mockStore.actions['grants/getFollowersForGrant'].mock.lastCall[1].paginateFrom).to.equal('id-x'); | ||
|
||
const followers = wrapper.findAll('[data-test-follower]'); | ||
|
||
expect(followers).toHaveLength(40); | ||
expect(wrapper.findComponent('[data-test-show-more-btn]').exists()).to.equal(false); | ||
}); | ||
}); |
Oops, something went wrong.