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

172 lines
4.8 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* eslint-disable no-new */
import _ from 'underscore';
2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import Sidebar from '~/right_sidebar';
import timeoutPromise from './helpers/set_timeout_promise_helper';
2017-08-17 22:00:37 +05:30
describe('Issuable right sidebar collapsed todo toggle', () => {
2019-05-18 00:54:41 +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);
mock.onPost(`${gl.TEST_HOST}/frontend-fixtures/issues-project/todos`).reply(() => {
2017-08-17 22:00:37 +05:30
const response = _.clone(todoData);
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(() => {
const response = _.clone(todoData);
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
.querySelector('.js-issuable-todo.sidebar-collapsed-icon svg use')
.getAttribute('xlink:href'),
).toContain('todo-add');
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'),
).toBe('Add todo');
});
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();
2018-03-17 18:26:18 +05:30
setTimeout(() => {
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
.querySelector('.js-issuable-todo.sidebar-collapsed-icon svg.todo-undone use')
.getAttribute('xlink:href'),
).toContain('todo-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('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();
2018-03-17 18:26:18 +05:30
setTimeout(() => {
expect(
document.querySelector('.issuable-sidebar-header .js-issuable-todo').textContent.trim(),
2018-10-15 14:42:47 +05:30
).toBe('Mark todo 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();
2018-03-17 18:26:18 +05:30
setTimeout(() => {
expect(
2018-12-13 13:39:08 +05:30
document
.querySelector('.js-issuable-todo.sidebar-collapsed-icon')
.getAttribute('data-original-title'),
2018-10-15 14:42:47 +05:30
).toBe('Mark todo 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();
2018-03-17 18:26:18 +05:30
timeoutPromise()
.then(() => {
expect(
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .todo-undone'),
).not.toBeNull();
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();
})
.then(timeoutPromise)
.then(() => {
expect(
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .todo-undone'),
).toBeNull();
expect(
document.querySelector('.issuable-sidebar-header .js-issuable-todo').textContent.trim(),
).toBe('Add todo');
})
.then(done)
.catch(done.fail);
2017-08-17 22:00:37 +05:30
});
2018-12-13 13:39:08 +05:30
it('updates aria-label to mark todo as done', done => {
2017-08-17 22:00:37 +05:30
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();
2018-03-17 18:26:18 +05:30
setTimeout(() => {
expect(
2018-12-13 13:39:08 +05:30
document
.querySelector('.js-issuable-todo.sidebar-collapsed-icon')
.getAttribute('aria-label'),
2018-10-15 14:42:47 +05:30
).toBe('Mark todo 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();
2018-03-17 18:26:18 +05:30
timeoutPromise()
.then(() => {
expect(
2018-12-13 13:39:08 +05:30
document
.querySelector('.js-issuable-todo.sidebar-collapsed-icon')
.getAttribute('aria-label'),
2018-10-15 14:42:47 +05:30
).toBe('Mark todo as done');
2018-03-17 18:26:18 +05:30
document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();
})
.then(timeoutPromise)
.then(() => {
expect(
2018-12-13 13:39:08 +05:30
document
.querySelector('.js-issuable-todo.sidebar-collapsed-icon')
.getAttribute('aria-label'),
2018-03-17 18:26:18 +05:30
).toBe('Add todo');
})
.then(done)
.catch(done.fail);
2017-08-17 22:00:37 +05:30
});
});