2021-01-14 13:10:59 -05:00
|
|
|
import { setTestTimeout } from 'helpers/timeout';
|
2021-02-15 16:08:59 -05:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import { waitForText } from 'helpers/wait_for_text';
|
2020-09-29 14:09:52 -04:00
|
|
|
import { createCommitId } from 'test_helpers/factories/commit_id';
|
2021-02-15 16:08:59 -05:00
|
|
|
import { useOverclockTimers } from 'test_helpers/utils/overclock_timers';
|
2020-11-19 04:09:38 -05:00
|
|
|
import * as ideHelper from './helpers/ide_helper';
|
2020-11-25 01:09:20 -05:00
|
|
|
import startWebIDE from './helpers/start';
|
2020-05-15 17:08:21 -04:00
|
|
|
|
|
|
|
describe('WebIDE', () => {
|
2020-08-06 17:10:15 -04:00
|
|
|
useOverclockTimers();
|
|
|
|
|
2020-05-15 17:08:21 -04:00
|
|
|
let vm;
|
2020-11-19 04:09:38 -05:00
|
|
|
let container;
|
2020-05-15 17:08:21 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-01-14 13:10:59 -05:00
|
|
|
// For some reason these tests were timing out in CI.
|
|
|
|
// We will investigate in https://gitlab.com/gitlab-org/gitlab/-/issues/298714
|
|
|
|
setTestTimeout(20000);
|
2020-11-19 04:09:38 -05:00
|
|
|
setFixtures('<div class="webide-container"></div>');
|
|
|
|
container = document.querySelector('.webide-container');
|
2020-05-15 17:08:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
vm = null;
|
|
|
|
});
|
2020-09-29 14:09:52 -04:00
|
|
|
|
|
|
|
it('user commits changes', async () => {
|
2020-11-25 01:09:20 -05:00
|
|
|
vm = startWebIDE(container);
|
2020-09-29 14:09:52 -04:00
|
|
|
|
|
|
|
await ideHelper.createFile('foo/bar/test.txt', 'Lorem ipsum dolar sit');
|
|
|
|
await ideHelper.deleteFile('foo/bar/.gitkeep');
|
|
|
|
await ideHelper.commit();
|
|
|
|
|
|
|
|
const commitId = createCommitId(1);
|
|
|
|
const commitShortId = commitId.slice(0, 8);
|
|
|
|
|
|
|
|
await waitForText('All changes are committed');
|
|
|
|
await waitForText(commitShortId);
|
|
|
|
|
|
|
|
expect(mockServer.db.branches.findBy({ name: 'master' }).commit).toMatchObject({
|
|
|
|
short_id: commitShortId,
|
|
|
|
id: commitId,
|
|
|
|
message: 'Update foo/bar/test.txt\nDeleted foo/bar/.gitkeep',
|
|
|
|
__actions: [
|
|
|
|
{
|
|
|
|
action: 'create',
|
|
|
|
content: 'Lorem ipsum dolar sit\n',
|
|
|
|
encoding: 'text',
|
|
|
|
file_path: 'foo/bar/test.txt',
|
|
|
|
last_commit_id: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'delete',
|
|
|
|
encoding: 'text',
|
|
|
|
file_path: 'foo/bar/.gitkeep',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
2020-10-29 05:08:38 -04:00
|
|
|
|
2021-01-13 22:10:47 -05:00
|
|
|
it('user commits changes to new branch', async () => {
|
|
|
|
vm = startWebIDE(container);
|
|
|
|
|
|
|
|
expect(window.location.pathname).toBe('/-/ide/project/gitlab-test/lorem-ipsum/tree/master/-/');
|
|
|
|
|
|
|
|
await ideHelper.updateFile('README.md', 'Lorem dolar si amit\n');
|
|
|
|
await ideHelper.commit({ newBranch: true, newMR: false, newBranchName: 'test-hello-world' });
|
|
|
|
|
|
|
|
await waitForText('All changes are committed');
|
|
|
|
|
|
|
|
// Wait for IDE to load new commit
|
|
|
|
await waitForText('10000000', document.querySelector('.ide-status-bar'));
|
|
|
|
|
|
|
|
// It's important that the new branch is now in the route
|
|
|
|
expect(window.location.pathname).toBe(
|
|
|
|
'/-/ide/project/gitlab-test/lorem-ipsum/blob/test-hello-world/-/README.md',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-10-29 05:08:38 -04:00
|
|
|
it('user adds file that starts with +', async () => {
|
2020-11-25 01:09:20 -05:00
|
|
|
vm = startWebIDE(container);
|
2020-10-29 05:08:38 -04:00
|
|
|
|
|
|
|
await ideHelper.createFile('+test', 'Hello world!');
|
|
|
|
await ideHelper.openFile('+test');
|
|
|
|
|
|
|
|
// Wait for monaco things
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
// Assert that +test is the only open tab
|
|
|
|
const tabs = Array.from(document.querySelectorAll('.multi-file-tab'));
|
2020-12-23 16:10:24 -05:00
|
|
|
expect(tabs.map((x) => x.textContent.trim())).toEqual(['+test']);
|
2020-10-29 05:08:38 -04:00
|
|
|
});
|
2020-12-01 19:09:45 -05:00
|
|
|
|
|
|
|
describe('editor info', () => {
|
|
|
|
let statusBar;
|
|
|
|
let editor;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
vm = startWebIDE(container);
|
|
|
|
|
|
|
|
await ideHelper.openFile('README.md');
|
|
|
|
editor = await ideHelper.waitForMonacoEditor();
|
|
|
|
|
|
|
|
statusBar = ideHelper.getStatusBar();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows line position and type', () => {
|
|
|
|
expect(statusBar).toHaveText('1:1');
|
|
|
|
expect(statusBar).toHaveText('markdown');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('persists viewer', async () => {
|
|
|
|
const markdownPreview = 'test preview_markdown result';
|
|
|
|
mockServer.post('/:namespace/:project/preview_markdown', () => ({
|
|
|
|
body: markdownPreview,
|
|
|
|
}));
|
|
|
|
|
|
|
|
await ideHelper.openFile('README.md');
|
|
|
|
ideHelper.clickPreviewMarkdown();
|
|
|
|
|
|
|
|
const el = await waitForText(markdownPreview);
|
|
|
|
expect(el).toHaveText(markdownPreview);
|
|
|
|
|
|
|
|
// Need to wait for monaco editor to load so it doesn't through errors on dispose
|
|
|
|
await ideHelper.openFile('.gitignore');
|
2021-02-18 13:10:41 -05:00
|
|
|
await ideHelper.waitForEditorModelChange(editor);
|
2020-12-01 19:09:45 -05:00
|
|
|
await ideHelper.openFile('README.md');
|
2021-02-18 13:10:41 -05:00
|
|
|
await ideHelper.waitForEditorModelChange(editor);
|
2020-12-01 19:09:45 -05:00
|
|
|
|
|
|
|
expect(el).toHaveText(markdownPreview);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when editor position changes', () => {
|
|
|
|
beforeEach(async () => {
|
2021-02-18 13:10:41 -05:00
|
|
|
editor.setPosition({ lineNumber: 4, column: 10 });
|
|
|
|
await vm.$nextTick();
|
2020-12-01 19:09:45 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows new line position', () => {
|
|
|
|
expect(statusBar).not.toHaveText('1:1');
|
|
|
|
expect(statusBar).toHaveText('4:10');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates after rename', async () => {
|
|
|
|
await ideHelper.renameFile('README.md', 'READMEZ.txt');
|
2021-02-18 13:10:41 -05:00
|
|
|
await ideHelper.waitForEditorModelChange(editor);
|
|
|
|
await vm.$nextTick();
|
2020-12-01 19:09:45 -05:00
|
|
|
|
|
|
|
expect(statusBar).toHaveText('1:1');
|
|
|
|
expect(statusBar).toHaveText('plaintext');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('persists position after opening then rename', async () => {
|
|
|
|
await ideHelper.openFile('files/js/application.js');
|
2021-02-18 13:10:41 -05:00
|
|
|
await ideHelper.waitForEditorModelChange(editor);
|
2020-12-01 19:09:45 -05:00
|
|
|
await ideHelper.renameFile('README.md', 'READING_RAINBOW.md');
|
|
|
|
await ideHelper.openFile('READING_RAINBOW.md');
|
2021-02-18 13:10:41 -05:00
|
|
|
await ideHelper.waitForEditorModelChange(editor);
|
2020-12-01 19:09:45 -05:00
|
|
|
|
|
|
|
expect(statusBar).toHaveText('4:10');
|
|
|
|
expect(statusBar).toHaveText('markdown');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('persists position after closing', async () => {
|
|
|
|
await ideHelper.closeFile('README.md');
|
|
|
|
await ideHelper.openFile('README.md');
|
2021-02-18 13:10:41 -05:00
|
|
|
await ideHelper.waitForMonacoEditor();
|
|
|
|
await vm.$nextTick();
|
2020-12-01 19:09:45 -05:00
|
|
|
|
|
|
|
expect(statusBar).toHaveText('4:10');
|
|
|
|
expect(statusBar).toHaveText('markdown');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-05-15 17:08:21 -04:00
|
|
|
});
|