|
| 1 | +import { v4 as uuidv4 } from 'uuid'; |
| 2 | + |
| 3 | +import { AuthTestUtils } from '../../support/auth-utils'; |
| 4 | +import { AddPageSelectors, PageIconSelectors, waitForReactUpdate } from '../../support/selectors'; |
| 5 | + |
| 6 | +describe('Page Icon Upload', () => { |
| 7 | + const authUtils = new AuthTestUtils(); |
| 8 | + let testEmail: string; |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + testEmail = `${uuidv4()}@appflowy.io`; |
| 12 | + cy.on('uncaught:exception', (err: Error) => { |
| 13 | + // Ignore common errors that don't affect the test |
| 14 | + if ( |
| 15 | + err.message.includes('No workspace or service found') || |
| 16 | + err.message.includes('View not found') || |
| 17 | + err.message.includes('Failed to fetch dynamically imported module') |
| 18 | + ) { |
| 19 | + return false; |
| 20 | + } |
| 21 | + |
| 22 | + return true; |
| 23 | + }); |
| 24 | + cy.viewport(1280, 720); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should upload page icon image and display after refresh', () => { |
| 28 | + // Set up intercept BEFORE visiting the page |
| 29 | + cy.intercept('PUT', '**/api/file_storage/**').as('fileUpload'); |
| 30 | + |
| 31 | + // 1. Sign in |
| 32 | + cy.visit('/login', { failOnStatusCode: false }); |
| 33 | + authUtils.signInWithTestUrl(testEmail).then(() => { |
| 34 | + cy.url({ timeout: 30000 }).should('include', '/app'); |
| 35 | + waitForReactUpdate(2000); |
| 36 | + }); |
| 37 | + |
| 38 | + // 2. Create a new page |
| 39 | + AddPageSelectors.inlineAddButton().first().click(); |
| 40 | + waitForReactUpdate(500); |
| 41 | + cy.get('[role="menuitem"]').first().click(); // Create Doc |
| 42 | + waitForReactUpdate(1000); |
| 43 | + |
| 44 | + // 3. Click "Add icon" button (force click since it's hidden until hover) |
| 45 | + PageIconSelectors.addIconButton().first().click({ force: true }); |
| 46 | + waitForReactUpdate(500); |
| 47 | + |
| 48 | + // 4. Click Upload tab |
| 49 | + PageIconSelectors.iconPopoverTabUpload().click(); |
| 50 | + waitForReactUpdate(500); |
| 51 | + |
| 52 | + // 5. Upload image via file input (use proper 100x100 test image) |
| 53 | + cy.get('input[type="file"]').attachFile('test-icon.png'); |
| 54 | + |
| 55 | + // Wait for upload to complete |
| 56 | + cy.wait('@fileUpload', { timeout: 15000 }); |
| 57 | + waitForReactUpdate(2000); // Wait for UI to update |
| 58 | + |
| 59 | + // 6. Verify icon changed to uploaded image in sidebar |
| 60 | + // The image should exist and have a src attribute (blob URL or file_storage URL) |
| 61 | + PageIconSelectors.pageIconImage().should('exist'); |
| 62 | + PageIconSelectors.pageIconImage() |
| 63 | + .should('have.attr', 'src') |
| 64 | + .and('not.be.empty') |
| 65 | + .and('match', /^blob:|file_storage/); |
| 66 | + |
| 67 | + // Additional verification: ensure the image is actually loaded and visible |
| 68 | + PageIconSelectors.pageIconImage().should('be.visible'); |
| 69 | + |
| 70 | + // 7. Refresh the page |
| 71 | + cy.reload(); |
| 72 | + waitForReactUpdate(3000); |
| 73 | + |
| 74 | + // 8. Verify uploaded image icon persists after refresh |
| 75 | + // After refresh, the image should be fetched with authentication |
| 76 | + // and displayed as a blob URL |
| 77 | + PageIconSelectors.pageIconImage().should('exist'); |
| 78 | + PageIconSelectors.pageIconImage() |
| 79 | + .should('have.attr', 'src') |
| 80 | + .and('match', /^blob:/); // Should be blob URL from authenticated fetch |
| 81 | + }); |
| 82 | + |
| 83 | + it('should display emoji icon correctly', () => { |
| 84 | + // 1. Sign in |
| 85 | + cy.visit('/login', { failOnStatusCode: false }); |
| 86 | + authUtils.signInWithTestUrl(testEmail).then(() => { |
| 87 | + cy.url({ timeout: 30000 }).should('include', '/app'); |
| 88 | + waitForReactUpdate(2000); |
| 89 | + }); |
| 90 | + |
| 91 | + // 2. Create a new page |
| 92 | + AddPageSelectors.inlineAddButton().first().click(); |
| 93 | + waitForReactUpdate(500); |
| 94 | + cy.get('[role="menuitem"]').first().click(); |
| 95 | + waitForReactUpdate(1000); |
| 96 | + |
| 97 | + // 3. Click "Add icon" button (force click since it's hidden until hover) |
| 98 | + PageIconSelectors.addIconButton().first().click({ force: true }); |
| 99 | + waitForReactUpdate(500); |
| 100 | + |
| 101 | + // 4. Emoji tab should be default, click on an emoji |
| 102 | + PageIconSelectors.iconPopoverTabEmoji().click(); |
| 103 | + waitForReactUpdate(300); |
| 104 | + |
| 105 | + // 5. Click on any emoji in the picker (emojis are in Button components) |
| 106 | + // The emoji picker renders native emojis in buttons with text-xl class |
| 107 | + cy.get('button.text-xl').first().click({ force: true }); |
| 108 | + waitForReactUpdate(500); |
| 109 | + |
| 110 | + // 6. Verify emoji is displayed in sidebar (not an image) |
| 111 | + PageIconSelectors.pageIconImage().should('not.exist'); |
| 112 | + PageIconSelectors.pageIcon().first().should('exist'); |
| 113 | + |
| 114 | + // 7. Refresh the page |
| 115 | + cy.reload(); |
| 116 | + waitForReactUpdate(2000); |
| 117 | + |
| 118 | + // 8. Verify emoji icon persists after refresh (not an image) |
| 119 | + PageIconSelectors.pageIconImage().should('not.exist'); |
| 120 | + PageIconSelectors.pageIcon().first().should('exist'); |
| 121 | + }); |
| 122 | +}); |
0 commit comments