mirror of
https://github.com/directus/directus.git
synced 2026-02-16 03:15:05 -05:00
Private view (#41)
* Add file structure * Add basics of private view * Add composition api in every test * Install nanoid * Add request queue * Register all global components * Make bunny run on api queue * Use private route for debug now * Move request queue to store * Remove unused sleep function in hover test * Use new request queue in private view * Remove jest pre-test config * Finish logo + tests * Add tests for private view * Fix unhandled promise in api test
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import { getRootPath } from './api';
|
||||
import Vue from 'vue';
|
||||
import VueCompositionAPI from '@vue/composition-api';
|
||||
import { onRequest, onResponse, onError, getRootPath } from './api';
|
||||
import { useRequestsStore } from '@/stores/requests';
|
||||
|
||||
describe('API', () => {
|
||||
beforeAll(() => {
|
||||
globalThis.window = Object.create(window);
|
||||
Vue.use(VueCompositionAPI);
|
||||
});
|
||||
|
||||
it('Calculates the correct API root URL based on window', () => {
|
||||
@@ -16,4 +20,46 @@ describe('API', () => {
|
||||
const result = getRootPath();
|
||||
expect(result).toBe('/api/nested/');
|
||||
});
|
||||
|
||||
it('Calls startRequest on the store on any request', () => {
|
||||
const store = useRequestsStore({});
|
||||
const spy = jest.spyOn(store, 'startRequest');
|
||||
spy.mockImplementation(() => 'abc');
|
||||
const newRequest = onRequest({});
|
||||
expect(spy).toHaveBeenCalled();
|
||||
expect(newRequest.id).toBe('abc');
|
||||
});
|
||||
|
||||
it('Calls endRequest on responses', () => {
|
||||
const store = useRequestsStore({});
|
||||
const spy = jest.spyOn(store, 'endRequest');
|
||||
onResponse({
|
||||
data: null,
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {},
|
||||
config: {
|
||||
id: 'abc'
|
||||
}
|
||||
});
|
||||
expect(spy).toHaveBeenCalledWith('abc');
|
||||
});
|
||||
|
||||
it('Calls endRequest on errors', async () => {
|
||||
const store = useRequestsStore({});
|
||||
const spy = jest.spyOn(store, 'endRequest');
|
||||
try {
|
||||
await onError({
|
||||
response: {
|
||||
config: {
|
||||
id: 'abc'
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
expect(error).toEqual({ response: { config: { id: 'abc' } } });
|
||||
}
|
||||
|
||||
expect(spy).toHaveBeenCalledWith('abc');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user