debian-mirror-gitlab/spec/frontend/blob/pdf/pdf_viewer_spec.js

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

63 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-04-08 14:13:33 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2020-04-08 14:13:33 +05:30
import { FIXTURES_PATH } from 'spec/test_constants';
import component from '~/blob/pdf/pdf_viewer.vue';
import PdfLab from '~/pdf/index.vue';
const testPDF = `${FIXTURES_PATH}/blob/pdf/test.pdf`;
describe('PDF renderer', () => {
let wrapper;
const mountComponent = () => {
wrapper = shallowMount(component, {
propsData: {
pdf: testPDF,
},
});
};
2022-08-27 11:52:29 +05:30
const findLoading = () => wrapper.findComponent(GlLoadingIcon);
const findPdfLab = () => wrapper.findComponent(PdfLab);
const findLoadError = () => wrapper.findComponent({ ref: 'loadError' });
2020-04-08 14:13:33 +05:30
beforeEach(() => {
mountComponent();
});
it('shows loading icon', () => {
expect(findLoading().exists()).toBe(true);
});
describe('successful response', () => {
beforeEach(() => {
findPdfLab().vm.$emit('pdflabload');
});
it('does not show loading icon', () => {
expect(findLoading().exists()).toBe(false);
});
it('renders the PDF', () => {
expect(findPdfLab().exists()).toBe(true);
});
});
describe('error getting file', () => {
beforeEach(() => {
findPdfLab().vm.$emit('pdflaberror', 'foo');
});
it('does not show loading icon', () => {
expect(findLoading().exists()).toBe(false);
});
it('shows error message', () => {
expect(findLoadError().text()).toBe(
'An error occurred while loading the file. Please try again later.',
);
});
});
});