datajunction-ui 0.0.31 → 0.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,14 @@ import { NodePage } from '../Loadable';
6
6
  import { MemoryRouter, Route, Routes } from 'react-router-dom';
7
7
  import userEvent from '@testing-library/user-event';
8
8
 
9
+ // Mock cronstrue for NodePreAggregationsTab
10
+ jest.mock('cronstrue', () => ({
11
+ toString: () => 'Every day at midnight',
12
+ }));
13
+
14
+ // Mock CSS imports
15
+ jest.mock('../../../../styles/preaggregations.css', () => ({}));
16
+
9
17
  describe('<NodePage />', () => {
10
18
  const domTestingLib = require('@testing-library/dom');
11
19
  const { queryHelpers } = domTestingLib;
@@ -61,6 +69,8 @@ describe('<NodePage />', () => {
61
69
  removeComplexDimensionLink: jest
62
70
  .fn()
63
71
  .mockResolvedValue({ status: 200 }),
72
+ listPreaggs: jest.fn().mockResolvedValue({ items: [] }),
73
+ deactivatePreaggWorkflow: jest.fn().mockResolvedValue({ status: 200 }),
64
74
  },
65
75
  };
66
76
  };
@@ -609,13 +619,13 @@ describe('<NodePage />', () => {
609
619
 
610
620
  it('renders an empty NodeMaterialization tab correctly', async () => {
611
621
  const djClient = mockDJClient();
612
- djClient.DataJunctionAPI.node.mockReturnValue(mocks.mockMetricNode);
622
+ djClient.DataJunctionAPI.node.mockResolvedValue(mocks.mockMetricNode);
613
623
  djClient.DataJunctionAPI.getMetric.mockResolvedValue(
614
624
  mocks.mockMetricNodeJson,
615
625
  );
616
- djClient.DataJunctionAPI.columns.mockReturnValue(mocks.metricNodeColumns);
617
- djClient.DataJunctionAPI.materializations.mockReturnValue([]);
618
- djClient.DataJunctionAPI.availabilityStates.mockReturnValue([]);
626
+ djClient.DataJunctionAPI.columns.mockResolvedValue(mocks.metricNodeColumns);
627
+ // For metric nodes, listPreaggs is called, not materializations
628
+ djClient.DataJunctionAPI.listPreaggs.mockResolvedValue({ items: [] });
619
629
 
620
630
  const element = (
621
631
  <DJClientContext.Provider value={djClient}>
@@ -631,35 +641,40 @@ describe('<NodePage />', () => {
631
641
  </Routes>
632
642
  </MemoryRouter>,
633
643
  );
634
- await waitFor(
635
- () => {
636
- fireEvent.click(
637
- screen.getByRole('button', { name: 'Materializations' }),
638
- );
639
- expect(djClient.DataJunctionAPI.materializations).toHaveBeenCalledWith(
640
- mocks.mockMetricNode.name,
641
- );
642
- screen.getByText(
643
- 'No materialization workflows configured for this revision.',
644
- );
645
- },
646
- { timeout: 5000 },
647
- );
644
+
645
+ // For metric nodes, NodePreAggregationsTab is used, which calls listPreaggs
646
+ await waitFor(() => {
647
+ expect(djClient.DataJunctionAPI.listPreaggs).toHaveBeenCalledWith({
648
+ node_name: mocks.mockMetricNode.name,
649
+ include_stale: true,
650
+ });
651
+ });
652
+
653
+ // Check for the empty state text (for NodePreAggregationsTab)
654
+ expect(
655
+ screen.getByText('No pre-aggregations found for this node.'),
656
+ ).toBeInTheDocument();
648
657
  });
649
658
 
650
659
  it('renders the NodeMaterialization tab with materializations correctly', async () => {
651
660
  const djClient = mockDJClient();
652
- djClient.DataJunctionAPI.node.mockReturnValue(mocks.mockTransformNode);
653
- djClient.DataJunctionAPI.getMetric.mockResolvedValue(
654
- mocks.mockMetricNodeJson,
655
- );
656
- djClient.DataJunctionAPI.columns.mockReturnValue(mocks.metricNodeColumns);
657
- djClient.DataJunctionAPI.materializations.mockReturnValue(
661
+ // Use cube node - only cubes use NodeMaterializationTab
662
+ // Override columns with explicit partition: null to avoid undefined.type_ error
663
+ const cubeNodeWithPartitions = {
664
+ ...mocks.mockCubeNode,
665
+ columns: mocks.mockCubeNode.columns.map(col => ({
666
+ ...col,
667
+ partition: null,
668
+ })),
669
+ };
670
+ djClient.DataJunctionAPI.node.mockResolvedValue(cubeNodeWithPartitions);
671
+ djClient.DataJunctionAPI.cube.mockResolvedValue(mocks.mockCubesCube);
672
+ djClient.DataJunctionAPI.columns.mockResolvedValue([]);
673
+ djClient.DataJunctionAPI.materializations.mockResolvedValue(
658
674
  mocks.nodeMaterializations,
659
675
  );
660
- djClient.DataJunctionAPI.availabilityStates.mockReturnValue([]);
661
-
662
- djClient.DataJunctionAPI.materializationInfo.mockReturnValue(
676
+ djClient.DataJunctionAPI.availabilityStates.mockResolvedValue([]);
677
+ djClient.DataJunctionAPI.materializationInfo.mockResolvedValue(
663
678
  mocks.materializationInfo,
664
679
  );
665
680
 
@@ -670,30 +685,28 @@ describe('<NodePage />', () => {
670
685
  );
671
686
  render(
672
687
  <MemoryRouter
673
- initialEntries={[
674
- '/nodes/default.repair_order_transform/materializations',
675
- ]}
688
+ initialEntries={['/nodes/default.repair_orders_cube/materializations']}
676
689
  >
677
690
  <Routes>
678
691
  <Route path="nodes/:name/:tab" element={element} />
679
692
  </Routes>
680
693
  </MemoryRouter>,
681
694
  );
682
- await waitFor(
683
- () => {
684
- fireEvent.click(
685
- screen.getByRole('button', { name: 'Materializations' }),
686
- );
687
- expect(djClient.DataJunctionAPI.node).toHaveBeenCalledWith(
688
- mocks.mockTransformNode.name,
689
- );
690
- expect(djClient.DataJunctionAPI.materializations).toHaveBeenCalledWith(
691
- mocks.mockTransformNode.name,
692
- );
693
- },
694
- { timeout: 3000 },
695
- );
696
- }, 60000);
695
+
696
+ // Wait for the node to load first
697
+ await waitFor(() => {
698
+ expect(djClient.DataJunctionAPI.node).toHaveBeenCalledWith(
699
+ 'default.repair_orders_cube',
700
+ );
701
+ });
702
+
703
+ // Then wait for materializations to be fetched
704
+ await waitFor(() => {
705
+ expect(djClient.DataJunctionAPI.materializations).toHaveBeenCalledWith(
706
+ mocks.mockCubeNode.name,
707
+ );
708
+ });
709
+ });
697
710
 
698
711
  it('renders the NodeValidate tab', async () => {
699
712
  const djClient = mockDJClient();