debian-mirror-gitlab/spec/frontend/vue_shared/components/markdown/suggestions_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2 KiB
JavaScript
Raw Normal View History

2023-06-20 00:43:36 +05:30
import { nextTick } from 'vue';
import { mountExtended } from 'helpers/vue_test_utils_helper';
2019-02-15 15:39:39 +05:30
import SuggestionsComponent from '~/vue_shared/components/markdown/suggestions.vue';
const MOCK_DATA = {
2019-07-07 11:18:12 +05:30
suggestions: [
{
id: 1,
appliable: true,
applied: false,
current_user: {
can_apply: true,
},
diff_lines: [
{
can_receive_suggestion: false,
line_code: null,
meta_data: null,
new_line: null,
old_line: 5,
rich_text: '-test',
text: '-test',
type: 'old',
},
{
can_receive_suggestion: true,
line_code: null,
meta_data: null,
new_line: 5,
old_line: null,
rich_text: '+new test',
text: '+new test',
type: 'new',
},
],
},
],
2019-02-15 15:39:39 +05:30
noteHtml: `
2019-07-07 11:18:12 +05:30
<div class="suggestion">
<div class="line">-oldtest</div>
2020-05-24 23:13:21 +05:30
</div>
2019-02-15 15:39:39 +05:30
<div class="suggestion">
2019-07-07 11:18:12 +05:30
<div class="line">+newtest</div>
2020-05-24 23:13:21 +05:30
</div>
2019-02-15 15:39:39 +05:30
`,
isApplied: false,
helpPagePath: 'path_to_docs',
2021-03-08 18:12:59 +05:30
defaultCommitMessage: 'Apply suggestion',
2019-02-15 15:39:39 +05:30
};
describe('Suggestion component', () => {
2023-06-20 00:43:36 +05:30
let wrapper;
2019-02-15 15:39:39 +05:30
2023-06-20 00:43:36 +05:30
const createComponent = (props = {}) => {
wrapper = mountExtended(SuggestionsComponent, {
propsData: {
...MOCK_DATA,
...props,
},
});
};
2019-02-15 15:39:39 +05:30
2023-06-20 00:43:36 +05:30
const findSuggestionsContainer = () => wrapper.findByTestId('suggestions-container');
2019-02-15 15:39:39 +05:30
2023-06-20 00:43:36 +05:30
beforeEach(async () => {
createComponent();
2019-02-15 15:39:39 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2019-02-15 15:39:39 +05:30
});
describe('mounted', () => {
it('renders a flash container', () => {
2023-06-20 00:43:36 +05:30
expect(wrapper.find('.js-suggestions-flash').exists()).toBe(true);
2019-02-15 15:39:39 +05:30
});
it('renders a container for suggestions', () => {
2023-06-20 00:43:36 +05:30
expect(findSuggestionsContainer().exists()).toBe(true);
2019-02-15 15:39:39 +05:30
});
it('renders suggestions', () => {
2023-06-20 00:43:36 +05:30
expect(findSuggestionsContainer().text()).toContain('oldtest');
expect(findSuggestionsContainer().text()).toContain('newtest');
2019-02-15 15:39:39 +05:30
});
});
});