move_file_operation.test.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict'
  2. const { expect } = require('chai')
  3. const ot = require('..')
  4. const File = ot.File
  5. const MoveFileOperation = ot.MoveFileOperation
  6. const Snapshot = ot.Snapshot
  7. describe('MoveFileOperation', function () {
  8. function makeEmptySnapshot() {
  9. return new Snapshot()
  10. }
  11. function makeOneFileSnapshot() {
  12. const snapshot = makeEmptySnapshot()
  13. snapshot.addFile('foo', File.fromString('test: foo'))
  14. return snapshot
  15. }
  16. function makeTwoFileSnapshot() {
  17. const snapshot = makeOneFileSnapshot()
  18. snapshot.addFile('bar', File.fromString('test: bar'))
  19. return snapshot
  20. }
  21. it('moves a file over another', function () {
  22. const snapshot = makeOneFileSnapshot()
  23. const operation = new MoveFileOperation('foo', 'bar')
  24. operation.applyTo(snapshot)
  25. expect(snapshot.countFiles()).to.equal(1)
  26. expect(snapshot.getFile('bar').getContent()).to.equal('test: foo')
  27. })
  28. it('moves a file to another pathname', function () {
  29. const snapshot = makeTwoFileSnapshot()
  30. const operation = new MoveFileOperation('foo', 'a')
  31. operation.applyTo(snapshot)
  32. expect(snapshot.countFiles()).to.equal(2)
  33. expect(snapshot.getFile('a').getContent()).to.equal('test: foo')
  34. expect(snapshot.getFile('bar').getContent()).to.equal('test: bar')
  35. })
  36. })