2022-07-26 10:53:08 -07:00
|
|
|
import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
|
2022-06-20 06:46:43 -07:00
|
|
|
|
2022-07-06 15:02:44 -07:00
|
|
|
import { mockStore, rootState } from 'soapbox/jest/test-helpers';
|
2022-03-28 13:30:27 -07:00
|
|
|
import { InstanceRecord } from 'soapbox/normalizers';
|
2022-09-14 13:05:40 -07:00
|
|
|
import { ReducerCompose } from 'soapbox/reducers/compose';
|
2022-03-28 13:30:27 -07:00
|
|
|
|
2022-07-26 10:53:08 -07:00
|
|
|
import { uploadCompose, submitCompose } from '../compose';
|
|
|
|
import { STATUS_CREATE_REQUEST } from '../statuses';
|
2022-03-28 13:30:27 -07:00
|
|
|
|
2022-07-06 15:02:44 -07:00
|
|
|
import type { IntlShape } from 'react-intl';
|
|
|
|
|
2022-03-28 13:30:27 -07:00
|
|
|
describe('uploadCompose()', () => {
|
|
|
|
describe('with images', () => {
|
2022-07-06 15:02:44 -07:00
|
|
|
let files: FileList, store: ReturnType<typeof mockStore>;
|
2022-03-28 13:30:27 -07:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const instance = InstanceRecord({
|
2022-07-06 15:02:44 -07:00
|
|
|
configuration: ImmutableMap({
|
|
|
|
statuses: ImmutableMap({
|
2022-03-28 13:30:27 -07:00
|
|
|
max_media_attachments: 4,
|
2022-07-06 15:02:44 -07:00
|
|
|
}),
|
|
|
|
media_attachments: ImmutableMap({
|
2022-03-28 13:30:27 -07:00
|
|
|
image_size_limit: 10,
|
2022-07-06 15:02:44 -07:00
|
|
|
}),
|
2022-06-20 06:46:43 -07:00
|
|
|
}),
|
2022-03-28 13:30:27 -07:00
|
|
|
});
|
|
|
|
|
2022-07-06 15:02:44 -07:00
|
|
|
const state = rootState
|
2022-03-28 13:30:27 -07:00
|
|
|
.set('me', '1234')
|
2022-09-14 13:05:40 -07:00
|
|
|
.set('instance', instance)
|
|
|
|
.setIn(['compose', 'home'], ReducerCompose());
|
2022-03-28 13:30:27 -07:00
|
|
|
|
|
|
|
store = mockStore(state);
|
|
|
|
files = [{
|
|
|
|
uri: 'image.png',
|
|
|
|
name: 'Image',
|
|
|
|
size: 15,
|
|
|
|
type: 'image/png',
|
2022-07-06 15:02:44 -07:00
|
|
|
}] as unknown as FileList;
|
2022-03-28 13:30:27 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('creates an alert if exceeds max size', async() => {
|
2022-03-30 07:36:01 -07:00
|
|
|
const mockIntl = {
|
|
|
|
formatMessage: jest.fn().mockReturnValue('Image exceeds the current file size limit (10 Bytes)'),
|
2022-07-06 15:02:44 -07:00
|
|
|
} as unknown as IntlShape;
|
2022-03-30 07:36:01 -07:00
|
|
|
|
2022-03-28 13:30:27 -07:00
|
|
|
const expectedActions = [
|
2022-09-14 13:05:40 -07:00
|
|
|
{ type: 'COMPOSE_UPLOAD_REQUEST', id: 'home', skipLoading: true },
|
|
|
|
{ type: 'COMPOSE_UPLOAD_FAIL', id: 'home', error: true, skipLoading: true },
|
2022-03-28 13:30:27 -07:00
|
|
|
];
|
|
|
|
|
2022-09-14 13:05:40 -07:00
|
|
|
await store.dispatch(uploadCompose('home', files, mockIntl));
|
2022-03-28 13:30:27 -07:00
|
|
|
const actions = store.getActions();
|
|
|
|
|
|
|
|
expect(actions).toEqual(expectedActions);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with videos', () => {
|
2022-07-06 15:02:44 -07:00
|
|
|
let files: FileList, store: ReturnType<typeof mockStore>;
|
2022-03-28 13:30:27 -07:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const instance = InstanceRecord({
|
2022-07-06 15:02:44 -07:00
|
|
|
configuration: ImmutableMap({
|
|
|
|
statuses: ImmutableMap({
|
2022-03-28 13:30:27 -07:00
|
|
|
max_media_attachments: 4,
|
2022-07-06 15:02:44 -07:00
|
|
|
}),
|
|
|
|
media_attachments: ImmutableMap({
|
2022-03-28 13:30:27 -07:00
|
|
|
video_size_limit: 10,
|
2022-07-06 15:02:44 -07:00
|
|
|
}),
|
2022-06-20 06:46:43 -07:00
|
|
|
}),
|
2022-03-28 13:30:27 -07:00
|
|
|
});
|
|
|
|
|
2022-07-06 15:02:44 -07:00
|
|
|
const state = rootState
|
2022-03-28 13:30:27 -07:00
|
|
|
.set('me', '1234')
|
2022-09-14 13:05:40 -07:00
|
|
|
.set('instance', instance)
|
|
|
|
.setIn(['compose', 'home'], ReducerCompose());
|
2022-03-28 13:30:27 -07:00
|
|
|
|
|
|
|
store = mockStore(state);
|
|
|
|
files = [{
|
|
|
|
uri: 'video.mp4',
|
|
|
|
name: 'Video',
|
|
|
|
size: 15,
|
|
|
|
type: 'video/mp4',
|
2022-07-06 15:02:44 -07:00
|
|
|
}] as unknown as FileList;
|
2022-03-28 13:30:27 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it('creates an alert if exceeds max size', async() => {
|
2022-03-30 07:36:01 -07:00
|
|
|
const mockIntl = {
|
|
|
|
formatMessage: jest.fn().mockReturnValue('Video exceeds the current file size limit (10 Bytes)'),
|
2022-07-06 15:02:44 -07:00
|
|
|
} as unknown as IntlShape;
|
2022-03-30 07:36:01 -07:00
|
|
|
|
2022-03-28 13:30:27 -07:00
|
|
|
const expectedActions = [
|
2022-09-14 13:05:40 -07:00
|
|
|
{ type: 'COMPOSE_UPLOAD_REQUEST', id: 'home', skipLoading: true },
|
|
|
|
{ type: 'COMPOSE_UPLOAD_FAIL', id: 'home', error: true, skipLoading: true },
|
2022-03-28 13:30:27 -07:00
|
|
|
];
|
|
|
|
|
2022-09-14 13:05:40 -07:00
|
|
|
await store.dispatch(uploadCompose('home', files, mockIntl));
|
2022-03-28 13:30:27 -07:00
|
|
|
const actions = store.getActions();
|
|
|
|
|
|
|
|
expect(actions).toEqual(expectedActions);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-07-26 10:53:08 -07:00
|
|
|
|
|
|
|
describe('submitCompose()', () => {
|
|
|
|
it('inserts mentions from text', async() => {
|
|
|
|
const state = rootState
|
|
|
|
.set('me', '123')
|
2022-09-14 13:05:40 -07:00
|
|
|
.setIn(['compose', 'home'], ReducerCompose({ text: '@alex hello @mkljczk@pl.fediverse.pl @gg@汉语/漢語.com alex@alexgleason.me' }));
|
2022-07-26 10:53:08 -07:00
|
|
|
|
|
|
|
const store = mockStore(state);
|
2022-09-14 13:05:40 -07:00
|
|
|
await store.dispatch(submitCompose('home'));
|
2022-07-26 10:53:08 -07:00
|
|
|
const actions = store.getActions();
|
|
|
|
|
|
|
|
const statusCreateRequest = actions.find(action => action.type === STATUS_CREATE_REQUEST);
|
|
|
|
const to = statusCreateRequest!.params.to as ImmutableOrderedSet<string>;
|
|
|
|
|
|
|
|
const expected = [
|
|
|
|
'alex',
|
|
|
|
'mkljczk@pl.fediverse.pl',
|
|
|
|
'gg@汉语/漢語.com',
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(to.toJS()).toEqual(expected);
|
|
|
|
});
|
|
|
|
});
|