login.e2e.js 1.16 KB
Newer Older
1 2
const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;

偏右's avatar
偏右 committed
3
describe('Login', () => {
valleykid's avatar
valleykid committed
4
  beforeAll(async () => {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
5
    jest.setTimeout(1000000);
valleykid's avatar
valleykid committed
6 7 8
  });

  beforeEach(async () => {
9
    await page.goto(`${BASE_URL}/user/login`, { waitUntil: 'networkidle2' });
valleykid's avatar
valleykid committed
10
    await page.evaluate(() => window.localStorage.setItem('antd-pro-authority', 'guest'));
偏右's avatar
偏右 committed
11 12 13
  });

  it('should login with failure', async () => {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
14 15 16
    await page.waitForSelector('#userName', {
      timeout: 2000,
    });
valleykid's avatar
valleykid committed
17 18 19 20
    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
偏右's avatar
偏右 committed
21 22
  });

afc163's avatar
afc163 committed
23
  it('should login successfully', async () => {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
24 25 26
    await page.waitForSelector('#userName', {
      timeout: 2000,
    });
valleykid's avatar
valleykid committed
27
    await page.type('#userName', 'admin');
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
28
    await page.type('#password', 'ant.design');
valleykid's avatar
valleykid committed
29 30 31
    await page.click('button[type="submit"]');
    await page.waitForSelector('.ant-layout-sider h1'); // should display error
    const text = await page.evaluate(() => document.body.innerHTML);
偏右's avatar
偏右 committed
32 33 34
    expect(text).toContain('<h1>Ant Design Pro</h1>');
  });
});