displayNameForUserTests.js 2.2 KB

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