displayNameForUserTests.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* eslint-disable
  2. no-return-assign,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  10. */
  11. import { expect } from 'chai'
  12. import displayNameForUser from '../../../../../frontend/js/ide/history/util/displayNameForUser'
  13. export default describe('displayNameForUser', function () {
  14. beforeEach(function () {
  15. return (window.user = { id: 42 })
  16. })
  17. it("should return 'Anonymous' with no user", function () {
  18. return expect(displayNameForUser(null)).to.equal('Anonymous')
  19. })
  20. it("should return 'you' when the user has the same id as the window", function () {
  21. return expect(
  22. displayNameForUser({
  23. id: window.user.id,
  24. email: 'james.allen@overleaf.com',
  25. first_name: 'James',
  26. last_name: 'Allen',
  27. })
  28. ).to.equal('you')
  29. })
  30. it('should return the first_name and last_name when present', function () {
  31. return expect(
  32. displayNameForUser({
  33. id: window.user.id + 1,
  34. email: 'james.allen@overleaf.com',
  35. first_name: 'James',
  36. last_name: 'Allen',
  37. })
  38. ).to.equal('James Allen')
  39. })
  40. it('should return only the firstAname if no last_name', function () {
  41. return expect(
  42. displayNameForUser({
  43. id: window.user.id + 1,
  44. email: 'james.allen@overleaf.com',
  45. first_name: 'James',
  46. last_name: '',
  47. })
  48. ).to.equal('James')
  49. })
  50. it('should return the email username if there are no names', function () {
  51. return expect(
  52. displayNameForUser({
  53. id: window.user.id + 1,
  54. email: 'james.allen@overleaf.com',
  55. first_name: '',
  56. last_name: '',
  57. })
  58. ).to.equal('james.allen')
  59. })
  60. it("should return the '?' if it has nothing", function () {
  61. return expect(
  62. displayNameForUser({
  63. id: window.user.id + 1,
  64. email: '',
  65. first_name: '',
  66. last_name: '',
  67. })
  68. ).to.equal('?')
  69. })
  70. })