summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstance Okoghenun <constanceokoghenun@gmail.com>2018-11-07 13:12:00 +0100
committerConstance Okoghenun <constanceokoghenun@gmail.com>2018-11-07 13:12:00 +0100
commitf1d80cd0dee5a327fd75e4a407dc5ce4c6b827a4 (patch)
treeeabe229ad5391ca5b3513c6101daa7dcb59f021e
parentc8472e112fb3a7eccc6c15fc34de24af75a9a8c7 (diff)
downloadgitlab-ce-f1d80cd0dee5a327fd75e4a407dc5ce4c6b827a4.tar.gz
Refactored spec for issue due date component
-rw-r--r--spec/javascripts/boards/components/issue_due_date_spec.js77
1 files changed, 23 insertions, 54 deletions
diff --git a/spec/javascripts/boards/components/issue_due_date_spec.js b/spec/javascripts/boards/components/issue_due_date_spec.js
index aa2f585fabc..9e49330c052 100644
--- a/spec/javascripts/boards/components/issue_due_date_spec.js
+++ b/spec/javascripts/boards/components/issue_due_date_spec.js
@@ -5,12 +5,14 @@ import mountComponent from '../../helpers/vue_mount_component_helper';
describe('Issue Due Date component', () => {
let vm;
+ let date;
+ const Component = Vue.extend(IssueDueDate);
+ const createComponent = (dueDate = new Date()) =>
+ mountComponent(Component, { date: dateFormat(dueDate, 'yyyy-mm-dd', true) });
beforeEach(() => {
- const Component = Vue.extend(IssueDueDate);
- vm = mountComponent(Component, {
- date: dateFormat(new Date(), 'yyyy-mm-dd', true),
- });
+ date = new Date();
+ vm = createComponent();
});
afterEach(() => {
@@ -23,73 +25,40 @@ describe('Issue Due Date component', () => {
expect(timeContainer.textContent.trim()).toEqual('Today');
});
- it('should render "Yesterday" if the due date is yesterday', done => {
- const date = new Date();
+ it('should render "Yesterday" if the due date is yesterday', () => {
date.setDate(date.getDate() - 1);
- const yesterday = dateFormat(date, 'yyyy-mm-dd', true);
- vm.date = yesterday;
+ vm = createComponent(date);
- vm.$nextTick(() => {
- const timeContainer = vm.$el.querySelector('time');
-
- expect(timeContainer.textContent.trim()).toEqual('Yesterday');
- done();
- });
+ expect(vm.$el.querySelector('time').textContent.trim()).toEqual('Yesterday');
});
- it('should render "Tomorrow" if the due date is one day from now', done => {
- const date = new Date();
+ it('should render "Tomorrow" if the due date is one day from now', () => {
date.setDate(date.getDate() + 1);
- const tomorrow = dateFormat(date, 'yyyy-mm-dd', true);
- vm.date = tomorrow;
-
- vm.$nextTick(() => {
- const timeContainer = vm.$el.querySelector('time');
+ vm = createComponent(date);
- expect(timeContainer.textContent.trim()).toEqual('Tomorrow');
- done();
- });
+ expect(vm.$el.querySelector('time').textContent.trim()).toEqual('Tomorrow');
});
- it('should render day of the week if due date is one week away', done => {
- const date = new Date();
+ it('should render day of the week if due date is one week away', () => {
date.setDate(date.getDate() + 5);
- const dueDate = dateFormat(date, 'yyyy-mm-dd', true);
- vm.date = dueDate;
-
- vm.$nextTick(() => {
- const timeContainer = vm.$el.querySelector('time');
+ vm = createComponent(date);
- expect(timeContainer.textContent.trim()).toEqual(dateFormat(dueDate, 'dddd', true));
- done();
- });
+ expect(vm.$el.querySelector('time').textContent.trim()).toEqual(dateFormat(date, 'dddd', true));
});
- it('should render month and day for other dates', done => {
- const date = new Date();
+ it('should render month and day for other dates', () => {
date.setDate(date.getDate() + 17);
- const dueDate = dateFormat(date, 'yyyy-mm-dd', true);
- vm.date = dueDate;
+ vm = createComponent(date);
- vm.$nextTick(() => {
- const timeContainer = vm.$el.querySelector('time');
-
- expect(timeContainer.textContent.trim()).toEqual(dateFormat(dueDate, 'mmm d', true));
- done();
- });
+ expect(vm.$el.querySelector('time').textContent.trim()).toEqual(
+ dateFormat(date, 'mmm d', true),
+ );
});
- it('should contain the correct `.text-danger` css class for overdue issue', done => {
- const date = new Date();
+ it('should contain the correct `.text-danger` css class for overdue issue', () => {
date.setDate(date.getDate() - 17);
- const dueDate = dateFormat(date, 'yyyy-mm-dd', true);
- vm.date = dueDate;
-
- vm.$nextTick(() => {
- const timeContainer = vm.$el.querySelector('time');
+ vm = createComponent(date);
- expect(timeContainer.classList.contains('text-danger')).toEqual(true);
- done();
- });
+ expect(vm.$el.querySelector('time').classList.contains('text-danger')).toEqual(true);
});
});