Skip to content
Merged
5 changes: 3 additions & 2 deletions src/components/dashboard/PageHeader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ function pageHeaders(): Usage[] {
}

describe('page header docs links', () => {
it('maps every page except the manual itself to a topic and section that exist', () => {
it('maps every page except the manual and legal documents to a topic and section that exist', () => {
const usages = pageHeaders()
expect(usages.length).toBeGreaterThan(20)

for (const usage of usages) {
if (basename(usage.file) === 'DocsView.vue') {
// The manual and the legal documents have no manual topic of their own.
if (['DocsView.vue', 'LegalView.vue'].includes(basename(usage.file))) {
expect(usage.docs).toBeUndefined()
continue
}
Expand Down
131 changes: 106 additions & 25 deletions src/components/data/CreateBucketDialog.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { defineComponent, h, ref } from 'vue'
import * as VueRuntime from 'vue'
import { describe, expect, it, vi } from 'vitest'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import * as BucketName from '@/lib/bucketName'
import * as BucketNaming from '@/lib/bucketNaming'
import * as DistributedMock from '@/lib/distributedMock'
import * as Utils from '@/lib/utils'
import { button, click, compileClientComponent, content, element, flush, moduleDefault, mountApp, nodes, typeValue } from '@/test/clientRender'
import { button, click, compileClientComponent, content, element, flush, moduleDefault, mountApp, nodes, typeValue, type HostNode } from '@/test/clientRender'

const Slotted = (tag: string) =>
defineComponent({ inheritAttrs: false, setup: (_, { attrs, slots }) => () => h(tag, attrs, slots.default?.()) })
Expand All @@ -19,17 +20,14 @@ const InputStub = defineComponent({
setup: (props, { attrs, emit }) => () =>
h('input', { ...attrs, invalid: props.invalid, value: props.modelValue, onInput: (event: { target: { value: string } }) => emit('update:modelValue', event.target.value) }),
})
const SelectStub = defineComponent({
props: { modelValue: String, options: { type: Array, default: () => [] } },
emits: ['update:modelValue'],
setup: (props, { attrs, emit }) => () =>
h('select', { ...attrs, value: props.modelValue, onChange: (value: string) => emit('update:modelValue', value) },
(props.options as { value: string; label: string }[]).map((option) => h('option', { value: option.value }, option.label))),
})
const StorageStub = defineComponent({ props: { open: Boolean }, setup: (props) => () => h('aside', { 'data-storage': props.open }) })
const ResultsStub = defineComponent({ props: { open: Boolean, name: String }, setup: (props) => () => h('aside', { 'data-results': props.open }, props.name) })

const s3 = { activateContext: vi.fn(), createBucket: vi.fn() }
// The group's routing and storages per node; a node missing here answers with no rule.
const routings = new Map<string, object>()
const getGroupRouting = vi.fn(async (_group: string, node: string) => routings.get(node) ?? { group_id: 'g1', warnings: [] })
const listGroupBackends = vi.fn(async () => ({ backends: [{ backend_id: 'b2', group_id: 'g1', kind: 's3', name: 'de.NBI-spire', public_config: {} }] }))
const free = new Map<string, number | null>([['https://one', 196 * 1024 ** 3], ['https://two', null]])
const nodeList = ref([
{ nodeId: 'two', kind: 'storage', reachable: true, isLocal: false, apiBase: 'https://two' },
Expand All @@ -43,7 +41,6 @@ const Dialog = compileClientComponent(new URL('./CreateBucketDialog.vue', import
'@lucide/vue': new Proxy({}, { get: () => defineComponent(() => () => null) }),
'@/components/ui/Button.vue': moduleDefault(ButtonStub),
'@/components/ui/Input.vue': moduleDefault(InputStub),
'@/components/ui/Select.vue': moduleDefault(SelectStub),
'@/components/ui/RefusalNote.vue': moduleDefault(defineComponent({ props: { message: String }, setup: (props) => () => h('p', { role: 'alert' }, props.message) })),
'@/components/ui/Spinner.vue': moduleDefault(Slotted('i')),
'@/components/ui/Dialog.vue': moduleDefault(Slotted('div')),
Expand All @@ -54,10 +51,13 @@ const Dialog = compileClientComponent(new URL('./CreateBucketDialog.vue', import
'@/components/ui/DialogClose.vue': moduleDefault(Slotted('span')),
'@/components/data/BucketCreateResults.vue': moduleDefault(ResultsStub),
'@/components/data/BucketStorageDialog.vue': moduleDefault(StorageStub),
'@/composables/useAruna': { useAruna: () => ({ apiBaseUrl: ref('https://one'), sessionEpoch: ref(1) }) },
'@/composables/useAruna': {
useAruna: () => ({ apiBaseUrl: ref('https://one'), sessionEpoch: ref(1), apiGroups: ref([{ group_id: 'g1', display_name: 'spire' }]), getGroupRouting, listGroupBackends }),
},
'@/composables/useRealmNodes': { useRealmNodes: () => ({ nodes: nodeList, displayName: (id: string) => `name-${id}`, isLocalNode: () => false }) },
'@/composables/useS3': { useS3: () => s3, s3ErrorMessage: (err: Error) => err.message },
'@/lib/bucketName': BucketName,
'@/lib/bucketNaming': BucketNaming,
'@/lib/bucketPlace': { readFreeSpace: async (base: string) => free.get(base) ?? null },
'@/lib/distributedMock': DistributedMock,
'@/lib/utils': Utils,
Expand All @@ -72,14 +72,19 @@ async function mount(nodeId: string | null = 'one') {
const name = () => element(mounted.root, (node) => node.tag === 'input' && node.props['aria-label'] === 'Bucket name')
const create = () => button(mounted.root, 'Create bucket')
const radios = () => nodes(mounted.root).filter((node) => node.tag === 'input' && node.props.type === 'radio')
const place = () => element(mounted.root, (node) => node.tag === 'select')
const pick = async (value: string) => {
;(place().props.onChange as (value: string) => void)(value)
// The node rows, each a label with its radio, in the order shown.
const rows = () => nodes(mounted.root).filter((node) => node.tag === 'label' && nodes(node).some((child) => child.props.name === 'bucket-node'))
const radioOf = (row: HostNode) => element(row, (node) => node.props.name === 'bucket-node')
const chosen = () => rows().find((row) => radioOf(row).props.checked)
const pick = async (label: string) => {
;(radioOf(rows().find((row) => content(row).includes(label))!).props.onChange as () => void)()
await flush()
}
return { root: mounted.root, created, open, name, create, radios, place, pick }
return { root: mounted.root, created, open, name, create, radios, rows, chosen, pick }
}

beforeEach(() => routings.clear())

describe('new bucket dialog', () => {
it('names the rule under the name and refuses a broken name', async () => {
const { root, name, create } = await mount()
Expand All @@ -91,10 +96,15 @@ describe('new bucket dialog', () => {
})

it('offers the reachable realm nodes, the open node first, with their free space, and a spread', async () => {
const { root, place, name } = await mount('one')
const labels = nodes(place()).filter((node) => node.tag === 'option').map((option) => content(option))
expect(labels).toEqual(['name-one, 196\u00a0GiB free', 'name-two', 'Spread over several nodes'])
expect(place().props.value).toBe('one')
const { root, rows, chosen, name } = await mount('one')
const labels = rows().map((row) => content(row))
expect(labels[0]).toContain('name-one')
expect(labels[0]).toContain('196\u00a0GiB free')
expect(labels[1]).toContain('name-two')
expect(labels[1]).not.toContain('free')
expect(labels[2]).toContain('Spread over several nodes')
expect(labels).toHaveLength(3)
expect(content(chosen()!)).toContain('name-one')
expect(content(root)).not.toContain('laptop')
// Stored data names the node that keeps it; a valid name shows its address.
expect(content(root)).toContain('Kept on name-one, counted against quotas.')
Expand All @@ -104,12 +114,12 @@ describe('new bucket dialog', () => {

it('chooses a storage node before the management node, even when the management node is open', async () => {
nodeList.value = [{ nodeId: 'mgmt', kind: 'management', reachable: true, isLocal: true, apiBase: 'https://mgmt' }, ...nodeList.value]
const { place } = await mount('mgmt')
const values = nodes(place()).filter((node) => node.tag === 'option').map((option) => option.props.value)
const { rows, chosen } = await mount('mgmt')
const names = rows().map((row) => content(row).match(/name-(two|one|mgmt)/)?.[0])
nodeList.value = nodeList.value.slice(1)

expect(values.slice(0, 3)).toEqual(['two', 'one', 'mgmt'])
expect(place().props.value).toBe('two')
expect(names.slice(0, 3)).toEqual(['name-two', 'name-one', 'name-mgmt'])
expect(content(chosen()!)).toContain('name-two')
})

it('needs a source address for a referenced bucket and hands it on after creating it', async () => {
Expand All @@ -132,7 +142,7 @@ describe('new bucket dialog', () => {
s3.createBucket.mockResolvedValueOnce(undefined)
const { name, create, pick, created, open } = await mount('one')
await typeValue(name(), 'assemblies-2026')
await pick('two')
await pick('name-two')
await click(create())

expect(s3.activateContext).toHaveBeenCalledWith('two', 'g1')
Expand All @@ -155,11 +165,82 @@ describe('new bucket dialog', () => {
s3.activateContext.mockClear()
const { root, name, create, pick } = await mount('one')
await typeValue(name(), 'big-data')
await pick('several')
await pick('Spread over several nodes')
expect(element(root, (node) => node.tag === 'aside' && 'data-storage' in node.props).props['data-storage']).toBe(true)

await click(create())
expect(element(root, (node) => node.tag === 'aside' && 'data-results' in node.props).props['data-results']).toBe(true)
expect(s3.activateContext).not.toHaveBeenCalled()
})

it('says what a new bucket gets on each node and starts on the node whose storage has the rule', async () => {
routings.set('two', { group_id: 'g1', default_target: { backend_id: 'b2' }, bucket_template: 'aruna-{group}-{bucket}', warnings: [] })
const { root, rows, chosen, name } = await mount('one')
expect(content(chosen()!)).toContain('name-two')
const [one, two] = rows()
expect(content(one)).toContain('Plain Aruna bucket, no storage rule on this node')
expect(content(two)).toContain('Own S3 bucket aruna-spire-{bucket}')
expect(content(two)).toContain('on de.NBI-spire')
await typeValue(name(), 'progenomes')
expect(content(rows()[1])).toContain('aruna-spire-progenomes')
expect(content(root)).toContain('Kept on name-two, counted against quotas.')
})

it('says nothing about a node whose rule cannot be read and keeps the open node', async () => {
getGroupRouting.mockRejectedValueOnce(new Error('forbidden')).mockRejectedValueOnce(new Error('forbidden'))
const { rows, chosen, name, create } = await mount('one')
expect(content(chosen()!)).toContain('name-one')
await typeValue(name(), 'progenomes')
expect(create().props.disabled).toBe(false)
for (const row of rows().slice(0, 2)) {
expect(content(row)).not.toContain('Plain Aruna bucket')
expect(content(row)).not.toContain('Own S3 bucket')
}
})

it('waits for the rule of every node before a bucket goes to the node it chose', async () => {
const replies: ((routing: object) => void)[] = []
const late = () => new Promise<object>((resolve) => replies.push(resolve))
getGroupRouting.mockImplementationOnce(late).mockImplementationOnce(late)
const { chosen, name, create } = await mount('one')
await typeValue(name(), 'progenomes')
expect(content(chosen()!)).toContain('name-one')
expect(create().props.disabled).toBe(true)

replies[0]({ group_id: 'g1', warnings: [] })
await flush()
expect(create().props.disabled).toBe(true)
replies[1]({ group_id: 'g1', default_target: { backend_id: 'b2' }, bucket_template: 'aruna-{bucket}', warnings: [] })
await flush()
expect(content(chosen()!)).toContain('name-two')
expect(create().props.disabled).toBe(false)
})

it('lets a node picked by hand take the bucket while the rules are still read', async () => {
getGroupRouting.mockImplementationOnce(() => new Promise(() => {})).mockImplementationOnce(() => new Promise(() => {}))
const { name, create, pick } = await mount('one')
await typeValue(name(), 'progenomes')
expect(create().props.disabled).toBe(true)
await pick('name-one')
expect(create().props.disabled).toBe(false)
})

it('chooses the node with the rule on the way back to stored data when its rule came meanwhile', async () => {
const replies: ((routing: object) => void)[] = []
const late = () => new Promise<object>((resolve) => replies.push(resolve))
getGroupRouting.mockImplementationOnce(late).mockImplementationOnce(late)
const { radios, chosen, name, create } = await mount('one')
await typeValue(name(), 'progenomes')
;(radios()[1].props.onChange as () => void)()
await flush()
replies[0]({ group_id: 'g1', warnings: [] })
replies[1]({ group_id: 'g1', default_target: { backend_id: 'b2' }, bucket_template: 'aruna-{bucket}', warnings: [] })
await flush()
expect(content(chosen()!)).toContain('name-one')

;(radios()[0].props.onChange as () => void)()
await flush()
expect(content(chosen()!)).toContain('name-two')
expect(create().props.disabled).toBe(false)
})
})
Loading
Loading