-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add e2e tests for CTB restarts from file changes
- Loading branch information
1 parent
79f8c92
commit 5ab818b
Showing
21 changed files
with
343 additions
and
118 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -1,95 +1,4 @@ | ||
const { | ||
file: { | ||
providers: { createLocalFileDestinationProvider }, | ||
}, | ||
strapi: { | ||
providers: { createLocalStrapiSourceProvider }, | ||
}, | ||
engine: { createTransferEngine }, | ||
} = require('@strapi/data-transfer'); | ||
const strapiFactory = require('@strapi/strapi'); | ||
const { ALLOWED_CONTENT_TYPES } = require('../constants'); | ||
|
||
/** | ||
* Export the data from a strapi project. | ||
* This script should be run as `node <path-to>/dts-export.js [exportFilePath]` from the | ||
* root directory of a strapi project e.g. `/examples/kitchensink`. Remember to import | ||
* the `with-admin` tar file into the project first because the tests rely on the data. | ||
*/ | ||
const exportData = async () => { | ||
let args = process.argv.slice(2); | ||
|
||
if (args.length !== 1) { | ||
console.error('Please provide the export file name as a parameter.'); | ||
process.exit(1); | ||
} | ||
|
||
const strapi = await createStrapiInstance(); | ||
|
||
const source = createSourceProvider(strapi); | ||
const destination = createDestinationProvider(args[0]); | ||
|
||
const engine = createTransferEngine(source, destination, { | ||
versionStrategy: 'ignore', // for an export to file, versionStrategy will always be skipped | ||
schemaStrategy: 'ignore', // for an export to file, schemaStrategy will always be skipped | ||
only: ['content', 'files'], | ||
transforms: { | ||
links: [ | ||
{ | ||
filter(link) { | ||
return ( | ||
ALLOWED_CONTENT_TYPES.includes(link.left.type) && | ||
ALLOWED_CONTENT_TYPES.includes(link.right.type) | ||
); | ||
}, | ||
}, | ||
], | ||
entities: [ | ||
{ | ||
filter(entity) { | ||
return ALLOWED_CONTENT_TYPES.includes(entity.type); | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
engine.diagnostics.onDiagnostic(console.log); | ||
|
||
try { | ||
const results = await engine.transfer(); | ||
|
||
console.log(JSON.stringify(results.engine, null, 2)); | ||
} catch { | ||
console.error('Export process failed.'); | ||
process.exit(1); | ||
} | ||
|
||
process.exit(0); | ||
}; | ||
|
||
const createSourceProvider = (strapi) => | ||
createLocalStrapiSourceProvider({ | ||
async getStrapi() { | ||
return strapi; | ||
}, | ||
}); | ||
|
||
const createDestinationProvider = (filePath) => | ||
createLocalFileDestinationProvider({ | ||
file: { path: filePath }, | ||
encryption: { enabled: false }, | ||
compression: { enabled: false }, | ||
}); | ||
|
||
const createStrapiInstance = async (logLevel = 'error') => { | ||
const appContext = await strapiFactory.compile(); | ||
const app = strapiFactory(appContext); | ||
|
||
app.log.level = logLevel; | ||
const loadedApp = await app.load(); | ||
|
||
return loadedApp; | ||
}; | ||
const { exportData } = require('../utils/dts-export'); | ||
|
||
// TODO: make an actual yargs command and pass common options to exportData so it's easier to build the test data | ||
exportData(); |
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
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
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
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
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
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
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
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
56 changes: 56 additions & 0 deletions
56
tests/e2e/tests/content-type-builder/collection-type/create-collection-type.spec.ts
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,56 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { login } from '../../../utils/login'; | ||
import { resetDatabaseAndImportDataFromPath } from '../../../utils/dts-import'; | ||
import { waitForRestart } from '../../../utils/restart'; | ||
import { resetFiles } from '../../../utils/file-reset'; | ||
|
||
test.describe('Create collection type', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await resetFiles(); | ||
await resetDatabaseAndImportDataFromPath('with-admin.tar'); | ||
await page.goto('/admin'); | ||
await login({ page }); | ||
|
||
await page.getByRole('link', { name: 'Content-Type Builder' }).click(); | ||
|
||
// close the tutorial modal if it's visible | ||
const modal = page.getByRole('button', { name: 'Close' }); | ||
if (modal.isVisible()) { | ||
await modal.click(); | ||
await expect(modal).not.toBeVisible(); | ||
} | ||
}); | ||
|
||
// TODO: each test should have a beforeAll that does this, maybe combine all the setup into one util to simplify it | ||
// to keep other suites that don't modify files from needing to reset files, clean up after ourselves at the end | ||
test.afterAll(async () => { | ||
await resetFiles(); | ||
}); | ||
|
||
test('Can create a collection type', async ({ page }) => { | ||
await page.getByRole('button', { name: 'Create new collection type' }).click(); | ||
|
||
await expect(page.getByRole('heading', { name: 'Create a collection type' })).toBeVisible(); | ||
|
||
const displayName = page.getByLabel('Display name'); | ||
await displayName.fill('Secret Document'); | ||
|
||
const singularId = page.getByLabel('API ID (Singular)'); | ||
await expect(singularId).toHaveValue('secret-document'); | ||
|
||
const pluralId = page.getByLabel('API ID (Plural)'); | ||
await expect(pluralId).toHaveValue('secret-documents'); | ||
|
||
await page.getByRole('button', { name: 'Continue' }).click(); | ||
|
||
await expect(page.getByText('Select a field for your collection type')).toBeVisible(); | ||
await page.getByText('Small or long text').click(); | ||
await page.getByLabel('Name', { exact: true }).fill('myattribute'); | ||
await page.getByRole('button', { name: 'Finish' }).click(); | ||
await page.getByRole('button', { name: 'Save' }).click(); | ||
|
||
await waitForRestart(page); | ||
|
||
await expect(page.getByRole('heading', { name: 'Secret Document' })).toBeVisible(); | ||
}); | ||
}); |
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
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,26 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { login } from '../../utils/login'; | ||
import { resetDatabaseAndImportDataFromPath } from '../../utils/dts-import'; | ||
|
||
test.describe('Tutorial', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await resetDatabaseAndImportDataFromPath('with-admin.tar'); | ||
await page.goto('/admin'); | ||
await login({ page }); | ||
}); | ||
|
||
test('Shows tutorial on first content type', async ({ page }) => { | ||
await page.getByRole('link', { name: 'Content-type Builder' }).click(); | ||
|
||
const modalHeader = page.getByRole('heading', { name: '馃 Create a first Collection' }); | ||
expect(modalHeader).toBeVisible(); | ||
await modalHeader.click(); | ||
|
||
const closeButton = page.getByRole('button', { name: 'Close' }); | ||
expect(closeButton).toBeVisible(); | ||
await closeButton.click(); | ||
|
||
await expect(closeButton).not.toBeVisible(); | ||
await expect(modalHeader).not.toBeVisible(); | ||
}); | ||
}); |
Oops, something went wrong.