2023-08-02 10:37:51 +03:00
|
|
|
import {expect, test} from '@playwright/test';
|
2023-08-03 11:29:14 +03:00
|
|
|
import {globalDataRequests, mockApi, responseFixtures} from '../../utils/e2e';
|
2023-06-28 05:59:05 +03:00
|
|
|
|
|
|
|
test.describe('Theme settings', async () => {
|
|
|
|
test('Browsing and installing default themes', async ({page}) => {
|
2023-08-03 11:29:14 +03:00
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
browseThemes: {method: 'GET', path: '/themes/', response: responseFixtures.themes},
|
|
|
|
installTheme: {method: 'POST', path: /^\/themes\/install\/\?/, response: {
|
|
|
|
themes: [{
|
|
|
|
name: 'headline',
|
|
|
|
package: {},
|
|
|
|
active: false,
|
|
|
|
templates: []
|
|
|
|
}]
|
|
|
|
}},
|
|
|
|
activateTheme: {method: 'PUT', path: '/themes/headline/activate/', response: {
|
|
|
|
themes: [{
|
|
|
|
name: 'headline',
|
|
|
|
package: {},
|
|
|
|
active: true,
|
|
|
|
templates: []
|
|
|
|
}]
|
|
|
|
}}
|
2023-06-28 05:59:05 +03:00
|
|
|
}});
|
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
2023-07-06 13:03:01 +03:00
|
|
|
const designSection = page.getByTestId('design');
|
2023-06-28 05:59:05 +03:00
|
|
|
|
2023-07-06 13:03:01 +03:00
|
|
|
await designSection.getByRole('button', {name: 'Customize'}).click();
|
|
|
|
|
|
|
|
const designModal = page.getByTestId('design-modal');
|
|
|
|
|
|
|
|
await designModal.getByTestId('change-theme').click();
|
2023-06-28 05:59:05 +03:00
|
|
|
|
|
|
|
const modal = page.getByTestId('theme-modal');
|
|
|
|
|
2023-07-31 20:27:30 +03:00
|
|
|
// The default theme is always considered "installed"
|
2023-06-28 05:59:05 +03:00
|
|
|
|
|
|
|
await modal.getByRole('button', {name: /Casper/}).click();
|
|
|
|
|
2023-07-03 08:59:31 +03:00
|
|
|
await expect(modal.getByRole('button', {name: 'Update Casper'})).toBeVisible();
|
2023-06-28 05:59:05 +03:00
|
|
|
|
|
|
|
await expect(page.locator('iframe[title="Theme preview"]')).toHaveAttribute('src', 'https://demo.ghost.io/');
|
|
|
|
|
2023-07-06 13:03:01 +03:00
|
|
|
await modal.getByRole('button', {name: 'Change theme'}).click();
|
2023-06-28 05:59:05 +03:00
|
|
|
|
|
|
|
// Try installing another theme
|
|
|
|
|
|
|
|
await modal.getByRole('button', {name: /Headline/}).click();
|
|
|
|
|
|
|
|
await modal.getByRole('button', {name: 'Install Headline'}).click();
|
|
|
|
|
2023-07-03 08:59:31 +03:00
|
|
|
await expect(page.getByTestId('confirmation-modal')).toHaveText(/successfully installed/);
|
|
|
|
|
|
|
|
await page.getByRole('button', {name: 'Activate'}).click();
|
|
|
|
|
|
|
|
await expect(page.getByTestId('toast')).toHaveText(/headline is now your active theme/);
|
2023-06-28 05:59:05 +03:00
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.installTheme?.url).toMatch(/\?source=github&ref=TryGhost%2FHeadline/);
|
2023-06-28 05:59:05 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Managing installed themes', async ({page}) => {
|
2023-08-03 11:29:14 +03:00
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
browseThemes: {method: 'GET', path: '/themes/', response: responseFixtures.themes},
|
|
|
|
activateTheme: {method: 'PUT', path: '/themes/casper/activate/', response: {
|
|
|
|
themes: [{
|
|
|
|
...responseFixtures.themes.themes.find(theme => theme.name === 'casper')!,
|
|
|
|
active: true
|
|
|
|
}]
|
|
|
|
}},
|
|
|
|
deleteTheme: {method: 'DELETE', path: '/themes/edition/', response: {}}
|
2023-06-28 05:59:05 +03:00
|
|
|
}});
|
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
2023-07-06 13:03:01 +03:00
|
|
|
const designSection = page.getByTestId('design');
|
|
|
|
|
|
|
|
await designSection.getByRole('button', {name: 'Customize'}).click();
|
|
|
|
|
|
|
|
const designModal = page.getByTestId('design-modal');
|
2023-06-28 05:59:05 +03:00
|
|
|
|
2023-07-06 13:03:01 +03:00
|
|
|
await designModal.getByTestId('change-theme').click();
|
2023-06-28 05:59:05 +03:00
|
|
|
|
|
|
|
const modal = page.getByTestId('theme-modal');
|
|
|
|
|
|
|
|
await modal.getByRole('tab', {name: 'Installed'}).click();
|
|
|
|
|
|
|
|
await expect(modal.getByTestId('theme-list-item')).toHaveCount(2);
|
|
|
|
|
|
|
|
const casper = modal.getByTestId('theme-list-item').filter({hasText: /casper/});
|
|
|
|
const edition = modal.getByTestId('theme-list-item').filter({hasText: /edition/});
|
|
|
|
|
|
|
|
// Activate the inactive theme
|
|
|
|
|
|
|
|
await expect(casper.getByRole('button', {name: 'Activate'})).toBeVisible();
|
|
|
|
await expect(edition).toHaveText(/Active/);
|
|
|
|
|
|
|
|
await casper.getByRole('button', {name: 'Activate'}).click();
|
|
|
|
|
|
|
|
await expect(casper).toHaveText(/Active/);
|
|
|
|
await expect(edition.getByRole('button', {name: 'Activate'})).toBeVisible();
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.activateTheme?.url).toMatch(/\/themes\/casper\/activate\//);
|
2023-06-28 05:59:05 +03:00
|
|
|
|
|
|
|
// Download the active theme
|
|
|
|
|
|
|
|
await casper.getByRole('button', {name: 'Menu'}).click();
|
|
|
|
await casper.getByRole('button', {name: 'Download'}).click();
|
|
|
|
|
|
|
|
await expect(page.locator('iframe#iframeDownload')).toHaveAttribute('src', /\/api\/admin\/themes\/casper\/download/);
|
|
|
|
|
|
|
|
await page.locator('[data-testid="menu-overlay"]:visible').click();
|
|
|
|
|
|
|
|
// Delete the inactive theme
|
|
|
|
|
|
|
|
await edition.getByRole('button', {name: 'Menu'}).click();
|
|
|
|
await edition.getByRole('button', {name: 'Delete'}).click();
|
|
|
|
|
|
|
|
const confirmation = page.getByTestId('confirmation-modal');
|
|
|
|
await confirmation.getByRole('button', {name: 'Delete'}).click();
|
|
|
|
|
|
|
|
await expect(modal.getByTestId('theme-list-item')).toHaveCount(1);
|
|
|
|
|
2023-08-03 11:29:14 +03:00
|
|
|
expect(lastApiRequests.deleteTheme?.url).toMatch(/\/themes\/edition\/$/);
|
2023-06-28 05:59:05 +03:00
|
|
|
});
|
|
|
|
});
|