|
| 1 | +import { execa } from 'execa'; |
| 2 | +import fixturify from 'fixturify'; |
| 3 | +import { describe, expect, it } from 'vitest'; |
| 4 | + |
| 5 | +import { makeFolder } from '../helpers.js'; |
| 6 | + |
| 7 | +describe('add command tests', () => { |
| 8 | + it('adds a new slide in an empty slides folder', async () => { |
| 9 | + const { cwd } = await makeFolder({ |
| 10 | + files: { |
| 11 | + slides: {}, |
| 12 | + }, |
| 13 | + }); |
| 14 | + |
| 15 | + const result = await execa({ |
| 16 | + cwd, |
| 17 | + })`${process.cwd()}/bin/auto-reveal add`; |
| 18 | + |
| 19 | + const fixtures = fixturify.readSync(cwd); |
| 20 | + |
| 21 | + expect(result.stdout).toStrictEqual( |
| 22 | + '\nauto-reveal\n\n Created ./slides/000.md\n Hint: Create a vertical slide by adding "---" to that file.\n', |
| 23 | + ); |
| 24 | + expect(result.exitCode).to.equal(0); |
| 25 | + expect(fixtures).toStrictEqual({ |
| 26 | + slides: { |
| 27 | + '000.md': 'Note:\n\nThis note is only visible to the presenter.\n', |
| 28 | + }, |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + it('adds a new slide without a title', async () => { |
| 33 | + const { cwd } = await makeFolder({ |
| 34 | + files: { |
| 35 | + slides: { |
| 36 | + '000.md': '# Slide 1', |
| 37 | + }, |
| 38 | + }, |
| 39 | + }); |
| 40 | + |
| 41 | + const result = await execa({ |
| 42 | + cwd, |
| 43 | + })`${process.cwd()}/bin/auto-reveal add`; |
| 44 | + |
| 45 | + const fixtures = fixturify.readSync(cwd); |
| 46 | + |
| 47 | + expect(result.stdout).toStrictEqual( |
| 48 | + '\nauto-reveal\n\n Created ./slides/010.md\n Hint: Create a vertical slide by adding "---" to that file.\n', |
| 49 | + ); |
| 50 | + expect(result.exitCode).to.equal(0); |
| 51 | + expect(fixtures).toStrictEqual({ |
| 52 | + slides: { |
| 53 | + '000.md': '# Slide 1', |
| 54 | + '010.md': 'Note:\n\nThis note is only visible to the presenter.\n', |
| 55 | + }, |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + it('adds a new slide with a custom increment', async () => { |
| 60 | + const { cwd } = await makeFolder({ |
| 61 | + files: { |
| 62 | + slides: { |
| 63 | + '003.md': '# Slide 1', |
| 64 | + }, |
| 65 | + }, |
| 66 | + }); |
| 67 | + |
| 68 | + const result1 = await execa({ |
| 69 | + cwd, |
| 70 | + })`${process.cwd()}/bin/auto-reveal add -i 5`; |
| 71 | + |
| 72 | + expect(result1.stdout).toStrictEqual( |
| 73 | + '\nauto-reveal\n\n Created ./slides/010.md\n Hint: Create a vertical slide by adding "---" to that file.\n', |
| 74 | + ); |
| 75 | + expect(result1.exitCode).to.equal(0); |
| 76 | + |
| 77 | + const result2 = await execa({ |
| 78 | + cwd, |
| 79 | + })`${process.cwd()}/bin/auto-reveal add -i 5`; |
| 80 | + |
| 81 | + expect(result2.stdout).toStrictEqual( |
| 82 | + '\nauto-reveal\n\n Created ./slides/015.md\n Hint: Create a vertical slide by adding "---" to that file.\n', |
| 83 | + ); |
| 84 | + expect(result2.exitCode).to.equal(0); |
| 85 | + |
| 86 | + const fixtures = fixturify.readSync(cwd); |
| 87 | + expect(fixtures).toStrictEqual({ |
| 88 | + slides: { |
| 89 | + '003.md': '# Slide 1', |
| 90 | + '010.md': 'Note:\n\nThis note is only visible to the presenter.\n', |
| 91 | + '015.md': 'Note:\n\nThis note is only visible to the presenter.\n', |
| 92 | + }, |
| 93 | + }); |
| 94 | + }); |
| 95 | + |
| 96 | + it('adds a new slide with a title', async () => { |
| 97 | + const { cwd } = await makeFolder({ |
| 98 | + files: { |
| 99 | + slides: { |
| 100 | + '000.md': '# Slide 1', |
| 101 | + }, |
| 102 | + }, |
| 103 | + }); |
| 104 | + |
| 105 | + const result = await execa({ |
| 106 | + cwd, |
| 107 | + })`${process.cwd()}/bin/auto-reveal add 👋 Hallöle`; |
| 108 | + |
| 109 | + const fixtures = fixturify.readSync(cwd); |
| 110 | + |
| 111 | + expect(result.stdout).toStrictEqual( |
| 112 | + '\nauto-reveal\n\n Created ./slides/010-hallole.md\n Hint: Create a vertical slide by adding "---" to that file.\n', |
| 113 | + ); |
| 114 | + expect(result.exitCode).to.equal(0); |
| 115 | + expect(fixtures).toStrictEqual({ |
| 116 | + slides: { |
| 117 | + '000.md': '# Slide 1', |
| 118 | + '010-hallole.md': |
| 119 | + '# 👋 Hallöle\n\nNote:\n\nThis note is only visible to the presenter.\n', |
| 120 | + }, |
| 121 | + }); |
| 122 | + }); |
| 123 | +}); |
0 commit comments