Added automatic refresh on mercure events

This commit is contained in:
Alejandro Celaya
2020-04-18 10:50:01 +02:00
parent 0f73cb9f8c
commit a22a1938c1
16 changed files with 132 additions and 54 deletions

View File

@@ -20,7 +20,9 @@ describe('<ShortUrlVisitsCount />', () => {
const maxVisitsHelper = wrapper.find('.short-urls-visits-count__max-visits-control');
const maxVisitsTooltip = wrapper.find(UncontrolledTooltip);
expect(wrapper.html()).toEqual(`<span><strong>${visitsCount}</strong></span>`);
expect(wrapper.html()).toEqual(
`<span><strong class="short-url-visits-count__amount">${visitsCount}</strong></span>`
);
expect(maxVisitsHelper).toHaveLength(0);
expect(maxVisitsTooltip).toHaveLength(0);
});

View File

@@ -26,7 +26,9 @@ describe('<VisitsHeader />', () => {
it('shows the amount of visits', () => {
const visitsBadge = wrapper.find('.badge');
expect(visitsBadge.html()).toContain(`Visits: <span><strong>${shortUrlVisits.visits.length}</strong></span>`);
expect(visitsBadge.html()).toContain(
`Visits: <span><strong class="short-url-visits-count__amount">${shortUrlVisits.visits.length}</strong></span>`
);
});
it('shows when the URL was created', () => {

View File

@@ -72,8 +72,13 @@ describe('shortUrlVisitsReducer', () => {
expect(ShlinkApiClient.getShortUrlVisits).toHaveBeenCalledTimes(1);
});
it('dispatches start and success when promise is resolved', async () => {
it.each([
[ undefined, undefined ],
[{}, undefined ],
[{ domain: 'foobar.com' }, 'foobar.com' ],
])('dispatches start and success when promise is resolved', async (query, domain) => {
const visits = [{}, {}];
const shortCode = 'abc123';
const ShlinkApiClient = buildApiClientMock(Promise.resolve({
data: visits,
pagination: {
@@ -82,11 +87,11 @@ describe('shortUrlVisitsReducer', () => {
},
}));
await getShortUrlVisits(() => ShlinkApiClient)('abc123')(dispatchMock, getState);
await getShortUrlVisits(() => ShlinkApiClient)(shortCode, query)(dispatchMock, getState);
expect(dispatchMock).toHaveBeenCalledTimes(2);
expect(dispatchMock).toHaveBeenNthCalledWith(1, { type: GET_SHORT_URL_VISITS_START });
expect(dispatchMock).toHaveBeenNthCalledWith(2, { type: GET_SHORT_URL_VISITS, visits });
expect(dispatchMock).toHaveBeenNthCalledWith(2, { type: GET_SHORT_URL_VISITS, visits, shortCode, domain });
expect(ShlinkApiClient.getShortUrlVisits).toHaveBeenCalledTimes(1);
});