2017-03-27 11:02:20 -04:00
|
|
|
/* eslint-disable no-new */
|
2020-03-11 17:09:19 -04:00
|
|
|
import { clone } from 'lodash';
|
2018-02-02 07:36:51 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2020-08-17 17:09:56 -04:00
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
2021-01-14 19:10:45 -05:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2018-02-02 07:36:51 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-12-15 07:57:08 -05:00
|
|
|
import Sidebar from '~/right_sidebar';
|
2017-03-27 11:02:20 -04:00
|
|
|
|
|
|
|
describe('Issuable right sidebar collapsed todo toggle', () => {
|
2019-03-26 12:03:28 -04:00
|
|
|
const fixtureName = 'issues/open-issue.html';
|
2017-03-27 11:02:20 -04:00
|
|
|
const jsonFixtureName = 'todos/todos.json';
|
2018-02-02 07:36:51 -05:00
|
|
|
let mock;
|
2017-03-27 11:02:20 -04:00
|
|
|
|
|
|
|
preloadFixtures(fixtureName);
|
|
|
|
preloadFixtures(jsonFixtureName);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const todoData = getJSONFixture(jsonFixtureName);
|
|
|
|
new Sidebar();
|
|
|
|
loadFixtures(fixtureName);
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
document.querySelector('.js-right-sidebar').classList.toggle('right-sidebar-expanded');
|
|
|
|
document.querySelector('.js-right-sidebar').classList.toggle('right-sidebar-collapsed');
|
2017-03-27 11:02:20 -04:00
|
|
|
|
2018-02-02 07:36:51 -05:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
mock.onPost(`${TEST_HOST}/frontend-fixtures/issues-project/todos`).reply(() => {
|
2020-03-11 17:09:19 -04:00
|
|
|
const response = clone(todoData);
|
2017-03-27 11:02:20 -04:00
|
|
|
|
2018-02-02 07:36:51 -05:00
|
|
|
return [200, response];
|
|
|
|
});
|
2017-03-27 11:02:20 -04:00
|
|
|
|
2018-02-02 07:36:51 -05:00
|
|
|
mock.onDelete(/(.*)\/dashboard\/todos\/\d+$/).reply(() => {
|
2020-03-11 17:09:19 -04:00
|
|
|
const response = clone(todoData);
|
2018-02-02 07:36:51 -05:00
|
|
|
delete response.delete_path;
|
|
|
|
|
|
|
|
return [200, response];
|
2017-03-27 11:02:20 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-02-02 07:36:51 -05:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2017-03-27 11:02:20 -04:00
|
|
|
it('shows add todo button', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(document.querySelector('.js-issuable-todo.sidebar-collapsed-icon')).not.toBeNull();
|
2017-03-27 11:02:20 -04:00
|
|
|
|
|
|
|
expect(
|
2018-10-23 07:50:41 -04:00
|
|
|
document
|
2020-08-20 17:10:18 -04:00
|
|
|
.querySelector('.js-issuable-todo.sidebar-collapsed-icon svg')
|
|
|
|
.getAttribute('data-testid'),
|
|
|
|
).toBe('todo-add-icon');
|
2017-03-27 11:02:20 -04:00
|
|
|
|
|
|
|
expect(
|
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .todo-undone'),
|
|
|
|
).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets default tooltip title', () => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').getAttribute('title'),
|
2020-10-08 05:08:40 -04:00
|
|
|
).toBe('Add a to do');
|
2017-03-27 11:02:20 -04:00
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('toggle todo state', (done) => {
|
2017-03-27 11:02:20 -04:00
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();
|
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
setImmediate(() => {
|
2018-02-02 07:36:51 -05:00
|
|
|
expect(
|
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .todo-undone'),
|
|
|
|
).not.toBeNull();
|
2017-03-27 11:02:20 -04:00
|
|
|
|
2018-02-02 07:36:51 -05:00
|
|
|
expect(
|
2018-10-23 07:50:41 -04:00
|
|
|
document
|
2020-08-20 17:10:18 -04:00
|
|
|
.querySelector('.js-issuable-todo.sidebar-collapsed-icon svg.todo-undone')
|
|
|
|
.getAttribute('data-testid'),
|
|
|
|
).toBe('todo-done-icon');
|
2017-03-27 11:02:20 -04:00
|
|
|
|
2018-02-02 07:36:51 -05:00
|
|
|
done();
|
|
|
|
});
|
2017-03-27 11:02:20 -04:00
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('toggle todo state of expanded todo toggle', (done) => {
|
2017-03-27 11:02:20 -04:00
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();
|
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
setImmediate(() => {
|
2018-02-02 07:36:51 -05:00
|
|
|
expect(
|
|
|
|
document.querySelector('.issuable-sidebar-header .js-issuable-todo').textContent.trim(),
|
2019-07-04 11:45:54 -04:00
|
|
|
).toBe('Mark as done');
|
2017-03-27 11:02:20 -04:00
|
|
|
|
2018-02-02 07:36:51 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-03-27 11:02:20 -04:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('toggles todo button tooltip', (done) => {
|
2017-03-27 11:02:20 -04:00
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();
|
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
setImmediate(() => {
|
2018-02-02 07:36:51 -05:00
|
|
|
expect(
|
2018-10-17 03:13:26 -04:00
|
|
|
document
|
|
|
|
.querySelector('.js-issuable-todo.sidebar-collapsed-icon')
|
|
|
|
.getAttribute('data-original-title'),
|
2019-07-04 11:45:54 -04:00
|
|
|
).toBe('Mark as done');
|
2017-03-27 11:02:20 -04:00
|
|
|
|
2018-02-02 07:36:51 -05:00
|
|
|
done();
|
|
|
|
});
|
2017-03-27 11:02:20 -04:00
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('marks todo as done', (done) => {
|
2017-03-27 11:02:20 -04:00
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();
|
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
waitForPromises()
|
2018-02-02 07:36:51 -05:00
|
|
|
.then(() => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .todo-undone'),
|
|
|
|
).not.toBeNull();
|
|
|
|
|
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();
|
|
|
|
})
|
2020-06-08 05:08:23 -04:00
|
|
|
.then(waitForPromises)
|
2018-02-02 07:36:51 -05:00
|
|
|
.then(() => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .todo-undone'),
|
|
|
|
).toBeNull();
|
|
|
|
|
|
|
|
expect(
|
|
|
|
document.querySelector('.issuable-sidebar-header .js-issuable-todo').textContent.trim(),
|
2020-10-08 05:08:40 -04:00
|
|
|
).toBe('Add a to do');
|
2018-02-02 07:36:51 -05:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-03-27 11:02:20 -04:00
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('updates aria-label to Mark as done', (done) => {
|
2017-03-27 11:02:20 -04:00
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();
|
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
setImmediate(() => {
|
2018-02-02 07:36:51 -05:00
|
|
|
expect(
|
2018-10-17 03:13:26 -04:00
|
|
|
document
|
|
|
|
.querySelector('.js-issuable-todo.sidebar-collapsed-icon')
|
|
|
|
.getAttribute('aria-label'),
|
2019-07-04 11:45:54 -04:00
|
|
|
).toBe('Mark as done');
|
2017-03-27 11:02:20 -04:00
|
|
|
|
2018-02-02 07:36:51 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it('updates aria-label to add todo', (done) => {
|
2017-03-27 11:02:20 -04:00
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();
|
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
waitForPromises()
|
2018-02-02 07:36:51 -05:00
|
|
|
.then(() => {
|
|
|
|
expect(
|
2018-10-17 03:13:26 -04:00
|
|
|
document
|
|
|
|
.querySelector('.js-issuable-todo.sidebar-collapsed-icon')
|
|
|
|
.getAttribute('aria-label'),
|
2019-07-04 11:45:54 -04:00
|
|
|
).toBe('Mark as done');
|
2018-02-02 07:36:51 -05:00
|
|
|
|
|
|
|
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();
|
|
|
|
})
|
2020-06-08 05:08:23 -04:00
|
|
|
.then(waitForPromises)
|
2018-02-02 07:36:51 -05:00
|
|
|
.then(() => {
|
|
|
|
expect(
|
2018-10-17 03:13:26 -04:00
|
|
|
document
|
|
|
|
.querySelector('.js-issuable-todo.sidebar-collapsed-icon')
|
|
|
|
.getAttribute('aria-label'),
|
2020-10-08 05:08:40 -04:00
|
|
|
).toBe('Add a to do');
|
2018-02-02 07:36:51 -05:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-03-27 11:02:20 -04:00
|
|
|
});
|
|
|
|
});
|