2019-12-21 20:55:43 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2022-07-16 23:28:13 +05:30
|
|
|
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2022-04-04 11:22:00 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2017-09-10 17:25:29 +05:30
|
|
|
import '~/lib/utils/common_utils';
|
2019-12-21 20:55:43 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
|
2019-12-21 20:55:43 +05:30
|
|
|
import { addDelimiter } from '~/lib/utils/text_utility';
|
2021-03-11 19:13:27 +05:30
|
|
|
import Todos from '~/pages/dashboard/todos/index/todos';
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
jest.mock('~/lib/utils/url_utility', () => ({
|
|
|
|
visitUrl: jest.fn().mockName('visitUrl'),
|
|
|
|
}));
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
const TEST_COUNT_BIG = 2000;
|
|
|
|
const TEST_DONE_COUNT_BIG = 7300;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe('Todos', () => {
|
2019-12-21 20:55:43 +05:30
|
|
|
let mock;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-07-16 23:28:13 +05:30
|
|
|
loadHTMLFixture('todos/todos.html');
|
2019-12-21 20:55:43 +05:30
|
|
|
mock = new MockAdapter(axios);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
return new Todos();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
describe('on done todo click', () => {
|
|
|
|
let onToggleSpy;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
const el = document.querySelector('.js-done-todo');
|
|
|
|
const path = el.dataset.href;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
// Arrange
|
|
|
|
mock
|
|
|
|
.onDelete(path)
|
2023-04-23 21:23:45 +05:30
|
|
|
.replyOnce(HTTP_STATUS_OK, { count: TEST_COUNT_BIG, done_count: TEST_DONE_COUNT_BIG });
|
2023-03-04 22:38:38 +05:30
|
|
|
onToggleSpy = jest.fn();
|
|
|
|
document.addEventListener('todo:toggle', onToggleSpy);
|
2022-06-21 17:19:12 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
// Act
|
|
|
|
el.click();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
// Wait for axios and HTML to udpate
|
|
|
|
return waitForPromises();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it('dispatches todo:toggle', () => {
|
|
|
|
expect(onToggleSpy).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
detail: {
|
|
|
|
count: TEST_COUNT_BIG,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it('updates pending text', () => {
|
|
|
|
expect(document.querySelector('.js-todos-pending .js-todos-badge').innerHTML).toEqual(
|
|
|
|
addDelimiter(TEST_COUNT_BIG),
|
|
|
|
);
|
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it('updates done text', () => {
|
|
|
|
expect(document.querySelector('.js-todos-done .js-todos-badge').innerHTML).toEqual(
|
|
|
|
addDelimiter(TEST_DONE_COUNT_BIG),
|
|
|
|
);
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|