vulnerability_training_spec.js 2.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
import VulnerabilityTraining, {
  i18n,
} from 'ee/vulnerabilities/components/vulnerability_training.vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { SUPPORTED_REFERENCE_SCHEMA } from 'ee/vulnerabilities/constants';

const defaultProps = {
  identifiers: [{ externalType: SUPPORTED_REFERENCE_SCHEMA.cwe }, { externalType: 'cve' }],
};

describe('VulnerabilityTraining component', () => {
  let wrapper;

  const createComponent = (props = {}) => {
    wrapper = shallowMountExtended(VulnerabilityTraining, {
      propsData: {
        ...defaultProps,
        ...props,
      },
    });
  };

  afterEach(() => {
    wrapper.destroy();
  });

  const findTitle = () => wrapper.findByRole('heading', i18n.trainingTitle);
  const findDescription = () => wrapper.findByTestId('description');
  const findUnavailableMessage = () => wrapper.findByTestId('unavailable-message');

  describe('basic structure', () => {
    beforeEach(() => {
      createComponent();
    });

    it('displays the title', () => {
      expect(findTitle().text()).toBe(i18n.trainingTitle);
    });

    it('displays the description', () => {
      expect(findDescription().text()).toBe(i18n.trainingDescription);
    });
  });

  describe('training availability message', () => {
    it('displays the message', () => {
      createComponent({ identifiers: [{ externalType: 'not supported identifier' }] });
      expect(findUnavailableMessage().text()).toBe(i18n.trainingUnavailable);
    });

    it.each`
      identifiers                                                         | exists
      ${[{ externalType: 'cve' }]}                                        | ${true}
      ${[{ externalType: SUPPORTED_REFERENCE_SCHEMA.cwe.toUpperCase() }]} | ${false}
      ${[{ externalType: SUPPORTED_REFERENCE_SCHEMA.cwe.toLowerCase() }]} | ${false}
    `('sets it to "$exists" for "$identifiers"', ({ identifiers, exists }) => {
      createComponent({ identifiers });
      expect(findUnavailableMessage().exists()).toBe(exists);
    });
  });
});