Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
6e680647
Commit
6e680647
authored
Oct 19, 2018
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add reusable component for counting down
parent
50222d4d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
0 deletions
+109
-0
app/assets/javascripts/vue_shared/components/gl_countdown.vue
...assets/javascripts/vue_shared/components/gl_countdown.vue
+46
-0
spec/javascripts/vue_shared/components/gl_countdown_spec.js
spec/javascripts/vue_shared/components/gl_countdown_spec.js
+63
-0
No files found.
app/assets/javascripts/vue_shared/components/gl_countdown.vue
0 → 100644
View file @
6e680647
<
script
>
import
{
calculateRemainingMilliseconds
,
formatTime
}
from
'
~/lib/utils/datetime_utility
'
;
/**
* Counts down to a given end date.
*/
export
default
{
props
:
{
endDate
:
{
type
:
String
,
required
:
true
,
},
},
data
()
{
return
{
remainingTime
:
formatTime
(
0
),
countdownUpdateIntervalId
:
null
,
};
},
mounted
()
{
const
updateRemainingTime
=
()
=>
{
const
remainingMilliseconds
=
calculateRemainingMilliseconds
(
this
.
endDate
);
this
.
remainingTime
=
formatTime
(
remainingMilliseconds
);
};
updateRemainingTime
();
this
.
countdownUpdateIntervalId
=
window
.
setInterval
(
updateRemainingTime
,
1000
);
},
beforeDestroy
()
{
window
.
clearInterval
(
this
.
countdownUpdateIntervalId
);
},
};
</
script
>
<
template
>
<time
v-gl-tooltip
:datetime=
"endDate"
:title=
"endDate"
>
{{
remainingTime
}}
</time>
</
template
>
spec/javascripts/vue_shared/components/gl_countdown_spec.js
0 → 100644
View file @
6e680647
import
mountComponent
from
'
spec/helpers/vue_mount_component_helper
'
;
import
Vue
from
'
vue
'
;
import
GlCountdown
from
'
~/vue_shared/components/gl_countdown.vue
'
;
describe
(
'
GlCountdown
'
,
()
=>
{
const
Component
=
Vue
.
extend
(
GlCountdown
);
let
vm
;
let
now
=
'
2000-01-01T00:00:00Z
'
;
beforeEach
(()
=>
{
spyOn
(
Date
,
'
now
'
).
and
.
callFake
(()
=>
new
Date
(
now
).
getTime
());
jasmine
.
clock
().
install
();
});
afterEach
(()
=>
{
vm
.
$destroy
();
jasmine
.
clock
().
uninstall
();
});
describe
(
'
when there is time remaining
'
,
()
=>
{
beforeEach
(
done
=>
{
vm
=
mountComponent
(
Component
,
{
endDate
:
'
2000-01-01T01:02:03Z
'
,
});
Vue
.
nextTick
()
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
displays remaining time
'
,
()
=>
{
expect
(
vm
.
$el
).
toContainText
(
'
01:02:03
'
);
});
it
(
'
updates remaining time
'
,
done
=>
{
now
=
'
2000-01-01T00:00:01Z
'
;
jasmine
.
clock
().
tick
(
1000
);
Vue
.
nextTick
()
.
then
(()
=>
{
expect
(
vm
.
$el
).
toContainText
(
'
01:02:02
'
);
done
();
})
.
catch
(
done
.
fail
);
});
});
describe
(
'
when there is no time remaining
'
,
()
=>
{
beforeEach
(
done
=>
{
vm
=
mountComponent
(
Component
,
{
endDate
:
'
1900-01-01T00:00:00Z
'
,
});
Vue
.
nextTick
()
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
displays 00:00:00
'
,
()
=>
{
expect
(
vm
.
$el
).
toContainText
(
'
00:00:00
'
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment