2020-12-10 04:09:32 -05:00
|
|
|
import { screen } from '@testing-library/dom';
|
2022-05-13 08:08:49 -04:00
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { useOverclockTimers } from 'test_helpers/utils/overclock_timers';
|
2020-12-10 04:09:32 -05:00
|
|
|
import * as ideHelper from './helpers/ide_helper';
|
|
|
|
import startWebIDE from './helpers/start';
|
|
|
|
|
2020-12-17 13:10:14 -05:00
|
|
|
describe('IDE: User opens a file in the Web IDE', () => {
|
2020-12-10 04:09:32 -05:00
|
|
|
useOverclockTimers();
|
|
|
|
|
|
|
|
let vm;
|
|
|
|
let container;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2022-05-13 08:08:49 -04:00
|
|
|
setHTMLFixture('<div class="webide-container"></div>');
|
2020-12-10 04:09:32 -05:00
|
|
|
container = document.querySelector('.webide-container');
|
|
|
|
|
|
|
|
vm = startWebIDE(container);
|
|
|
|
|
|
|
|
await screen.findByText('README'); // wait for file tree to load
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
vm = null;
|
2022-05-13 08:08:49 -04:00
|
|
|
resetHTMLFixture();
|
2020-12-10 04:09:32 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('user opens a directory', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await ideHelper.openFile('files/images');
|
|
|
|
await screen.findByText('logo-white.png');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('expands directory in the left sidebar', () => {
|
|
|
|
expect(ideHelper.getFilesList()).toEqual(
|
|
|
|
expect.arrayContaining(['html', 'js', 'images', 'logo-white.png']),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('user opens a text file', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await ideHelper.openFile('README.md');
|
|
|
|
await ideHelper.waitForTabToOpen('README.md');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens the file in monaco editor', async () => {
|
|
|
|
expect(await ideHelper.getEditorValue()).toContain('Sample repo for testing gitlab features');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('user switches to review mode', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
ideHelper.switchLeftSidebarTab('Review');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows diff editor', async () => {
|
|
|
|
expect(await ideHelper.findMonacoDiffEditor()).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('user opens an image file', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await ideHelper.openFile('files/images/logo-white.png');
|
|
|
|
await ideHelper.waitForTabToOpen('logo-white.png');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens image viewer for the file', async () => {
|
|
|
|
const viewer = await screen.findByTestId('image-viewer');
|
|
|
|
const img = viewer.querySelector('img');
|
|
|
|
|
|
|
|
expect(img.src).toContain('logo-white.png');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('user opens a binary file', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await ideHelper.openFile('Gemfile.zip');
|
|
|
|
await ideHelper.waitForTabToOpen('Gemfile.zip');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('opens image viewer for the file', async () => {
|
|
|
|
const downloadButton = await screen.findByText('Download');
|
|
|
|
|
|
|
|
expect(downloadButton.getAttribute('download')).toEqual('Gemfile.zip');
|
|
|
|
expect(downloadButton.getAttribute('href')).toContain('/raw/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|