displayNameForUserTests.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. import { expect } from 'chai'
  13. import displayNameForUser from '../../../../../frontend/js/ide/history/util/displayNameForUser'
  14. export default describe('displayNameForUser', function() {
  15. beforeEach(function() {
  16. return (window.user = { id: 42 })
  17. })
  18. it("should return 'Anonymous' with no user", function() {
  19. return expect(displayNameForUser(null)).to.equal('Anonymous')
  20. })
  21. it("should return 'you' when the user has the same id as the window", function() {
  22. return expect(
  23. displayNameForUser({
  24. id: window.user.id,
  25. email: 'james.allen@overleaf.com',
  26. first_name: 'James',
  27. last_name: 'Allen'
  28. })
  29. ).to.equal('you')
  30. })
  31. it('should return the first_name and last_name when present', function() {
  32. return expect(
  33. displayNameForUser({
  34. id: window.user.id + 1,
  35. email: 'james.allen@overleaf.com',
  36. first_name: 'James',
  37. last_name: 'Allen'
  38. })
  39. ).to.equal('James Allen')
  40. })
  41. it('should return only the firstAname if no last_name', function() {
  42. return expect(
  43. displayNameForUser({
  44. id: window.user.id + 1,
  45. email: 'james.allen@overleaf.com',
  46. first_name: 'James',
  47. last_name: ''
  48. })
  49. ).to.equal('James')
  50. })
  51. it('should return the email username if there are no names', function() {
  52. return expect(
  53. displayNameForUser({
  54. id: window.user.id + 1,
  55. email: 'james.allen@overleaf.com',
  56. first_name: '',
  57. last_name: ''
  58. })
  59. ).to.equal('james.allen')
  60. })
  61. it("should return the '?' if it has nothing", function() {
  62. return expect(
  63. displayNameForUser({
  64. id: window.user.id + 1,
  65. email: '',
  66. first_name: '',
  67. last_name: ''
  68. })
  69. ).to.equal('?')
  70. })
  71. })