diff --git a/cypress.json b/cypress.json index ffc56dfa7..958b04a86 100644 --- a/cypress.json +++ b/cypress.json @@ -1,6 +1,5 @@ { "baseUrl": "http://127.0.0.1:3001/", "defaultCommandTimeout": 15000, - "experimentalFetchPolyfill": true, "video": false } diff --git a/cypress/integration/history.spec.ts b/cypress/integration/history.spec.ts index 19ee9967a..b1859a6e4 100644 --- a/cypress/integration/history.spec.ts +++ b/cypress/integration/history.spec.ts @@ -24,33 +24,66 @@ describe('History', () => { }) describe('Pinning', () => { - beforeEach(() => { - cy.route({ - method: 'PUT', - url: '/api/v2/history/**', - status: 401, - response: {} + describe('working', () => { + beforeEach(() => { + cy.intercept('PUT', '/api/v2/history/features', (req) => { + req.reply(200, req.body) + }) + }) + + it('Cards', () => { + cy.get('div.card') + .should('be.visible') + cy.get('.history-pin.btn') + .first() + .as('pin-button') + cy.get('@pin-button') + .should('not.have.class', 'pinned') + .click() + cy.get('@pin-button') + .should('have.class', 'pinned') + }) + + it('Table', () => { + cy.get('i.fa-table') + .click() + cy.get('.history-pin.btn') + .first() + .as('pin-button') + cy.get('@pin-button') + .should('not.have.class', 'pinned') + .click() + cy.get('@pin-button') + .should('have.class', 'pinned') }) }) - it('Cards', () => { - cy.get('div.card') - .should('be.visible') - cy.get('.fa-thumb-tack') - .first() - .click() - cy.get('.modal-dialog') - .should('be.visible') - }) + describe('failing', () => { + beforeEach(() => { + cy.intercept('PUT', '/api/v2/history/features', { + statusCode: 401 + }) + }) - it('Table', () => { - cy.get('i.fa-table') - .click() - cy.get('.fa-thumb-tack') - .first() - .click() - cy.get('.modal-dialog') - .should('be.visible') + it('Cards', () => { + cy.get('div.card') + .should('be.visible') + cy.get('.fa-thumb-tack') + .first() + .click() + cy.get('.modal-dialog') + .should('be.visible') + }) + + it('Table', () => { + cy.get('i.fa-table') + .click() + cy.get('.fa-thumb-tack') + .first() + .click() + cy.get('.modal-dialog') + .should('be.visible') + }) }) }) }) diff --git a/cypress/integration/profile.spec.ts b/cypress/integration/profile.spec.ts index dd9d7ee8d..14026ed74 100644 --- a/cypress/integration/profile.spec.ts +++ b/cypress/integration/profile.spec.ts @@ -6,29 +6,32 @@ describe('profile page', () => { beforeEach(() => { - cy.route({ + cy.intercept({ url: '/api/v2/tokens', - method: 'GET', - response: [ + method: 'GET' + }, { + body: [ { label: "cypress-App", created: 1601991518 } ] }) - cy.route({ + cy.intercept({ url: '/api/v2/tokens', - method: 'POST', - response: { + method: 'POST' + }, { + body: { label: 'cypress', secret: 'c-y-p-r-e-s-s', created: Date.now() } }) - cy.route({ + cy.intercept({ url: '/api/v2/tokens/1601991518', - method: 'DELETE', - response: [] + method: 'DELETE' + }, { + body: [] }) cy.visit('/profile') }) diff --git a/cypress/support/config.ts b/cypress/support/config.ts index 5dd2d6467..3398d8037 100644 --- a/cypress/support/config.ts +++ b/cypress/support/config.ts @@ -15,10 +15,9 @@ export const branding = { } beforeEach(() => { - cy.server() - cy.route({ - url: '/api/v2/config', - response: { + cy.intercept('/api/v2/config', { + statusCode: 200, + body: { allowAnonymous: true, authProviders: { facebook: true, diff --git a/src/components/history-page/history-page.tsx b/src/components/history-page/history-page.tsx index 409c0e6c4..fad408a15 100644 --- a/src/components/history-page/history-page.tsx +++ b/src/components/history-page/history-page.tsx @@ -153,21 +153,25 @@ export const HistoryPage: React.FC = () => { }) }) } else if (location === HistoryEntryOrigin.REMOTE) { - const entry = remoteHistoryEntries.find(entry => entry.id === entryId) - if (!entry) { + const foundEntry = remoteHistoryEntries.find(entry => entry.id === entryId) + if (!foundEntry) { setError('notFoundEntry') return } - entry.pinned = !entry.pinned - updateHistoryEntry(entryId, entry) - .then(() => setRemoteHistoryEntries((entries) => { - return entries.map((entry) => { - if (entry.id === entryId) { - entry.pinned = !entry.pinned - } - return entry - }) - })) + const changedEntry = { + ...foundEntry, + pinned: !foundEntry.pinned + } + updateHistoryEntry(entryId, changedEntry) + .then(() => setRemoteHistoryEntries((entries) => ( + entries.map((entry) => { + if (entry.id === entryId) { + entry.pinned = !entry.pinned + } + return entry + }) + ) + )) .catch(() => setError('updateEntry')) } }, [remoteHistoryEntries])