初始化 antd-pro
This commit is contained in:
34
admin-web/src/e2e/baseLayout.e2e.js
Normal file
34
admin-web/src/e2e/baseLayout.e2e.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import RouterConfig from '../../config/router.config';
|
||||
|
||||
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
|
||||
|
||||
function formatter(data) {
|
||||
return data
|
||||
.reduce((pre, item) => {
|
||||
pre.push(item.path);
|
||||
return pre;
|
||||
}, [])
|
||||
.filter(item => item);
|
||||
}
|
||||
|
||||
describe('Homepage', async () => {
|
||||
const testPage = path => async () => {
|
||||
await page.goto(`${BASE_URL}${path}`);
|
||||
await page.waitForSelector('footer', {
|
||||
timeout: 2000,
|
||||
});
|
||||
const haveFooter = await page.evaluate(
|
||||
() => document.getElementsByTagName('footer').length > 0
|
||||
);
|
||||
expect(haveFooter).toBeTruthy();
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.setTimeout(1000000);
|
||||
await page.setCacheEnabled(false);
|
||||
});
|
||||
const routers = formatter(RouterConfig[1].routes);
|
||||
routers.forEach(route => {
|
||||
it(`test pages ${route}`, testPage(route));
|
||||
});
|
||||
});
|
||||
15
admin-web/src/e2e/home.e2e.js
Normal file
15
admin-web/src/e2e/home.e2e.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
|
||||
|
||||
describe('Homepage', () => {
|
||||
beforeAll(async () => {
|
||||
jest.setTimeout(1000000);
|
||||
});
|
||||
it('it should have logo text', async () => {
|
||||
await page.goto(BASE_URL);
|
||||
await page.waitForSelector('h1', {
|
||||
timeout: 5000,
|
||||
});
|
||||
const text = await page.evaluate(() => document.getElementsByTagName('h1')[0].innerText);
|
||||
expect(text).toContain('Ant Design Pro');
|
||||
});
|
||||
});
|
||||
34
admin-web/src/e2e/login.e2e.js
Normal file
34
admin-web/src/e2e/login.e2e.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
|
||||
|
||||
describe('Login', () => {
|
||||
beforeAll(async () => {
|
||||
jest.setTimeout(1000000);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await page.goto(`${BASE_URL}/user/login`, { waitUntil: 'networkidle2' });
|
||||
await page.evaluate(() => window.localStorage.setItem('antd-pro-authority', 'guest'));
|
||||
});
|
||||
|
||||
it('should login with failure', async () => {
|
||||
await page.waitForSelector('#userName', {
|
||||
timeout: 2000,
|
||||
});
|
||||
await page.type('#userName', 'mockuser');
|
||||
await page.type('#password', 'wrong_password');
|
||||
await page.click('button[type="submit"]');
|
||||
await page.waitForSelector('.ant-alert-error'); // should display error
|
||||
});
|
||||
|
||||
it('should login successfully', async () => {
|
||||
await page.waitForSelector('#userName', {
|
||||
timeout: 2000,
|
||||
});
|
||||
await page.type('#userName', 'admin');
|
||||
await page.type('#password', 'ant.design');
|
||||
await page.click('button[type="submit"]');
|
||||
await page.waitForSelector('.ant-layout-sider h1'); // should display error
|
||||
const text = await page.evaluate(() => document.body.innerHTML);
|
||||
expect(text).toContain('<h1>Ant Design Pro</h1>');
|
||||
});
|
||||
});
|
||||
18
admin-web/src/e2e/topMenu.e2e.js
Normal file
18
admin-web/src/e2e/topMenu.e2e.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
|
||||
|
||||
describe('Homepage', () => {
|
||||
beforeAll(async () => {
|
||||
jest.setTimeout(1000000);
|
||||
});
|
||||
it('topmenu should have footer', async () => {
|
||||
const params = '/form/basic-form?navTheme=light&layout=topmenu';
|
||||
await page.goto(`${BASE_URL}${params}`);
|
||||
await page.waitForSelector('footer', {
|
||||
timeout: 2000,
|
||||
});
|
||||
const haveFooter = await page.evaluate(
|
||||
() => document.getElementsByTagName('footer').length > 0
|
||||
);
|
||||
expect(haveFooter).toBeTruthy();
|
||||
});
|
||||
});
|
||||
32
admin-web/src/e2e/userLayout.e2e.js
Normal file
32
admin-web/src/e2e/userLayout.e2e.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import RouterConfig from '../../config/router.config';
|
||||
|
||||
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
|
||||
|
||||
function formatter(data) {
|
||||
return data
|
||||
.reduce((pre, item) => {
|
||||
pre.push(item.path);
|
||||
return pre;
|
||||
}, [])
|
||||
.filter(item => item);
|
||||
}
|
||||
|
||||
describe('Homepage', () => {
|
||||
const testPage = path => async () => {
|
||||
await page.goto(`${BASE_URL}${path}`);
|
||||
await page.waitForSelector('footer', {
|
||||
timeout: 2000,
|
||||
});
|
||||
const haveFooter = await page.evaluate(
|
||||
() => document.getElementsByTagName('footer').length > 0
|
||||
);
|
||||
expect(haveFooter).toBeTruthy();
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.setTimeout(1000000);
|
||||
});
|
||||
formatter(RouterConfig[0].routes).forEach(route => {
|
||||
it(`test pages ${route}`, testPage(route));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user