debian-mirror-gitlab/spec/frontend/collapsed_sidebar_todo_spec.js

173 lines
4.8 KiB
JavaScript
Raw Normal View History

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