diff options
author | Constance Okoghenun <constanceokoghenun@gmail.com> | 2018-09-24 23:26:39 +0300 |
---|---|---|
committer | Constance Okoghenun <constanceokoghenun@gmail.com> | 2018-09-24 23:27:11 +0300 |
commit | 518ae5725325431e7b0890cab6f85c085b620ef7 (patch) | |
tree | 763ce42d7ac6afdcc34103bf36dad25dfbeddf99 | |
parent | b58191308eccb060a6e78e7c540dcfb9294ea9c3 (diff) |
Port of spec from https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/7078/
-rw-r--r-- | app/assets/javascripts/lib/utils/pretty_time.js | 8 | ||||
-rw-r--r-- | spec/features/boards/add_issues_modal_spec.rb | 2 | ||||
-rw-r--r-- | spec/javascripts/boards/components/issue_due_date_spec.js | 28 | ||||
-rw-r--r-- | spec/javascripts/boards/issue_card_spec.js | 10 | ||||
-rw-r--r-- | spec/javascripts/lib/utils/pretty_time_spec.js | 25 |
5 files changed, 52 insertions, 21 deletions
diff --git a/app/assets/javascripts/lib/utils/pretty_time.js b/app/assets/javascripts/lib/utils/pretty_time.js index b1ffd797f7e..94620ca606a 100644 --- a/app/assets/javascripts/lib/utils/pretty_time.js +++ b/app/assets/javascripts/lib/utils/pretty_time.js @@ -39,12 +39,16 @@ export function parseSeconds(seconds, { daysPerWeek = 5, hoursPerDay = 8 } = {}) /* * Accepts a timeObject (see parseSeconds) and returns a condensed string representation of it * (e.g. '1w 2d 3h 1m' or '1h 30m'). Zero value units are not included. +* If the 'full' paramter is passed it returns a non condensed string eg '1 week 3 days' */ -export function stringifyTime(timeObject) { +export function stringifyTime(timeObject, full = false) { const reducedTime = _.reduce(timeObject, (memo, unitValue, unitName) => { const isNonZero = !!unitValue; - return isNonZero ? `${memo} ${unitValue}${unitName.charAt(0)}` : memo; + let finalUnitValue = (isNonZero && unitValue > 1) ? unitName : unitName.replace(/s$/, ''); + finalUnitValue = full ? ` ${finalUnitValue}` : unitName.charAt(0); + + return isNonZero ? `${memo} ${unitValue}${finalUnitValue}` : memo; }, '').trim(); return reducedTime.length ? reducedTime : '0m'; } diff --git a/spec/features/boards/add_issues_modal_spec.rb b/spec/features/boards/add_issues_modal_spec.rb index eebc987499d..9ce55ace0fe 100644 --- a/spec/features/boards/add_issues_modal_spec.rb +++ b/spec/features/boards/add_issues_modal_spec.rb @@ -160,7 +160,7 @@ describe 'Issue Boards add issue modal', :js do it 'changes button text with plural' do page.within('.add-issues-modal') do - all('.board-card .board-card-number').each do |el| + all('.board-card .board-card-number-container').each do |el| el.click end diff --git a/spec/javascripts/boards/components/issue_due_date_spec.js b/spec/javascripts/boards/components/issue_due_date_spec.js index a43cf6a1df6..f340e70004f 100644 --- a/spec/javascripts/boards/components/issue_due_date_spec.js +++ b/spec/javascripts/boards/components/issue_due_date_spec.js @@ -38,6 +38,19 @@ describe('Issue Due Date component', () => { expect(vm.$el.textContent.trim()).toEqual('Yesterday'); }); + it('should render "Tomorrow" if the due date is one day from now', () => { + const date = new Date(); + date.setDate(date.getDate() + 1); + const yesterday = dateFormat(date, 'yyyy-mm-dd', true); + vm = new IssueDueDate({ + propsData: { + date: yesterday, + }, + }).$mount(); + + expect(vm.$el.textContent.trim()).toEqual('Tomorrow'); + }); + it('should render day of the week if due date is one week away', () => { const date = new Date(); date.setDate(date.getDate() + 5); @@ -74,19 +87,8 @@ describe('Issue Due Date component', () => { }, }).$mount(); - expect(vm.$el.classList.contains('text-danger')).toEqual(true); - }); - - it('should render month, day and year when due date is not current year', () => { - const date = new Date(); - date.setDate(date.getDate() + 365); - const dueDate = dateFormat(date, 'yyyy-mm-dd', true); - vm = new IssueDueDate({ - propsData: { - date: dueDate, - }, - }).$mount(); + const $timeContainer = vm.$el.querySelector('time'); - expect(vm.$el.textContent.trim()).toEqual(dateFormat(dueDate, 'mmm d, yyyy', true)); + expect($timeContainer.classList.contains('text-danger')).toEqual(true); }); }); diff --git a/spec/javascripts/boards/issue_card_spec.js b/spec/javascripts/boards/issue_card_spec.js index b6c61e7bad7..d6e61c5f4cd 100644 --- a/spec/javascripts/boards/issue_card_spec.js +++ b/spec/javascripts/boards/issue_card_spec.js @@ -122,7 +122,7 @@ describe('Issue card component', () => { component.$el .querySelector('.board-card-assignee img') .getAttribute('data-original-title'), - ).toContain(`Assigned to ${user.name}`); + ).toContain(`${user.name}`); }); it('sets users path', () => { @@ -155,7 +155,7 @@ describe('Issue card component', () => { it('displays defaults avatar if users avatar is null', () => { expect(component.$el.querySelector('.board-card-assignee img')).not.toBeNull(); expect(component.$el.querySelector('.board-card-assignee img').getAttribute('src')).toBe( - 'default_avatar?width=20', + 'default_avatar?width=24', ); }); }); @@ -189,7 +189,7 @@ describe('Issue card component', () => { }); it('renders all four assignees', () => { - expect(component.$el.querySelectorAll('.board-card-assignee .avatar').length).toEqual(4); + expect(component.$el.querySelectorAll('.board-card-assignee .avatar').length).toEqual(2); }); describe('more than four assignees', () => { @@ -209,11 +209,11 @@ describe('Issue card component', () => { it('renders more avatar counter', () => { expect( component.$el.querySelector('.board-card-assignee .avatar-counter').innerText, - ).toEqual('+2'); + ).toEqual('+3'); }); it('renders three assignees', () => { - expect(component.$el.querySelectorAll('.board-card-assignee .avatar').length).toEqual(3); + expect(component.$el.querySelectorAll('.board-card-assignee .avatar').length).toEqual(2); }); it('renders 99+ avatar counter', done => { diff --git a/spec/javascripts/lib/utils/pretty_time_spec.js b/spec/javascripts/lib/utils/pretty_time_spec.js new file mode 100644 index 00000000000..cf22dc3a6da --- /dev/null +++ b/spec/javascripts/lib/utils/pretty_time_spec.js @@ -0,0 +1,25 @@ +import * as prettyTime from '~/lib/utils/pretty_time'; + +describe('pretty_time', () => { + describe('stringifyTime', () => { + it('should return representation of weeks, hours, and minutes', () => { + const timeObject = { weeks: 1, days: 2, hours: 1, minutes: 2 }; + expect(prettyTime.stringifyTime(timeObject)).toEqual('1w 2d 1h 2m'); + }); + + it('should return condensed representation of time object', () => { + const timeObject = { weeks: 1, days: 0, hours: 1, minutes: 0 }; + expect(prettyTime.stringifyTime(timeObject)).toEqual('1w 1h'); + }); + + it('should return non-condensed representation of time object', () => { + const timeObject = { weeks: 1, days: 0, hours: 1, minutes: 0 }; + expect(prettyTime.stringifyTime(timeObject, true)).toEqual('1 week 1 hour'); + }); + + it('should return 0m if time object contains 0 values', () => { + const timeObject = { weeks: 0, days: 0, hours: 0, minutes: 0 }; + expect(prettyTime.stringifyTime(timeObject)).toEqual('0m'); + }); + }); +}); |