Skip to content

Commit

Permalink
update snapshots
Browse files Browse the repository at this point in the history
Signed-off-by: Chenyang Ji <[email protected]>
  • Loading branch information
ansjcy committed Jan 14, 2025
1 parent ffb1dd0 commit 02e1c64
Show file tree
Hide file tree
Showing 12 changed files with 4,056 additions and 104 deletions.
12 changes: 6 additions & 6 deletions cypress/e2e/2_query_details.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ describe('Top Queries Details Page', () => {
'CPU Time',
'Memory Usage',
'Indices',
'Search type',
'Coordinator node ID',
'Total shards',
'Search Type',
'Coordinator Node ID',
'Total Shards',
];
fieldLabels.forEach((label) => {
cy.get('.euiPanel').contains('h4', label).should('be.visible');
Expand Down Expand Up @@ -96,19 +96,19 @@ describe('Top Queries Details Page', () => {
// Validate Indices
cy.contains('h4', 'Indices').parent().next().invoke('text').should('not.be.empty');
// Validate Search Type
cy.contains('h4', 'Search type')
cy.contains('h4', 'Search Type')
.parent()
.next()
.invoke('text')
.should('equal', 'query then fetch');
// Validate Coordinator Node ID
cy.contains('h4', 'Coordinator node ID')
cy.contains('h4', 'Coordinator Node ID')
.parent()
.next()
.invoke('text')
.should('not.be.empty');
// Validate Total Shards
cy.contains('h4', 'Total shards')
cy.contains('h4', 'Total Shards')
.parent()
.next()
.invoke('text')
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@elastic/elastic-eslint-config-kibana": "link:../../packages/opensearch-eslint-config-opensearch-dashboards",
"@elastic/eslint-import-resolver-kibana": "link:../../packages/osd-eslint-import-resolver-opensearch-dashboards",
"@testing-library/dom": "^8.11.3",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/user-event": "^14.4.3",
"@types/react-dom": "^16.9.8",
"@types/object-hash": "^3.0.0",
Expand Down
31 changes: 6 additions & 25 deletions public/pages/Configuration/Configuration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,18 @@ const defaultMemorySettings = {
currTimeUnit: 'HOURS',
};

const renderConfiguration = (overrides = {}) => {
const renderConfiguration = (overrides = {}) =>
render(
<MemoryRouter>
<Configuration
latencySettings={{ ...defaultLatencySettings, ...overrides }}
cpuSettings={defaultCpuSettings}
memorySettings={defaultMemorySettings}
configInfo={mockConfigInfo}
// @ts-ignore
core={mockCoreStart}
/>
</MemoryRouter>
);
};

const getWindowSizeConfigurations = () => screen.getAllByRole('combobox');
const getTopNSizeConfiguration = () => screen.getByRole('spinbutton');
Expand All @@ -60,31 +58,13 @@ describe('Configuration Component', () => {
});

it('renders with default settings', () => {
renderConfiguration();
// main header
expect(
screen.getByRole('heading', { name: /Top n queries monitoring configuration settings/i })
).toBeInTheDocument();
// section headers
expect(screen.getByRole('heading', { name: /Metric Type/i })).toBeInTheDocument();
expect(screen.getByRole('heading', { name: /Enabled/i })).toBeInTheDocument();
expect(screen.getByRole('heading', { name: /Value of N/i })).toBeInTheDocument();
expect(screen.getByRole('heading', { name: /Window size/i })).toBeInTheDocument();
// Check values for window size configurations
const selectBoxes = getWindowSizeConfigurations();
expect(selectBoxes[0]).toHaveValue('latency');
expect(selectBoxes[1]).toHaveValue('10');
expect(selectBoxes[2]).toHaveValue('MINUTES');
// Check the value for top n size configurations
expect(getTopNSizeConfiguration()).toHaveValue(5);
// Check the value for enabled switch
const enableBox = getEnableToggle();
expect(enableBox).toBeInTheDocument();
expect(enableBox).toBeChecked();
const { container } = renderConfiguration();
expect(container).toMatchSnapshot('should match default settings snapshot');
});

// The following tests test the interactions on the frontend with Mocks.
it('updates state when toggling metrics and enables Save button when changes are made', () => {
renderConfiguration();
const { container } = renderConfiguration();
// before toggling the metric
expect(getWindowSizeConfigurations()[0]).toHaveValue('latency');
expect(getEnableToggle()).toBeChecked();
Expand All @@ -100,6 +80,7 @@ describe('Configuration Component', () => {
fireEvent.click(getEnableToggle());
expect(getEnableToggle()).toBeChecked();
expect(screen.getByText('Save')).toBeEnabled();
expect(container).toMatchSnapshot('should match settings snapshot after toggling');
});

it('validates topNSize and windowSize inputs and disables Save button for invalid input', () => {
Expand Down
Loading

0 comments on commit 02e1c64

Please sign in to comment.