Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions apps/files_trashbin/src/files_views/columns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { deleted, deletedBy, originalLocation } from './columns.ts'
import { trashbinView } from './trashbinView.ts'
import * as ncAuth from '@nextcloud/auth'

vi.mock('@nextcloud/l10n', async (originalModule) => ({
...(await originalModule()),
getLanguage: () => 'en',
getCanonicalLocale: () => 'en-US',
}))

describe('files_trashbin: file list columns', () => {

describe('column: original location', () => {
Expand Down Expand Up @@ -100,19 +106,19 @@ describe('files_trashbin: file list columns', () => {
})

it('renders a node with deletion date', () => {
const node = new File({ owner: 'test', source: 'https://example.com/remote.php/dav/files/test/a.txt', mime: 'text/plain', attributes: { 'trashbin-deletion-time': 1741684522 } })
const node = new File({ owner: 'test', source: 'https://example.com/remote.php/dav/files/test/a.txt', mime: 'text/plain', attributes: { 'trashbin-deletion-time': (Date.now() / 1000) - 120 } })
const el: HTMLElement = deleted.render(node, trashbinView)
expect(el).toBeInstanceOf(HTMLElement)
expect(el.textContent).toBe('a minute ago')
expect(el.title).toBe('March 11, 2025 9:15 AM')
expect(el.textContent).toBe('2 minutes ago')
expect(el.title).toBe('March 11, 2025 at 9:14 AM')
})

it('renders a node when deletion date is missing and falls back to mtime', () => {
const node = new File({ owner: 'test', source: 'https://example.com/remote.php/dav/files/test/a.txt', mime: 'text/plain', mtime: new Date(1741684522000) })
const node = new File({ owner: 'test', source: 'https://example.com/remote.php/dav/files/test/a.txt', mime: 'text/plain', mtime: new Date(Date.now() - 60000) })
const el: HTMLElement = deleted.render(node, trashbinView)
expect(el).toBeInstanceOf(HTMLElement)
expect(el.textContent).toBe('a minute ago')
expect(el.title).toBe('March 11, 2025 9:15 AM')
expect(el.textContent).toBe('1 minute ago')
expect(el.title).toBe('March 11, 2025 at 9:15 AM')
})

it('renders a node when deletion date is missing', () => {
Expand Down
10 changes: 6 additions & 4 deletions apps/files_trashbin/src/files_views/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import moment from '@nextcloud/moment'
import { getCurrentUser } from '@nextcloud/auth'
import { Column, Node } from '@nextcloud/files'
import { getCanonicalLocale, getLanguage, translate as t } from '@nextcloud/l10n'
import { formatRelativeTime, getCanonicalLocale, getLanguage, t } from '@nextcloud/l10n'
import { dirname } from '@nextcloud/paths'

import Vue from 'vue'
Expand Down Expand Up @@ -67,8 +66,11 @@ export const deleted = new Column({
const deletionTime = node.attributes?.['trashbin-deletion-time'] || ((node?.mtime?.getTime() ?? 0) / 1000)
const span = document.createElement('span')
if (deletionTime) {
span.title = moment.unix(deletionTime).format('LLL')
span.textContent = moment.unix(deletionTime).fromNow()
const formatter = Intl.DateTimeFormat([getCanonicalLocale()], { dateStyle: 'long', timeStyle: 'short' })
const timestamp = new Date(deletionTime * 1000)

span.title = formatter.format(timestamp)
span.textContent = formatRelativeTime(timestamp, { ignoreSeconds: t('files', 'few seconds ago') })
return span
}

Expand Down
Loading