Skip to content

Commit f6e3191

Browse files
committed
update snapshots
Signed-off-by: Chenyang Ji <[email protected]>
1 parent ffb1dd0 commit f6e3191

File tree

11 files changed

+4050
-97
lines changed

11 files changed

+4050
-97
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@elastic/elastic-eslint-config-kibana": "link:../../packages/opensearch-eslint-config-opensearch-dashboards",
4343
"@elastic/eslint-import-resolver-kibana": "link:../../packages/osd-eslint-import-resolver-opensearch-dashboards",
4444
"@testing-library/dom": "^8.11.3",
45+
"@testing-library/jest-dom": "^5.16.2",
4546
"@testing-library/user-event": "^14.4.3",
4647
"@types/react-dom": "^16.9.8",
4748
"@types/object-hash": "^3.0.0",

public/pages/Configuration/Configuration.test.tsx

+6-24
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const defaultMemorySettings = {
3535
currTimeUnit: 'HOURS',
3636
};
3737

38-
const renderConfiguration = (overrides = {}) => {
38+
const renderConfiguration = (overrides = {}) =>
3939
render(
4040
<MemoryRouter>
4141
<Configuration
@@ -48,7 +48,6 @@ const renderConfiguration = (overrides = {}) => {
4848
/>
4949
</MemoryRouter>
5050
);
51-
};
5251

5352
const getWindowSizeConfigurations = () => screen.getAllByRole('combobox');
5453
const getTopNSizeConfiguration = () => screen.getByRole('spinbutton');
@@ -60,31 +59,13 @@ describe('Configuration Component', () => {
6059
});
6160

6261
it('renders with default settings', () => {
63-
renderConfiguration();
64-
// main header
65-
expect(
66-
screen.getByRole('heading', { name: /Top n queries monitoring configuration settings/i })
67-
).toBeInTheDocument();
68-
// section headers
69-
expect(screen.getByRole('heading', { name: /Metric Type/i })).toBeInTheDocument();
70-
expect(screen.getByRole('heading', { name: /Enabled/i })).toBeInTheDocument();
71-
expect(screen.getByRole('heading', { name: /Value of N/i })).toBeInTheDocument();
72-
expect(screen.getByRole('heading', { name: /Window size/i })).toBeInTheDocument();
73-
// Check values for window size configurations
74-
const selectBoxes = getWindowSizeConfigurations();
75-
expect(selectBoxes[0]).toHaveValue('latency');
76-
expect(selectBoxes[1]).toHaveValue('10');
77-
expect(selectBoxes[2]).toHaveValue('MINUTES');
78-
// Check the value for top n size configurations
79-
expect(getTopNSizeConfiguration()).toHaveValue(5);
80-
// Check the value for enabled switch
81-
const enableBox = getEnableToggle();
82-
expect(enableBox).toBeInTheDocument();
83-
expect(enableBox).toBeChecked();
62+
const { container } = renderConfiguration();
63+
expect(container).toMatchSnapshot('should match default settings snapshot');
8464
});
8565

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

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

0 commit comments

Comments
 (0)