debian-mirror-gitlab/spec/frontend_integration/ide/ide_integration_spec.js

105 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2021-01-03 14:25:43 +05:30
import { waitForText } from 'helpers/wait_for_text';
import waitForPromises from 'helpers/wait_for_promises';
2020-10-24 23:57:45 +05:30
import { useOverclockTimers } from 'test_helpers/utils/overclock_timers';
2021-01-03 14:25:43 +05:30
import { createCommitId } from 'test_helpers/factories/commit_id';
2020-05-24 23:13:21 +05:30
import { initIde } from '~/ide';
2020-10-24 23:57:45 +05:30
import extendStore from '~/ide/stores/extend';
2021-01-03 14:25:43 +05:30
import * as ideHelper from './ide_helper';
2020-10-24 23:57:45 +05:30
const TEST_DATASET = {
emptyStateSvgPath: '/test/empty_state.svg',
noChangesStateSvgPath: '/test/no_changes_state.svg',
committedStateSvgPath: '/test/committed_state.svg',
pipelinesEmptyStateSvgPath: '/test/pipelines_empty_state.svg',
promotionSvgPath: '/test/promotion.svg',
ciHelpPagePath: '/test/ci_help_page',
webIDEHelpPagePath: '/test/web_ide_help_page',
clientsidePreviewEnabled: 'true',
renderWhitespaceInCode: 'false',
codesandboxBundlerUrl: 'test/codesandbox_bundler',
};
2020-05-24 23:13:21 +05:30
describe('WebIDE', () => {
2020-10-24 23:57:45 +05:30
useOverclockTimers();
2020-05-24 23:13:21 +05:30
let vm;
let root;
beforeEach(() => {
root = document.createElement('div');
2020-10-24 23:57:45 +05:30
document.body.appendChild(root);
2020-05-24 23:13:21 +05:30
2020-10-24 23:57:45 +05:30
global.jsdom.reconfigure({
url: `${TEST_HOST}/-/ide/project/gitlab-test/lorem-ipsum`,
2020-05-24 23:13:21 +05:30
});
});
afterEach(() => {
vm.$destroy();
vm = null;
2020-10-24 23:57:45 +05:30
root.remove();
2020-05-24 23:13:21 +05:30
});
const createComponent = () => {
const el = document.createElement('div');
2020-10-24 23:57:45 +05:30
Object.assign(el.dataset, TEST_DATASET);
2020-05-24 23:13:21 +05:30
root.appendChild(el);
2020-10-24 23:57:45 +05:30
vm = initIde(el, { extendStore });
2020-05-24 23:13:21 +05:30
};
it('runs', () => {
createComponent();
2020-10-24 23:57:45 +05:30
expect(root).toMatchSnapshot();
2020-05-24 23:13:21 +05:30
});
2021-01-03 14:25:43 +05:30
it('user commits changes', async () => {
createComponent();
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',
},
],
});
});
it('user adds file that starts with +', async () => {
createComponent();
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'));
expect(tabs.map(x => x.textContent.trim())).toEqual(['+test']);
});
2020-05-24 23:13:21 +05:30
});