login.e2e.js 1.1 KB
Newer Older
valleykid's avatar
valleykid committed
1
import puppeteer from 'puppeteer';
偏右's avatar
偏右 committed
2 3

describe('Login', () => {
valleykid's avatar
valleykid committed
4
  let browser;
偏右's avatar
偏右 committed
5
  let page;
valleykid's avatar
valleykid committed
6 7 8 9 10 11 12 13 14

  beforeAll(async () => {
    browser = await puppeteer.launch();
  });

  beforeEach(async () => {
    page = await browser.newPage();
    await page.goto('http://localhost:8000/#/user/login');
    await page.evaluate(() => window.localStorage.setItem('antd-pro-authority', 'guest'));
偏右's avatar
偏右 committed
15 16
  });

valleykid's avatar
valleykid committed
17 18
  afterEach(() => page.close());

偏右's avatar
偏右 committed
19
  it('should login with failure', async () => {
valleykid's avatar
valleykid committed
20 21 22 23
    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
24 25
  });

afc163's avatar
afc163 committed
26
  it('should login successfully', async () => {
valleykid's avatar
valleykid committed
27 28 29 30 31
    await page.type('#userName', 'admin');
    await page.type('#password', '888888');
    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
    expect(text).toContain('<h1>Ant Design Pro</h1>');
  });
valleykid's avatar
valleykid committed
34 35

  afterAll(() => browser.close());
偏右's avatar
偏右 committed
36
});