|
| 1 | +describe('History', () => { |
| 2 | + it('should display "history", open the flyout and display messages when clicked', () => { |
| 3 | + cy.visit('/simulator?target=v3.html', { |
| 4 | + onBeforeLoad(win) { |
| 5 | + Object.defineProperty(win.navigator, 'language', { value: 'en-US' }); |
| 6 | + }, |
| 7 | + }) |
| 8 | + .get('[data-testid=component-name]') |
| 9 | + .should('be.visible'); |
| 10 | + const now = new Date(); |
| 11 | + const formattedHourMinute = now.toLocaleTimeString('en-US').split(':').slice(0, 2).join(':'); |
| 12 | + |
| 13 | + const formattedDate = now.toLocaleDateString('en-US', { |
| 14 | + year: 'numeric', |
| 15 | + month: '2-digit', |
| 16 | + day: '2-digit', |
| 17 | + }); |
| 18 | + |
| 19 | + // Setup |
| 20 | + cy.get('[data-testid=component-name]').contains('model-no-render').click(); |
| 21 | + |
| 22 | + cy.get('[data-testid=history-flyout]').contains('History').should('be.visible'); |
| 23 | + |
| 24 | + cy.get('[data-testid=history-flyout]').contains('History').click(); |
| 25 | + |
| 26 | + // Message is visible and displays information as expected |
| 27 | + cy.get('[data-testid=history-message-0]').should('be.visible'); |
| 28 | + cy.get('[data-testid=history-message-0]').contains('+0ms').should('be.visible'); |
| 29 | + cy.get('[data-testid=history-message-0]').contains(formattedHourMinute).should('be.visible'); |
| 30 | + |
| 31 | + cy.iframe('#target').find('[data-testid=model-no-render]').should('be.visible').clear(); |
| 32 | + |
| 33 | + cy.get('[data-testid=history-flyout] li').should('have.length', 2); |
| 34 | + |
| 35 | + cy.iframe('#target') |
| 36 | + .find('[data-testid=model-no-render]') |
| 37 | + .should('be.visible') |
| 38 | + .type('new', { delay: 20 }); |
| 39 | + |
| 40 | + cy.get('[data-testid=history-flyout] li').should('have.length', 5); |
| 41 | + |
| 42 | + // selecting a snapshot displays right info |
| 43 | + cy.get('[data-testid=history-message-3]').click(); |
| 44 | + |
| 45 | + cy.get('[data-testid=attr-list-header]') |
| 46 | + .should('be.visible') |
| 47 | + .should('contain.text', formattedDate) |
| 48 | + .should('contain.text', formattedHourMinute); |
| 49 | + cy.get('[data-testid=data-property-name-text]') |
| 50 | + .should('be.visible') |
| 51 | + .should('have.text', 'text'); |
| 52 | + cy.get('[data-testid=data-property-value-text]') |
| 53 | + .should('be.visible') |
| 54 | + .should('have.text', '"ne"'); |
| 55 | + |
| 56 | + // unselecting a snapshot reverts |
| 57 | + cy.get('[data-testid=history-message-3]').click(); |
| 58 | + |
| 59 | + cy.get('[data-testid=data-property-name-text]') |
| 60 | + .should('be.visible') |
| 61 | + .should('have.text', 'text'); |
| 62 | + cy.get('[data-testid=data-property-value-text]') |
| 63 | + .should('be.visible') |
| 64 | + .should('have.text', '"new"'); |
| 65 | + |
| 66 | + cy.get('[data-testid=apply-snapshot]').should('not.exist'); |
| 67 | + |
| 68 | + // Apply snapshot |
| 69 | + cy.get('[data-testid=history-message-3]').click(); |
| 70 | + |
| 71 | + cy.get('[data-testid=apply-snapshot]').should('be.visible'); |
| 72 | + cy.get('[data-testid=apply-snapshot]').click(); |
| 73 | + |
| 74 | + cy.iframe('#target') |
| 75 | + .find('[data-testid=model-no-render]') |
| 76 | + .should('be.visible') |
| 77 | + .should('have.value', 'ne'); |
| 78 | + }); |
| 79 | + |
| 80 | + it('pinning a field works across messages', () => { |
| 81 | + cy.visit('/simulator?target=v3.html').get('[data-testid=component-name]').should('be.visible'); |
| 82 | + |
| 83 | + // Setup |
| 84 | + cy.get('[data-testid=component-name]').contains('model-no-render').click(); |
| 85 | + |
| 86 | + cy.get('[data-testid=history-flyout]').contains('History').should('be.visible'); |
| 87 | + |
| 88 | + cy.get('[data-testid=history-flyout]').contains('History').click(); |
| 89 | + |
| 90 | + cy.iframe('#target') |
| 91 | + .find('[data-testid=nested-model-no-render]') |
| 92 | + .should('be.visible') |
| 93 | + .clear() |
| 94 | + .type('new', { delay: 0 }); |
| 95 | + |
| 96 | + cy.get('[data-testid=history-flyout] li').should('have.length', 3); |
| 97 | + |
| 98 | + // Setup the "pin" |
| 99 | + cy.get('[data-testid=history-message-0]').click(); |
| 100 | + |
| 101 | + cy.get('[data-testid=data-property-name-model]').click(); |
| 102 | + cy.get('[data-testid=data-property-name-nested') |
| 103 | + .should('be.visible') |
| 104 | + .should('have.text', 'nested'); |
| 105 | + cy.get('[data-testid=data-property-value-nested') |
| 106 | + .should('be.visible') |
| 107 | + .should('have.text', '"nested-initial"'); |
| 108 | + |
| 109 | + cy.get('[data-testid="pin-model.nested"]').should('be.visible').should('have.text', '(pin)'); |
| 110 | + cy.get('[data-testid="pin-model.nested"]').click(); |
| 111 | + |
| 112 | + cy.get('[data-testid=data-property-name-text').should('not.exist'); |
| 113 | + cy.get('[data-testid=apply-snapshot]').should('be.visible'); |
| 114 | + |
| 115 | + cy.get('[data-testid=history-message-1]').click(); |
| 116 | + cy.get('[data-testid=data-property-name-text').should('not.exist'); |
| 117 | + cy.get('[data-testid=data-property-name-nested') |
| 118 | + .should('be.visible') |
| 119 | + .should('have.text', 'nested'); |
| 120 | + cy.get('[data-testid=data-property-value-nested') |
| 121 | + .should('be.visible') |
| 122 | + .should('have.text', '""'); |
| 123 | + |
| 124 | + cy.get('[data-testid="unpin-model.nested"]').click(); |
| 125 | + |
| 126 | + cy.get('[data-testid=data-property-name-text').should('be.visible'); |
| 127 | + }); |
| 128 | + |
| 129 | + it('opening attributes syncs across live component data and messages', () => { |
| 130 | + cy.visit('/simulator?target=v3.html').get('[data-testid=component-name]').should('be.visible'); |
| 131 | + |
| 132 | + // Setup |
| 133 | + cy.get('[data-testid=component-name]').contains('model-no-render').click(); |
| 134 | + |
| 135 | + cy.get('[data-testid=history-flyout]').contains('History').should('be.visible'); |
| 136 | + |
| 137 | + cy.get('[data-testid=history-flyout]').contains('History').click(); |
| 138 | + |
| 139 | + cy.iframe('#target') |
| 140 | + .find('[data-testid=nested-model-no-render]') |
| 141 | + .should('be.visible') |
| 142 | + .clear() |
| 143 | + .type('new', { delay: 0 }); |
| 144 | + |
| 145 | + cy.get('[data-testid=history-flyout] li').should('have.length', 3); |
| 146 | + |
| 147 | + // open attr in "component live data view" |
| 148 | + cy.get('[data-testid=data-property-name-model]').click(); |
| 149 | + cy.get('[data-testid=data-property-name-nested') |
| 150 | + .should('be.visible') |
| 151 | + .should('have.text', 'nested'); |
| 152 | + |
| 153 | + // select a message |
| 154 | + cy.get('[data-testid=history-message-2]').click(); |
| 155 | + |
| 156 | + cy.get('[data-testid=data-property-name-nested') |
| 157 | + .should('be.visible') |
| 158 | + .should('have.text', 'nested'); |
| 159 | + // opened attr is maintained |
| 160 | + cy.get('[data-testid=data-property-value-nested') |
| 161 | + .should('be.visible') |
| 162 | + .should('have.text', '"new"'); |
| 163 | + |
| 164 | + // close attr from "message view" |
| 165 | + cy.get('[data-testid=data-property-name-model').click(); |
| 166 | + cy.get('[data-testid=data-property-name-nested').should('not.exist'); |
| 167 | + |
| 168 | + // TODO: syncing message "open" state back to "component view" doesn't work |
| 169 | + // would need refactoring to maintain accurate "openAttrs" globally for messages |
| 170 | + // and component. |
| 171 | + |
| 172 | + // // unselect message |
| 173 | + // cy.get('[data-testid=history-message-2]').click(); |
| 174 | + |
| 175 | + // // should be "live data view" |
| 176 | + // cy.get('[data-testid=apply-snapshot]').should('not.exist'); |
| 177 | + // // close should have synced |
| 178 | + // cy.get('[data-testid=data-property-name-nested').should('not.exist'); |
| 179 | + }); |
| 180 | +}); |
0 commit comments