Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion src/test-utils/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface MakeNodeOptions {
favorite?: boolean
mtime?: Date
basename?: string
/** Folder the file sits in, relative to the owner's root; '/' for the root. */
dirname?: string
/** Outgoing share-type numbers; stored in the nested shape DAV returns. */
shareTypes?: number[]
}
Expand All @@ -33,12 +35,14 @@ export function makeNode({
favorite = false,
mtime = new Date('2024-01-01T00:00:00Z'),
basename = `file-${id}.odt`,
dirname = '/',
shareTypes,
}: MakeNodeOptions = {}): Node {
const ownerSegment = owner ?? 'nobody'
const folder = dirname === '/' ? '' : dirname
return new File({
id,
source: `https://cloud.example.com/remote.php/dav/files/${ownerSegment}/${basename}`,
source: `https://cloud.example.com/remote.php/dav/files/${ownerSegment}${folder}/${basename}`,
root: `/files/${ownerSegment}`,
owner,
mime,
Expand Down
27 changes: 27 additions & 0 deletions src/views/OfficeOverview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,33 @@ describe('OfficeOverview > rendering states', () => {
expect(wrapper.findComponent({ name: 'NcListItem' }).props('name')).toBe('report.odt')
expect(wrapper.findComponent({ name: 'FileCard' }).exists()).toBe(false)
})

it('shows the folder of each file in grid view, "/" for the root', async () => {
getTemplatesMock.mockResolvedValue([makeCreator()])
getAllOfficeFilesMock.mockResolvedValue(officeFilesResult([
makeNode({ owner: 'alice', basename: 'report.odt', dirname: '/Projects/2024' }),
makeNode({ owner: 'alice', basename: 'report.odt' }),
]))

const wrapper = await mountOverview({ FileCard: stubRenderingAllSlots('FileCard') })

const subnames = wrapper.findAllComponents({ name: 'FileCard' }).map(card => card.text())
expect(subnames[0]).toContain('/Projects/2024')
expect(subnames[1]).toContain('/')
expect(subnames[1]).not.toContain('/Projects')
})

it('shows the folder of each file in list view', async () => {
localStorage.setItem('office.overview.gridView', 'false')
getTemplatesMock.mockResolvedValue([makeCreator()])
getAllOfficeFilesMock.mockResolvedValue(officeFilesResult([
makeNode({ owner: 'alice', basename: 'report.odt', dirname: '/Projects/2024' }),
]))

const wrapper = await mountOverview({ NcListItem: stubRenderingAllSlots('NcListItem', ['name']) })

expect(wrapper.findComponent({ name: 'NcListItem' }).text()).toContain('/Projects/2024')
})
})

describe('OfficeOverview > creator on the URL', () => {
Expand Down
10 changes: 8 additions & 2 deletions src/views/OfficeOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ type ViewMode = 'list' | 'grid'

const currentUid = getCurrentUser()?.uid ?? null

/** Folder the file lives in, shown next to the date so same-named files can be told apart. */
function folderLabel(file: Node): string {
const dir = (file.dirname ?? '/').replace(/\/+$/, '')
return dir === '' ? '/' : dir
}

const route = useRoute()
const router = useRouter()

Expand Down Expand Up @@ -401,7 +407,7 @@ fetchAll()
</template>

<template #subname>
<NcDateTime :timestamp="file.mtime" />
<NcDateTime :timestamp="file.mtime" /> · {{ folderLabel(file) }}
</template>
</FileCard>
</div>
Expand Down Expand Up @@ -429,7 +435,7 @@ fetchAll()
</span>
</template>
<template #subname>
<NcDateTime :timestamp="file.mtime" />
<NcDateTime :timestamp="file.mtime" /> · {{ folderLabel(file) }}
</template>
</NcListItem>
</div>
Expand Down