Commit d9bb4cd1 authored by Mark Florian's avatar Mark Florian

Verify exact strings in tests

This approach gives us two things:

1. Exact strings are verified, rather than more loosely checking for
   a substring
2. Should the string change in future, these tests no longer have to
   change. The purpose of them is to verify that some constant is
   returned, but they don't care what that constant actually contains.
parent b9e5d0c9
import createState from 'ee/security_dashboard/store/modules/filters/state'; import createState from 'ee/security_dashboard/store/modules/filters/state';
import * as getters from 'ee/security_dashboard/store/modules/filters/getters'; import * as getters from 'ee/security_dashboard/store/modules/filters/getters';
import { BASE_FILTERS } from 'ee/security_dashboard/store/modules/filters/constants';
describe('filters module getters', () => { describe('filters module getters', () => {
const mockedGetters = state => { const mockedGetters = state => {
...@@ -28,13 +29,13 @@ describe('filters module getters', () => { ...@@ -28,13 +29,13 @@ describe('filters module getters', () => {
describe('getSelectedOptions', () => { describe('getSelectedOptions', () => {
describe('with one selected option', () => { describe('with one selected option', () => {
it('should return "All" as the selected option', () => { it('should return the base filter as the selected option', () => {
const selectedOptions = getters.getSelectedOptions(state, mockedGetters(state))( const selectedOptions = getters.getSelectedOptions(state, mockedGetters(state))(
'report_type', 'report_type',
); );
expect(selectedOptions).toHaveLength(1); expect(selectedOptions).toHaveLength(1);
expect(selectedOptions[0].name).toContain('All'); expect(selectedOptions[0].name).toBe(BASE_FILTERS.report_type.name);
}); });
}); });
...@@ -57,12 +58,12 @@ describe('filters module getters', () => { ...@@ -57,12 +58,12 @@ describe('filters module getters', () => {
}); });
describe('getSelectedOptionNames', () => { describe('getSelectedOptionNames', () => {
it('should return "All" as the selected option', () => { it('should return the base filter as the selected option', () => {
const selectedOptionNames = getters.getSelectedOptionNames(state, mockedGetters(state))( const selectedOptionNames = getters.getSelectedOptionNames(state, mockedGetters(state))(
'severity', 'severity',
); );
expect(selectedOptionNames.firstOption).toContain('All'); expect(selectedOptionNames.firstOption).toBe(BASE_FILTERS.severity.name);
expect(selectedOptionNames.extraOptionCount).toBe(''); expect(selectedOptionNames.extraOptionCount).toBe('');
}); });
......
...@@ -2,6 +2,7 @@ import createStore from 'ee/security_dashboard/store/index'; ...@@ -2,6 +2,7 @@ import createStore from 'ee/security_dashboard/store/index';
import * as projectsMutationTypes from 'ee/security_dashboard/store/modules/projects/mutation_types'; import * as projectsMutationTypes from 'ee/security_dashboard/store/modules/projects/mutation_types';
import * as filtersMutationTypes from 'ee/security_dashboard/store/modules/filters/mutation_types'; import * as filtersMutationTypes from 'ee/security_dashboard/store/modules/filters/mutation_types';
import * as vulnerabilitiesMutationTypes from 'ee/security_dashboard/store/modules/vulnerabilities/mutation_types'; import * as vulnerabilitiesMutationTypes from 'ee/security_dashboard/store/modules/vulnerabilities/mutation_types';
import { BASE_FILTERS } from 'ee/security_dashboard/store/modules/filters/constants';
describe('moderator', () => { describe('moderator', () => {
let store; let store;
...@@ -22,7 +23,7 @@ describe('moderator', () => { ...@@ -22,7 +23,7 @@ describe('moderator', () => {
'filters/setFilterOptions', 'filters/setFilterOptions',
Object({ Object({
filterId: 'project_id', filterId: 'project_id',
options: [{ name: 'All projects', id: 'all' }, { name: 'foo', id: '1' }], options: [BASE_FILTERS.project_id, { name: 'foo', id: '1' }],
}), }),
); );
}); });
......
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