displayNameForUserTests.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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(['ide/history/util/displayNameForUser'], displayNameForUser =>
  13. 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. }))