pixelia.test.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. const { eq, ok } = require('../../helpers/assert');
  2. const { makeNetwork, makePeer } = require('../../helpers/setup');
  3. describe('pixelia: paint pixel', (t) => {
  4. t('A paints a pixel', async () => {
  5. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  6. await A.use('pixelia').paintPixel(10, 20, '#ff0000');
  7. const canvas = await A.use('pixelia').listPixels();
  8. ok(canvas.length >= 1);
  9. });
  10. t('A repaints pixel (replaces previous)', async () => {
  11. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  12. await A.use('pixelia').paintPixel(5, 5, '#00ff00');
  13. await A.use('pixelia').paintPixel(5, 5, '#0000ff');
  14. const canvas = await A.use('pixelia').listPixels();
  15. ok(Array.isArray(canvas));
  16. const greens = canvas.filter(p => p.color === '#00ff00');
  17. eq(greens.length, 0, 'old color tombstoned');
  18. });
  19. t('B (other user) sees A pixel in canvas', async () => {
  20. const net = makeNetwork(); const A = makePeer(net); const B = makePeer(net); A.setActor();
  21. await A.use('pixelia').paintPixel(1, 1, '#ffffff');
  22. B.setActor();
  23. const canvas = await B.use('pixelia').listPixels();
  24. ok(Array.isArray(canvas));
  25. ok(canvas.length >= 1);
  26. });
  27. });