mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-05-28 16:16:24 +00:00
Ensured domain is passed when editing tags for a short URL on a specific domain
This commit is contained in:
@@ -19,7 +19,7 @@ const EditTagsModal = (TagsSelector) => class EditTagsModal extends React.Compon
|
|||||||
saveTags = () => {
|
saveTags = () => {
|
||||||
const { editShortUrlTags, shortUrl, toggle } = this.props;
|
const { editShortUrlTags, shortUrl, toggle } = this.props;
|
||||||
|
|
||||||
editShortUrlTags(shortUrl.shortCode, this.state.tags)
|
editShortUrlTags(shortUrl.shortCode, shortUrl.domain, this.state.tags)
|
||||||
.then(toggle)
|
.then(toggle)
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export const editShortUrlMeta = (buildShlinkApiClient) => (shortCode, meta) => a
|
|||||||
const { updateShortUrlMeta } = await buildShlinkApiClient(getState);
|
const { updateShortUrlMeta } = await buildShlinkApiClient(getState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await updateShortUrlMeta(shortCode, meta);
|
await updateShortUrlMeta(shortCode, undefined, meta);
|
||||||
dispatch({ shortCode, meta, type: SHORT_URL_META_EDITED });
|
dispatch({ shortCode, meta, type: SHORT_URL_META_EDITED });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dispatch({ type: EDIT_SHORT_URL_META_ERROR });
|
dispatch({ type: EDIT_SHORT_URL_META_ERROR });
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ export default handleActions({
|
|||||||
[RESET_EDIT_SHORT_URL_TAGS]: () => initialState,
|
[RESET_EDIT_SHORT_URL_TAGS]: () => initialState,
|
||||||
}, initialState);
|
}, initialState);
|
||||||
|
|
||||||
export const editShortUrlTags = (buildShlinkApiClient) => (shortCode, tags) => async (dispatch, getState) => {
|
export const editShortUrlTags = (buildShlinkApiClient) => (shortCode, domain, tags) => async (dispatch, getState) => {
|
||||||
dispatch({ type: EDIT_SHORT_URL_TAGS_START });
|
dispatch({ type: EDIT_SHORT_URL_TAGS_START });
|
||||||
const { updateShortUrlTags } = await buildShlinkApiClient(getState);
|
const { updateShortUrlTags } = await buildShlinkApiClient(getState);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const normalizedTags = await updateShortUrlTags(shortCode, tags);
|
const normalizedTags = await updateShortUrlTags(shortCode, domain, tags);
|
||||||
|
|
||||||
dispatch({ tags: normalizedTags, shortCode, type: SHORT_URL_TAGS_EDITED });
|
dispatch({ tags: normalizedTags, shortCode, type: SHORT_URL_TAGS_EDITED });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React from 'react';
|
|||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import { Modal } from 'reactstrap';
|
import { Modal } from 'reactstrap';
|
||||||
import createEditTagsModal from '../../../src/short-urls/helpers/EditTagsModal';
|
import createEditTagsModal from '../../../src/short-urls/helpers/EditTagsModal';
|
||||||
|
import each from 'jest-each';
|
||||||
|
|
||||||
describe('<EditTagsModal />', () => {
|
describe('<EditTagsModal />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
@@ -10,7 +11,7 @@ describe('<EditTagsModal />', () => {
|
|||||||
const editShortUrlTags = jest.fn(() => Promise.resolve());
|
const editShortUrlTags = jest.fn(() => Promise.resolve());
|
||||||
const resetShortUrlsTags = jest.fn();
|
const resetShortUrlsTags = jest.fn();
|
||||||
const toggle = jest.fn();
|
const toggle = jest.fn();
|
||||||
const createWrapper = (shortUrlTags) => {
|
const createWrapper = (shortUrlTags, domain) => {
|
||||||
const EditTagsModal = createEditTagsModal(TagsSelector);
|
const EditTagsModal = createEditTagsModal(TagsSelector);
|
||||||
|
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
@@ -19,6 +20,7 @@ describe('<EditTagsModal />', () => {
|
|||||||
shortUrl={{
|
shortUrl={{
|
||||||
tags: [],
|
tags: [],
|
||||||
shortCode,
|
shortCode,
|
||||||
|
domain,
|
||||||
originalUrl: 'https://long-domain.com/foo/bar',
|
originalUrl: 'https://long-domain.com/foo/bar',
|
||||||
}}
|
}}
|
||||||
shortUrlTags={shortUrlTags}
|
shortUrlTags={shortUrlTags}
|
||||||
@@ -74,19 +76,19 @@ describe('<EditTagsModal />', () => {
|
|||||||
expect(saveBtn.text()).toEqual('Saving tags...');
|
expect(saveBtn.text()).toEqual('Saving tags...');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('saves tags when save button is clicked', (done) => {
|
each([[ undefined ], [ null ], [ 'example.com' ]]).it('saves tags when save button is clicked', (domain, done) => {
|
||||||
const wrapper = createWrapper({
|
const wrapper = createWrapper({
|
||||||
shortCode,
|
shortCode,
|
||||||
tags: [],
|
tags: [],
|
||||||
saving: true,
|
saving: true,
|
||||||
error: false,
|
error: false,
|
||||||
});
|
}, domain);
|
||||||
const saveBtn = wrapper.find('.btn-primary');
|
const saveBtn = wrapper.find('.btn-primary');
|
||||||
|
|
||||||
saveBtn.simulate('click');
|
saveBtn.simulate('click');
|
||||||
|
|
||||||
expect(editShortUrlTags).toHaveBeenCalledTimes(1);
|
expect(editShortUrlTags).toHaveBeenCalledTimes(1);
|
||||||
expect(editShortUrlTags).toHaveBeenCalledWith(shortCode, []);
|
expect(editShortUrlTags).toHaveBeenCalledWith(shortCode, domain, []);
|
||||||
|
|
||||||
// Wrap this expect in a setImmediate since it is called as a result of an inner promise
|
// Wrap this expect in a setImmediate since it is called as a result of an inner promise
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ describe('shortUrlMetaReducer', () => {
|
|||||||
|
|
||||||
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
|
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
|
||||||
expect(updateShortUrlMeta).toHaveBeenCalledTimes(1);
|
expect(updateShortUrlMeta).toHaveBeenCalledTimes(1);
|
||||||
expect(updateShortUrlMeta).toHaveBeenCalledWith(shortCode, meta);
|
expect(updateShortUrlMeta).toHaveBeenCalledWith(shortCode, undefined, meta);
|
||||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_META_START });
|
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_META_START });
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_META_EDITED, meta, shortCode });
|
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_META_EDITED, meta, shortCode });
|
||||||
@@ -80,7 +80,7 @@ describe('shortUrlMetaReducer', () => {
|
|||||||
|
|
||||||
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
|
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
|
||||||
expect(updateShortUrlMeta).toHaveBeenCalledTimes(1);
|
expect(updateShortUrlMeta).toHaveBeenCalledTimes(1);
|
||||||
expect(updateShortUrlMeta).toHaveBeenCalledWith(shortCode, meta);
|
expect(updateShortUrlMeta).toHaveBeenCalledWith(shortCode, undefined, meta);
|
||||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_META_START });
|
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_META_START });
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(2, { type: EDIT_SHORT_URL_META_ERROR });
|
expect(dispatch).toHaveBeenNthCalledWith(2, { type: EDIT_SHORT_URL_META_ERROR });
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import each from 'jest-each';
|
||||||
import reducer, {
|
import reducer, {
|
||||||
EDIT_SHORT_URL_TAGS_ERROR,
|
EDIT_SHORT_URL_TAGS_ERROR,
|
||||||
EDIT_SHORT_URL_TAGS_START,
|
EDIT_SHORT_URL_TAGS_START,
|
||||||
@@ -60,16 +61,16 @@ describe('shortUrlTagsReducer', () => {
|
|||||||
dispatch.mockReset();
|
dispatch.mockReset();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('dispatches normalized tags on success', async () => {
|
each([[ undefined ], [ null ], [ 'example.com' ]]).it('dispatches normalized tags on success', async (domain) => {
|
||||||
const normalizedTags = [ 'bar', 'foo' ];
|
const normalizedTags = [ 'bar', 'foo' ];
|
||||||
|
|
||||||
updateShortUrlTags.mockResolvedValue(normalizedTags);
|
updateShortUrlTags.mockResolvedValue(normalizedTags);
|
||||||
|
|
||||||
await editShortUrlTags(buildShlinkApiClient)(shortCode, tags)(dispatch);
|
await editShortUrlTags(buildShlinkApiClient)(shortCode, domain, tags)(dispatch);
|
||||||
|
|
||||||
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
|
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
|
||||||
expect(updateShortUrlTags).toHaveBeenCalledTimes(1);
|
expect(updateShortUrlTags).toHaveBeenCalledTimes(1);
|
||||||
expect(updateShortUrlTags).toHaveBeenCalledWith(shortCode, tags);
|
expect(updateShortUrlTags).toHaveBeenCalledWith(shortCode, domain, tags);
|
||||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_TAGS_START });
|
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_TAGS_START });
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_TAGS_EDITED, tags: normalizedTags, shortCode });
|
expect(dispatch).toHaveBeenNthCalledWith(2, { type: SHORT_URL_TAGS_EDITED, tags: normalizedTags, shortCode });
|
||||||
@@ -81,14 +82,14 @@ describe('shortUrlTagsReducer', () => {
|
|||||||
updateShortUrlTags.mockRejectedValue(error);
|
updateShortUrlTags.mockRejectedValue(error);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await editShortUrlTags(buildShlinkApiClient)(shortCode, tags)(dispatch);
|
await editShortUrlTags(buildShlinkApiClient)(shortCode, undefined, tags)(dispatch);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e).toBe(error);
|
expect(e).toBe(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
|
expect(buildShlinkApiClient).toHaveBeenCalledTimes(1);
|
||||||
expect(updateShortUrlTags).toHaveBeenCalledTimes(1);
|
expect(updateShortUrlTags).toHaveBeenCalledTimes(1);
|
||||||
expect(updateShortUrlTags).toHaveBeenCalledWith(shortCode, tags);
|
expect(updateShortUrlTags).toHaveBeenCalledWith(shortCode, undefined, tags);
|
||||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_TAGS_START });
|
expect(dispatch).toHaveBeenNthCalledWith(1, { type: EDIT_SHORT_URL_TAGS_START });
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(2, { type: EDIT_SHORT_URL_TAGS_ERROR });
|
expect(dispatch).toHaveBeenNthCalledWith(2, { type: EDIT_SHORT_URL_TAGS_ERROR });
|
||||||
|
|||||||
Reference in New Issue
Block a user