-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(protocol-designer): add migration + load-save e2e tests #5369
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e1f79e5
initial setup
IanLondon 1d5dab8
fix tests, use cy.window, add 1_0_0 mig
IanLondon 6d68641
rearrange fixture files
IanLondon 10ee411
format JSON new fixtures
IanLondon 6eaff86
remove comment
IanLondon 05d65f4
remove console log
IanLondon 0bc1ddc
update fixtures after pauseAction update and v3->v4.0.0 PD version bump
IanLondon d386a26
fix settings test (unrelated but whatevs)
IanLondon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
protocol-designer/cypress/integration/migrations.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import 'cypress-file-upload' | ||
import cloneDeep from 'lodash/cloneDeep' | ||
import { expectDeepEqual } from '../utils' | ||
|
||
describe('Protocol fixtures migrate and match snapshots', () => { | ||
beforeEach(() => { | ||
cy.visit('/') | ||
cy.closeAnnouncementModal() | ||
}) | ||
|
||
const testCases = [ | ||
{ | ||
title: 'preFlexGrandfatheredProtocol 1.0.0 -> 4.0.x, schema 3', | ||
importFixture: | ||
'../../fixtures/protocol/1/preFlexGrandfatheredProtocol.json', | ||
expectedExportFixture: | ||
'../../fixtures/protocol/3/preFlexGrandfatheredProtocolMigratedFromV1_0_0.json', | ||
newLabwareDefsMigrationModal: true, | ||
unusedPipettes: false, | ||
apiUpdateRequiredMigrationModal: false, | ||
genericMigrationModal: false, | ||
}, | ||
{ | ||
title: 'example_1_1_0 -> 4.0.x, schema 3', | ||
importFixture: '../../fixtures/protocol/1/example_1_1_0.json', | ||
expectedExportFixture: | ||
'../../fixtures/protocol/3/example_1_1_0MigratedFromV1_0_0.json', | ||
newLabwareDefsMigrationModal: true, | ||
unusedPipettes: true, | ||
apiUpdateRequiredMigrationModal: false, | ||
genericMigrationModal: false, | ||
}, | ||
{ | ||
title: 'doItAllV3 -> import and re-export should preserve data', | ||
importFixture: '../../fixtures/protocol/3/doItAllV3.json', | ||
expectedExportFixture: '../../fixtures/protocol/3/doItAllV3.json', | ||
newLabwareDefsMigrationModal: false, | ||
unusedPipettes: false, | ||
apiUpdateRequiredMigrationModal: false, | ||
genericMigrationModal: false, | ||
}, | ||
{ | ||
title: 'doItAllV4 -> import and re-export should preserve data', | ||
importFixture: '../../fixtures/protocol/4/doItAllV4.json', | ||
expectedExportFixture: '../../fixtures/protocol/4/doItAllV4.json', | ||
newLabwareDefsMigrationModal: false, | ||
unusedPipettes: false, | ||
apiUpdateRequiredMigrationModal: true, | ||
genericMigrationModal: false, | ||
}, | ||
] | ||
|
||
testCases.forEach( | ||
({ | ||
title, | ||
importFixture, | ||
expectedExportFixture, | ||
newLabwareDefsMigrationModal, | ||
unusedPipettes, | ||
apiUpdateRequiredMigrationModal, | ||
genericMigrationModal, | ||
}) => { | ||
it(title, () => { | ||
cy.fixture(importFixture).then(fileContent => { | ||
// TODO(IL, 2020-04-02): `cy.fixture` always parses .json files, though we want the plain text. | ||
// So we have to use JSON.stringify. See https://github.com/cypress-io/cypress/issues/5395 | ||
// Also, the latest version v4 of cypress-file-upload is too implicit to allow us to | ||
// use the JSON.stringify workaround, so we're stuck on 3.5.3, | ||
// see https://github.com/abramenal/cypress-file-upload/issues/175 | ||
cy.get('input[type=file]').upload({ | ||
fileContent: JSON.stringify(fileContent), | ||
fileName: 'fixture.json', | ||
mimeType: 'application/json', | ||
encoding: 'utf8', | ||
}) | ||
}) | ||
|
||
if (genericMigrationModal) { | ||
cy.get('div') | ||
.contains( | ||
'Your protocol was made in an older version of Protocol Designer' | ||
) | ||
.should('exist') | ||
cy.get('button') | ||
.contains('ok', { matchCase: false }) | ||
.click() | ||
} | ||
|
||
if (newLabwareDefsMigrationModal) { | ||
// close migration announcement modal | ||
cy.get('div') | ||
.contains('Update protocol to use new labware definitions') | ||
.should('exist') | ||
cy.get('button') | ||
.contains('update protocol', { matchCase: false }) | ||
.click() | ||
} | ||
|
||
cy.fixture(expectedExportFixture).then(expectedExportProtocol => { | ||
cy.get('button') | ||
.contains('Export') | ||
.click() | ||
|
||
if (unusedPipettes) { | ||
cy.get('div') | ||
.contains('Unused pipette') | ||
.should('exist') | ||
cy.get('button') | ||
.contains('continue with export', { matchCase: false }) | ||
.click() | ||
} | ||
|
||
if (apiUpdateRequiredMigrationModal) { | ||
cy.get('div') | ||
.contains( | ||
'Robot requirements for running module inclusive JSON protocols' | ||
) | ||
.should('exist') | ||
cy.get('button') | ||
.contains('continue', { matchCase: false }) | ||
.click() | ||
} | ||
|
||
cy.window().then(window => { | ||
const savedFile = cloneDeep(window.__lastSavedFile__) | ||
const expected = cloneDeep(expectedExportProtocol) | ||
|
||
assert.match( | ||
savedFile.designerApplication.version, | ||
/^4\.0\.\d+$/, | ||
'designerApplication.version is 4.0.x' | ||
) | ||
;[savedFile, expected].forEach(f => { | ||
// Homogenize fields we don't want to compare | ||
f.metadata.lastModified = 123 | ||
f.designerApplication.data._internalAppBuildDate = 'Foo Date' | ||
f.designerApplication.version = 'x.x.x' | ||
}) | ||
|
||
expectDeepEqual(savedFile, expected) | ||
}) | ||
}) | ||
}) | ||
} | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import isEqual from 'lodash/isEqual' | ||
import isObject from 'lodash/isObject' | ||
import transform from 'lodash/transform' | ||
|
||
const difference = (object, base) => { | ||
const changes = (object, base) => { | ||
return transform(object, function(result, value, key) { | ||
if (!isEqual(value, base[key])) { | ||
result[key] = | ||
isObject(value) && isObject(base[key]) | ||
? changes(value, base[key]) | ||
: value | ||
} | ||
}) | ||
} | ||
return changes(object, base) | ||
} | ||
|
||
// deepEqual won't always return a diff, Cypress doesn't fully support object diffs :( | ||
// also Cypress doesn't seem to support logging to the console? So throwing the diff as an error instead | ||
export const expectDeepEqual = (a, b) => { | ||
try { | ||
assert.deepEqual(a, b) | ||
} catch (e) { | ||
// visualize undefineds | ||
const replacer = (key, value) => | ||
typeof value === 'undefined' ? '__undefined__' : value | ||
throw Error( | ||
'Expected deep equal. Diff is: ' + | ||
JSON.stringify(difference(a, b), replacer, 4) | ||
) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, really? I was able to log to console in one of my tests, so I'm not sure why it wouldn't work here
Edit: I misunderstood. This makes sense now.