mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Refactored RelativeDateTime
Removed timeouts for the sake of simplicity
This commit is contained in:
parent
cc05ea11b5
commit
68f0dde62f
@ -1,15 +1,24 @@
|
|||||||
import { shallowMount } from '@vue/test-utils'
|
import { shallowMount, createLocalVue } from '@vue/test-utils'
|
||||||
import RelativeDateTime from './index.vue'
|
import RelativeDateTime from './index.vue'
|
||||||
|
|
||||||
|
import Filters from '../../plugins/vue-filters.js'
|
||||||
|
const localVue = createLocalVue()
|
||||||
|
localVue.use(Filters)
|
||||||
|
|
||||||
describe('RelativeDateTime', () => {
|
describe('RelativeDateTime', () => {
|
||||||
let wrapper
|
let wrapper
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallowMount(RelativeDateTime, {})
|
wrapper = shallowMount(RelativeDateTime, {
|
||||||
|
localVue,
|
||||||
|
propsData: {
|
||||||
|
dateTime: new Date()
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renders', () => {
|
it('renders', () => {
|
||||||
console.log(wrapper.html())
|
console.log(wrapper.html())
|
||||||
expect(wrapper.is('div')).toBe(true)
|
expect(wrapper.is('span')).toBe(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<span :title="absoluteTime">{{ relativeDateTime }}</span>
|
<span>{{ relativeDateTime }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -11,54 +11,9 @@ export default {
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
computed: {
|
||||||
return {
|
relativeDateTime() {
|
||||||
relativeDateTime: null,
|
return this.$filters.relativeDateTime(this.dateTime)
|
||||||
interval: 15000,
|
|
||||||
timeout: null,
|
|
||||||
absoluteTime: null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
locale() {
|
|
||||||
this.calcRelativeDateTime()
|
|
||||||
},
|
|
||||||
dateTime(dateTime) {
|
|
||||||
this.calcRelativeDateTime()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
this.calcRelativeDateTime()
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.calcRelativeDateTime()
|
|
||||||
},
|
|
||||||
destroyed() {
|
|
||||||
clearTimeout(this.timeout)
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
calcRelativeDateTime() {
|
|
||||||
// Reset Timer
|
|
||||||
clearTimeout(this.timeout)
|
|
||||||
|
|
||||||
// Calculate Relative Date
|
|
||||||
this.relativeDateTime = this.$filters.relativeDateTime(this.dateTime)
|
|
||||||
|
|
||||||
// TODO It is unclear what exactly this does and how to archive it
|
|
||||||
/*if (
|
|
||||||
this.relativeDateTime ===
|
|
||||||
t
|
|
||||||
.add(this.interval, 'milliseconds')
|
|
||||||
.utc()
|
|
||||||
.fromNow()
|
|
||||||
) {
|
|
||||||
this.interval += 15000
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Recalculate Timer
|
|
||||||
this.timeout = setTimeout(() => {
|
|
||||||
this.calcRelativeDateTime()
|
|
||||||
}, this.interval)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user