UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

108 lines 5.41 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } import TeamCentralCardClient from '../client/TeamCentralCardClient'; import UserProfileCardClient from '../client/UserProfileCardClient'; import profiles from './profile-data'; import { reportingLinesData } from './reporting-lines-data'; import { getTimeString, getWeekday, random } from './util'; export default function getMockProfileClient(BaseProfileClient, modifyResponse) { var MockUserClient = /*#__PURE__*/function (_UserProfileCardClien) { function MockUserClient() { _classCallCheck(this, MockUserClient); return _callSuper(this, MockUserClient, arguments); } _inherits(MockUserClient, _UserProfileCardClien); return _createClass(MockUserClient, [{ key: "makeRequest", value: function makeRequest(cloudId, userId) { var timeout = random(1500) + 500; var matchError = userId.match(/^error:([0-9a-zA-Z\-]+)$/); var error = matchError && matchError[1]; return new Promise(function (resolve, reject) { setTimeout(function () { if (error) { return reject({ reason: error }); } var userIdAsIndex = parseInt(userId, 10); var profile = profiles[userIdAsIndex] || profiles[0]; if (!profile) { return reject({ reason: 'default' }); } var weekday = getWeekday(); var data = _objectSpread({}, profile); data.remoteTimeString = getTimeString(); data.remoteWeekdayIndex = weekday.index; data.remoteWeekdayString = weekday.string; return resolve(modifyResponse(data)); }, timeout); }); } }]); }(UserProfileCardClient); var MockTeamCentralClient = /*#__PURE__*/function (_TeamCentralCardClien) { function MockTeamCentralClient() { _classCallCheck(this, MockTeamCentralClient); return _callSuper(this, MockTeamCentralClient, arguments); } _inherits(MockTeamCentralClient, _TeamCentralCardClien); return _createClass(MockTeamCentralClient, [{ key: "preloadOrgId", value: function preloadOrgId() { return Promise.resolve('mock-org-id'); } }, { key: "preloadWorkspaceExistsWithType", value: function preloadWorkspaceExistsWithType() { return Promise.resolve('mock-workspace-exists-with-type'); } }, { key: "createOrgContainsAnyWorkspacePromise", value: function createOrgContainsAnyWorkspacePromise(config) { return Promise.resolve(true); } }, { key: "makeRequest", value: function makeRequest(userId) { var timeout = random(1500) + 500; var matchError = userId.match(/^error:([0-9a-zA-Z\-]+)$/); var error = matchError && matchError[1]; return new Promise(function (resolve, reject) { setTimeout(function () { if (error) { return reject({ reason: error }); } return resolve(reportingLinesData); }, timeout); }); } }]); }(TeamCentralCardClient); return /*#__PURE__*/function (_BaseProfileClient) { function MockProfileClient(options) { var clients = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, MockProfileClient); return _callSuper(this, MockProfileClient, [options, _objectSpread({ userClient: new MockUserClient(options), teamCentralClient: new MockTeamCentralClient(_objectSpread(_objectSpread({}, options), {}, { gatewayGraphqlUrl: 'defaultGatewayGraphqlUrl' })) }, clients)]); } _inherits(MockProfileClient, _BaseProfileClient); return _createClass(MockProfileClient); }(BaseProfileClient); }