MountingPortal: stubComponent()

in ee/spec/frontend/vulnerabilities/vulnerability_details_spec.js [75:212]


        MountingPortal: stubComponent(MountingPortal),
      },
      mocks: { $router },
    });
  };

  const getById = (id) => wrapper.findByTestId(id);
  const getAllById = (id) => wrapper.findAllByTestId(id);
  const getText = (id) => getById(id).text();
  const getLink = (id) => getById(id).findComponent(GlLink).attributes('href');
  const findVulnerabilityTraining = () => wrapper.findComponent(VulnerabilityTraining);
  const findFalsePositiveAlert = () => wrapper.findComponent(FalsePositiveAlert);
  const findDependencyPath = () => wrapper.findComponent(DependencyPath);

  it('shows the properties that should always be shown', () => {
    createWrapper();
    expect(getById('description').html()).toContain(vulnerability.descriptionHtml);
    expect(wrapper.findComponent(SeverityBadge).props('severity')).toBe(vulnerability.severity);
    expect(wrapper.findComponent(SeverityBadge).props('severityOverride')).toBe(
      vulnerability.severityOverride,
    );
    expect(wrapper.findComponent(SeverityBadge).props('showSeverityOverrides')).toBe(true);
    expect(getText('reportType')).toBe(`Report type: ${vulnerability.reportType}`);

    expect(getById('cvss').exists()).toBe(false);
    expect(getById('kev').exists()).toBe(false);
    expect(getById('epss').exists()).toBe(false);
    expect(getById('project').exists()).toBe(false);
    expect(findFalsePositiveAlert().exists()).toBe(false);
    expect(getById('image').exists()).toBe(false);
    expect(getById('os').exists()).toBe(false);
    expect(getById('file').exists()).toBe(false);
    expect(getById('class').exists()).toBe(false);
    expect(getById('method').exists()).toBe(false);
    expect(getById('url').exists()).toBe(false);
    expect(getById('evidence').exists()).toBe(false);
    expect(getById('scanner').exists()).toBe(false);
    expect(getById('validityCheck').exists()).toBe(false);
    expect(getById('show-code-flow').exists()).toBe(true);
    expect(getAllById('link')).toHaveLength(0);
    expect(getAllById('identifier')).toHaveLength(0);
  });

  describe('when the feature flag "vulnerabilityReportTypeScannerFilter" is disabled', () => {
    it('shows the properties that should always be shown', () => {
      createWrapper({}, { vulnerabilityReportTypeScannerFilter: false });
      expect(getText('reportType')).toBe(`Tool: ${vulnerability.reportType}`);
    });
  });

  it('renders gfm', () => {
    createWrapper();

    expect(renderGFM).toHaveBeenCalledWith(getById('description').element);
  });

  it.each([true, false])(
    'shows/hides the false-positive alert when `falsePositive` is: %s',
    (falsePositive) => {
      createWrapper({ falsePositive });
      expect(findFalsePositiveAlert().exists()).toBe(falsePositive);
    },
  );

  it('renders description when descriptionHtml is not present', () => {
    createWrapper({
      descriptionHtml: null,
    });
    expect(getById('description').html()).not.toContain(vulnerability.descriptionHtml);
    expect(getText('description')).toBe(vulnerability.description);
  });

  it('shows a link to the project if it exists', () => {
    const project = {
      fullName: 'myProject',
      fullPath: '/path/to/project',
    };
    createWrapper({ project });
    const projectLink = getById('project').findComponent(GlLink);

    expect(projectLink.attributes('href')).toBe(project.fullPath);
    expect(projectLink.text()).toBe(project.fullName);
  });

  it.each`
    reportType                  | expectedOutput
    ${'SAST'}                   | ${'SAST'}
    ${'DAST'}                   | ${'DAST'}
    ${'DEPENDENCY_SCANNING'}    | ${'Dependency Scanning'}
    ${'CONTAINER_SCANNING'}     | ${'Container Scanning'}
    ${'SECRET_DETECTION'}       | ${'Secret Detection'}
    ${'COVERAGE_FUZZING'}       | ${'Coverage Fuzzing'}
    ${'API_FUZZING'}            | ${'API Fuzzing'}
    ${'CLUSTER_IMAGE_SCANNING'} | ${'Cluster Image Scanning'}
  `(
    'displays "$expectedOutput" when report type is "$reportType"',
    ({ reportType, expectedOutput }) => {
      createWrapper({ reportType });
      expect(getText('reportType')).toBe(`Report type: ${expectedOutput}`);
    },
  );

  it('shows the location image if it exists', () => {
    createWrapper({ location: { image: 'some image' } });
    expect(getText('image')).toBe(`Image: some image`);
  });

  it('shows the location image as a link if it exists', () => {
    createWrapper({
      location: { image: 'some image', containerRepositoryUrl: 'http://www.gitlab.com' },
    });
    expect(getText('image')).toBe(`Image: some image`);
    expect(getLink('image')).toBe('http://www.gitlab.com');
  });

  it('shows the operating system if it exists', () => {
    createWrapper({ location: { operatingSystem: 'linux' } });
    expect(getText('namespace')).toBe(`Namespace: linux`);
  });

  it('shows the vulnerability class if it exists', () => {
    createWrapper({ location: { file: 'file', class: 'class name' } });
    expect(getText('class')).toBe(`Class: class name`);
  });

  it('shows the crash state if it exists', () => {
    createWrapper({ location: { crashState: 'crash state' } });
    expect(getText('crash_state')).toBe(`Crash State: crash state`);
  });

  it('shows the vulnerability method if it exists', () => {
    createWrapper({ location: { vulnerableMethod: 'method name' } });
    expect(getText('method')).toBe(`Method: method name`);
  });

  describe('security scores', () => {
    it('shows security scores', () => {
      createWrapper({