Skip to content

Commit

Permalink
Check for NXentry or NXroot specifically when looking for NX groups
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Nov 3, 2021
1 parent fb68c3f commit a9ed6c3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
12 changes: 6 additions & 6 deletions cypress/specs/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ describe('App', () => {
});

it('visualize dataset with "spectrum" interpretation as NxSpectrum', () => {
cy.findByRole('treeitem', { name: /^nexus_entry/ }).click();
cy.findByRole('treeitem', { name: /^nexus_entry / }).click();
cy.findByRole('treeitem', { name: 'spectrum (NeXus group)' }).click();

cy.findByRole('heading', { name: 'nexus_entry / spectrum' }).should(
Expand All @@ -266,7 +266,7 @@ describe('App', () => {
});

it('visualize dataset with "image" interpretation as NxImage', () => {
cy.findByRole('treeitem', { name: /^nexus_entry/ }).click();
cy.findByRole('treeitem', { name: /^nexus_entry / }).click();
cy.findByRole('treeitem', { name: 'image (NeXus group)' }).click();

cy.findByRole('heading', { name: 'nexus_entry / image' }).should('exist');
Expand All @@ -284,7 +284,7 @@ describe('App', () => {
});

it('use axis values to compute axis ticks', () => {
cy.findByRole('treeitem', { name: /^nexus_entry/ }).click();
cy.findByRole('treeitem', { name: /^nexus_entry / }).click();
cy.findByRole('treeitem', { name: 'image (NeXus group)' }).click();

cy.get('svg[data-type="abscissa"] .visx-axis-tick').should(
Expand All @@ -294,7 +294,7 @@ describe('App', () => {
});

it('visualize dataset with log scales on both axes on NxSpectrum with SILX_style', () => {
cy.findByRole('treeitem', { name: /^nexus_entry/ }).click();
cy.findByRole('treeitem', { name: /^nexus_entry / }).click();
cy.findByRole('treeitem', { name: /log_spectrum/ }).click();

cy.findByRole('heading', { name: 'nexus_entry / log_spectrum' }).should(
Expand All @@ -310,7 +310,7 @@ describe('App', () => {
});

it('visualize signal and auxiliary signals datasets as NxSpectrum', () => {
cy.findByRole('treeitem', { name: /^nexus_entry/ }).click();
cy.findByRole('treeitem', { name: /^nexus_entry / }).click();
cy.findByRole('treeitem', { name: /spectrum_with_aux/ }).click();

cy.findByRole('heading', {
Expand All @@ -324,7 +324,7 @@ describe('App', () => {
});

it('visualize dataset with "rgb-image" interpretation as NxRGB', () => {
cy.findByRole('treeitem', { name: /^nexus_entry/ }).click();
cy.findByRole('treeitem', { name: /^nexus_entry / }).click();
cy.findByRole('treeitem', { name: /rgb-image/ }).click();

cy.findByRole('heading', { name: 'nexus_entry / rgb-image' }).should(
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/__tests__/MetadataViewer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ test('follow path attributes', async () => {
);

const nxEntry = await screen.findByRole('treeitem', {
name: /^nexus_entry/,
name: /^nexus_entry /,
});
expect(nxEntry).toHaveAttribute('aria-selected', 'true');
expect(nxEntry).toHaveAttribute('aria-expanded', 'true');
Expand Down
9 changes: 9 additions & 0 deletions packages/app/src/__tests__/NexusPack.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ test('visualize NXdata group with "rgb-image" interpretation', async () => {
expect(tabs[0]).toHaveTextContent(NexusVis.NxRGB);
});

test('visualize NXentry group with implicit default child NXdata group', async () => {
await renderApp();
await selectExplorerNode('nexus_entry_no_default');

const tabs = await findVisSelectorTabs();
expect(tabs).toHaveLength(1);
expect(tabs[0]).toHaveTextContent(NexusVis.NxSpectrum);
});

test('show error when encountering malformed NeXus metadata', async () => {
await renderApp();

Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/vis-packs/nexus/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export function isNxGroup(entity: Entity): boolean {
isGroup(entity) &&
(isNxDataGroup(entity) ||
hasAttribute(entity, 'default') ||
hasAttribute(entity, 'NX_class'))
getAttributeValue(entity, 'NX_class') === 'NXentry' ||
getAttributeValue(entity, 'NX_class') === 'NXroot')
);
}

Expand Down
19 changes: 9 additions & 10 deletions packages/shared/src/mock/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ export const mockMetadata = makeNxGroup(mockFilepath, 'NXroot', {
}),
],
}),
makeNxGroup('nexus_entry_no_default', 'NXentry', {
defaultPath: undefined,
children: [
makeNxGroup('ignore_me', 'NXprocess'),
makeNxDataGroup('spectrum', {
signal: makeNxDataset('oneD', intType, [41]),
}),
],
}),
makeGroup('nexus_malformed', [
makeGroup('default_not_string', [], {
attributes: [makeScalarAttr('default', intType, 42)],
Expand Down Expand Up @@ -209,15 +218,5 @@ export const mockMetadata = makeNxGroup(mockFilepath, 'NXroot', {
}),
}),
]),
makeNxGroup('no_default_nexus_entry', 'NXentry', {
defaultPath: undefined,
children: [
makeNxDataGroup('spectrum', {
signal: makeNxDataset('oneD', intType, [41]),
axes: { X: makeNxDataset('X', floatType, [41]) },
axesAttr: ['X'],
}),
],
}),
],
});

0 comments on commit a9ed6c3

Please sign in to comment.