diff options
Diffstat (limited to 'spec/frontend_integration/test_helpers')
13 files changed, 34 insertions, 22 deletions
diff --git a/spec/frontend_integration/test_helpers/factories/commit_id.js b/spec/frontend_integration/test_helpers/factories/commit_id.js index 9fa278c9dde..815da19a2d9 100644 --- a/spec/frontend_integration/test_helpers/factories/commit_id.js +++ b/spec/frontend_integration/test_helpers/factories/commit_id.js @@ -1,7 +1,5 @@ const COMMIT_ID_LENGTH = 40; -const DEFAULT_COMMIT_ID = Array(COMMIT_ID_LENGTH) - .fill('0') - .join(''); +const DEFAULT_COMMIT_ID = Array(COMMIT_ID_LENGTH).fill('0').join(''); export const createCommitId = (index = 0) => `${index}${DEFAULT_COMMIT_ID}`.substr(0, COMMIT_ID_LENGTH); diff --git a/spec/frontend_integration/test_helpers/fixtures.js b/spec/frontend_integration/test_helpers/fixtures.js index 46946ed71f2..fde3fd8cb63 100644 --- a/spec/frontend_integration/test_helpers/fixtures.js +++ b/spec/frontend_integration/test_helpers/fixtures.js @@ -10,9 +10,9 @@ const createFactoryWithDefault = (fn, defaultValue) => () => { }; const factory = { - json: fn => createFactoryWithDefault(fn, { error: 'fixture not found' }), - text: fn => createFactoryWithDefault(fn, 'Hello world\nHow are you today?\n'), - binary: fn => createFactoryWithDefault(fn, ''), + json: (fn) => createFactoryWithDefault(fn, { error: 'fixture not found' }), + text: (fn) => createFactoryWithDefault(fn, 'Hello world\nHow are you today?\n'), + binary: (fn) => createFactoryWithDefault(fn, ''), }; export const getProject = factory.json(() => require('test_fixtures/api/projects/get.json')); diff --git a/spec/frontend_integration/test_helpers/mock_server/index.js b/spec/frontend_integration/test_helpers/mock_server/index.js index 6f090565635..2aebdefaafb 100644 --- a/spec/frontend_integration/test_helpers/mock_server/index.js +++ b/spec/frontend_integration/test_helpers/mock_server/index.js @@ -26,7 +26,7 @@ export const createMockServerOptions = () => ({ }, seeds(schema) { schema.db.loadData({ - files: getRepositoryFiles().map(path => ({ path })), + files: getRepositoryFiles().map((path) => ({ path })), projects: [getProject(), getEmptyProject()], branches: [getBranch()], mergeRequests: getMergeRequests(), diff --git a/spec/frontend_integration/test_helpers/mock_server/routes/404.js b/spec/frontend_integration/test_helpers/mock_server/routes/404.js index 9e08016577b..bc8edba927e 100644 --- a/spec/frontend_integration/test_helpers/mock_server/routes/404.js +++ b/spec/frontend_integration/test_helpers/mock_server/routes/404.js @@ -1,5 +1,5 @@ -export default server => { - ['get', 'post', 'put', 'delete', 'patch'].forEach(method => { +export default (server) => { + ['get', 'post', 'put', 'delete', 'patch'].forEach((method) => { server[method]('*', () => { return new Response(404); }); diff --git a/spec/frontend_integration/test_helpers/mock_server/routes/ci.js b/spec/frontend_integration/test_helpers/mock_server/routes/ci.js index 83951f09c56..6f1593a2cf9 100644 --- a/spec/frontend_integration/test_helpers/mock_server/routes/ci.js +++ b/spec/frontend_integration/test_helpers/mock_server/routes/ci.js @@ -1,6 +1,6 @@ import { getPipelinesEmptyResponse } from 'test_helpers/fixtures'; -export default server => { +export default (server) => { server.get('*/commit/:id/pipelines', () => { return getPipelinesEmptyResponse(); }); diff --git a/spec/frontend_integration/test_helpers/mock_server/routes/graphql.js b/spec/frontend_integration/test_helpers/mock_server/routes/graphql.js index ebb5415ba97..a22763dcb45 100644 --- a/spec/frontend_integration/test_helpers/mock_server/routes/graphql.js +++ b/spec/frontend_integration/test_helpers/mock_server/routes/graphql.js @@ -1,6 +1,6 @@ import { graphqlQuery } from '../graphql'; -export default server => { +export default (server) => { server.post('/api/graphql', (schema, request) => { const batches = JSON.parse(request.requestBody); diff --git a/spec/frontend_integration/test_helpers/mock_server/routes/index.js b/spec/frontend_integration/test_helpers/mock_server/routes/index.js index eea196b5158..e30fecf2f06 100644 --- a/spec/frontend_integration/test_helpers/mock_server/routes/index.js +++ b/spec/frontend_integration/test_helpers/mock_server/routes/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -export default server => { +export default (server) => { [ require('./graphql'), require('./projects'), diff --git a/spec/frontend_integration/test_helpers/mock_server/routes/projects.js b/spec/frontend_integration/test_helpers/mock_server/routes/projects.js index f4d8ce4b23d..de37aa98eee 100644 --- a/spec/frontend_integration/test_helpers/mock_server/routes/projects.js +++ b/spec/frontend_integration/test_helpers/mock_server/routes/projects.js @@ -1,6 +1,6 @@ import { withKeys } from 'test_helpers/utils/obj'; -export default server => { +export default (server) => { server.get('/api/v4/projects/:id', (schema, request) => { const { id } = request.params; diff --git a/spec/frontend_integration/test_helpers/mock_server/routes/repository.js b/spec/frontend_integration/test_helpers/mock_server/routes/repository.js index 166c0cc32db..ba36463cad8 100644 --- a/spec/frontend_integration/test_helpers/mock_server/routes/repository.js +++ b/spec/frontend_integration/test_helpers/mock_server/routes/repository.js @@ -1,9 +1,9 @@ import { createNewCommit, createCommitIdGenerator } from 'test_helpers/factories'; -export default server => { +export default (server) => { const commitIdGenerator = createCommitIdGenerator(); - server.get('/api/v4/projects/:id/repository/branches', schema => { + server.get('/api/v4/projects/:id/repository/branches', (schema) => { return schema.db.branches; }); @@ -15,7 +15,7 @@ export default server => { return branch.attrs; }); - server.get('*/-/files/:id', schema => { + server.get('*/-/files/:id', (schema) => { return schema.db.files.map(({ path }) => path); }); @@ -37,13 +37,23 @@ export default server => { ); const branch = schema.branches.findBy({ name: branchName }); + const prevCommit = branch + ? branch.attrs.commit + : schema.branches.findBy({ name: 'master' }).attrs.commit; const commit = { - ...createNewCommit({ id: commitIdGenerator.next(), message }, branch.attrs.commit), + ...createNewCommit({ id: commitIdGenerator.next(), message }, prevCommit), __actions: actions, }; - branch.update({ commit }); + if (branch) { + branch.update({ commit }); + } else { + schema.branches.create({ + name: branchName, + commit, + }); + } return commit; }); diff --git a/spec/frontend_integration/test_helpers/setup/index.js b/spec/frontend_integration/test_helpers/setup/index.js index ba1d256e16e..946ccbec00c 100644 --- a/spec/frontend_integration/test_helpers/setup/index.js +++ b/spec/frontend_integration/test_helpers/setup/index.js @@ -3,3 +3,4 @@ import './setup_globals'; import './setup_axios'; import './setup_serializers'; import './setup_mock_server'; +import './setup_testing_library'; diff --git a/spec/frontend_integration/test_helpers/setup/setup_testing_library.js b/spec/frontend_integration/test_helpers/setup/setup_testing_library.js new file mode 100644 index 00000000000..5081b1c3b62 --- /dev/null +++ b/spec/frontend_integration/test_helpers/setup/setup_testing_library.js @@ -0,0 +1,3 @@ +import { configure } from '@testing-library/dom'; + +configure({ asyncUtilTimeout: 10000 }); diff --git a/spec/frontend_integration/test_helpers/snapshot_serializer.js b/spec/frontend_integration/test_helpers/snapshot_serializer.js index 8c4f95a9156..aacd144217f 100644 --- a/spec/frontend_integration/test_helpers/snapshot_serializer.js +++ b/spec/frontend_integration/test_helpers/snapshot_serializer.js @@ -4,7 +4,7 @@ export default { }, print(element, serialize) { element.$_hit = true; - element.querySelectorAll('[style]').forEach(el => { + element.querySelectorAll('[style]').forEach((el) => { el.$_hit = true; if (el.style.display === 'none') { el.textContent = '(jest: contents hidden)'; diff --git a/spec/frontend_integration/test_helpers/utils/obj_spec.js b/spec/frontend_integration/test_helpers/utils/obj_spec.js index 0ad7b4a1a4c..614250ccddc 100644 --- a/spec/frontend_integration/test_helpers/utils/obj_spec.js +++ b/spec/frontend_integration/test_helpers/utils/obj_spec.js @@ -3,9 +3,9 @@ import { withKeys, withValues } from './obj'; describe('frontend_integration/test_helpers/utils/obj', () => { describe('withKeys', () => { it('picks and maps keys', () => { - expect(withKeys({ a: '123', b: 456, c: 'd' }, { b: 'lorem', c: 'ipsum', z: 'zed ' })).toEqual( - { lorem: 456, ipsum: 'd' }, - ); + expect( + withKeys({ a: '123', b: 456, c: 'd' }, { b: 'lorem', c: 'ipsum', z: 'zed ' }), + ).toEqual({ lorem: 456, ipsum: 'd' }); }); }); |