Assert policies rendering against fully mounted table

parent e0a79b85
import { GlTable, GlDrawer } from '@gitlab/ui'; import { GlTable, GlDrawer } from '@gitlab/ui';
import { createLocalVue } from '@vue/test-utils'; import { createLocalVue } from '@vue/test-utils';
import { merge, cloneDeep } from 'lodash'; import { merge } from 'lodash';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import PolicyList from 'ee/threat_monitoring/components/policy_list.vue'; import PolicyList from 'ee/threat_monitoring/components/policy_list.vue';
import networkPoliciesQuery from 'ee/threat_monitoring/graphql/queries/network_policies.query.graphql'; import networkPoliciesQuery from 'ee/threat_monitoring/graphql/queries/network_policies.query.graphql';
import scanExecutionPoliciesQuery from 'ee/threat_monitoring/graphql/queries/scan_execution_policies.query.graphql'; import scanExecutionPoliciesQuery from 'ee/threat_monitoring/graphql/queries/scan_execution_policies.query.graphql';
import createStore from 'ee/threat_monitoring/store'; import createStore from 'ee/threat_monitoring/store';
import createMockApolloProvider from 'helpers/mock_apollo_helper'; import createMockApolloProvider from 'helpers/mock_apollo_helper';
import { stubComponent } from 'helpers/stub_component';
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
import { networkPolicies, scanExecutionPolicies } from '../mocks/mock_apollo'; import { networkPolicies, scanExecutionPolicies } from '../mocks/mock_apollo';
import { mockNetworkPoliciesResponse, mockScanExecutionPoliciesResponse } from '../mocks/mock_data'; import { mockNetworkPoliciesResponse, mockScanExecutionPoliciesResponse } from '../mocks/mock_data';
...@@ -137,33 +137,26 @@ describe('PolicyList component', () => { ...@@ -137,33 +137,26 @@ describe('PolicyList component', () => {
}); });
describe('given policies have been fetched', () => { describe('given policies have been fetched', () => {
beforeEach(() => { let rows;
mountShallowWrapper({
stubs: {
GlTable: stubComponent(GlTable, {
template: '<table data-testid="table" />',
props: ['items'],
}),
},
});
});
it('passes all policies to the table', () => { beforeEach(async () => {
expect(cloneDeep(wrapper.findByTestId('table').props('items'))).toEqual([ mountWrapper();
expect.objectContaining({ await waitForPromises();
name: mockNetworkPoliciesResponse[0].name, rows = wrapper.findAll('tr');
}), });
expect.objectContaining({
name: 'drop-outbound', it.each`
}), rowIndex | expectedPolicyName
expect.objectContaining({ ${1} | ${mockNetworkPoliciesResponse[0].name}
name: 'allow-inbound-http', ${2} | ${'drop-outbound'}
}), ${3} | ${'allow-inbound-http'}
expect.objectContaining({ ${4} | ${mockScanExecutionPoliciesResponse[0].name}
name: mockScanExecutionPoliciesResponse[0].name, `(
}), 'renders "$expectedPolicyName" policy in row #$rowIndex',
]); ({ expectedPolicyName, rowIndex }) => {
}); expect(rows.at(rowIndex).text()).toContain(expectedPolicyName);
},
);
}); });
describe('with allEnvironments enabled', () => { describe('with allEnvironments enabled', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment