H-296: cover stale Captain Skills list errors (#52)
* test: cover stale captain skill list errors * test: flush stale skill request rejection --------- Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
+46
-3
@@ -1,4 +1,4 @@
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
import { flushPromises, shallowMount } from '@vue/test-utils';
|
||||
import Index from './Index.vue';
|
||||
|
||||
const mocked = vi.hoisted(() => ({
|
||||
@@ -11,13 +11,21 @@ const mocked = vi.hoisted(() => ({
|
||||
}));
|
||||
|
||||
vi.mock('dashboard/composables/store', async () => {
|
||||
const { computed } = await vi.importActual('vue');
|
||||
const { computed, reactive } = await vi.importActual('vue');
|
||||
const state = reactive({ records: [] });
|
||||
Object.defineProperty(mocked, 'records', {
|
||||
configurable: true,
|
||||
get: () => state.records,
|
||||
set: value => {
|
||||
state.records = value;
|
||||
},
|
||||
});
|
||||
return {
|
||||
useStore: () => ({ dispatch: (...args) => mocked.dispatch(...args) }),
|
||||
useMapGetter: key =>
|
||||
computed(() =>
|
||||
key === 'captainSkills/getRecords'
|
||||
? mocked.records
|
||||
? state.records
|
||||
: mocked.flags
|
||||
),
|
||||
};
|
||||
@@ -87,6 +95,41 @@ describe('Assistant skills page', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps the latest list when an older assistant request fails', async () => {
|
||||
let rejectOldRequest;
|
||||
let resolveNewRequest;
|
||||
const newAssistantSkills = [
|
||||
{ ...activeSkill, id: 10, name: 'Shipping', bound: true },
|
||||
];
|
||||
mocked.dispatch = vi.fn().mockImplementation((action, params) => {
|
||||
if (action !== 'captainSkills/get') return Promise.resolve([]);
|
||||
if (params.assistantId === 9) {
|
||||
return new Promise((_, reject) => {
|
||||
rejectOldRequest = reject;
|
||||
});
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
resolveNewRequest = payload => {
|
||||
mocked.records = payload;
|
||||
resolve(payload);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const wrapper = mountPage();
|
||||
mocked.route.params.assistantId = 10;
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
resolveNewRequest(newAssistantSkills);
|
||||
await Promise.resolve();
|
||||
rejectOldRequest(new Error('old assistant request failed'));
|
||||
await flushPromises();
|
||||
|
||||
expect(mocked.records).toEqual(newAssistantSkills);
|
||||
expect(wrapper.text()).toContain('Shipping');
|
||||
expect(wrapper.find('[role="alert"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('groups bound and available skills', () => {
|
||||
mocked.records = [
|
||||
{ ...activeSkill, bound: true },
|
||||
|
||||
Reference in New Issue
Block a user