You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/11/03 13:41:27 UTC

[GitHub] [apisix-dashboard] juzhiyuan commented on a change in pull request #619: feat: added e2e test for Login page

juzhiyuan commented on a change in pull request #619:
URL: https://github.com/apache/apisix-dashboard/pull/619#discussion_r515752341



##########
File path: frontend/src/e2e/Logout.e2e.js
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* eslint-disable import/no-extraneous-dependencies */
+const puppeteer = require('puppeteer');
+
+const {
+  setupLogin
+} = require('./public')
+
+let browser
+const domSelectors = {
+  userProfile: '.ant-space-horizontal div:nth-child(2)',
+  dropdownMenuItem: '.ant-dropdown-menu-item',
+  buttonLogin:".ant-btn-lg",
+  logoutButton: '.ant-dropdown > ul > li:nth-child(3)',
+};
+
+describe('Logout', () => {
+
+beforeAll(async () => {
+  browser = await puppeteer.launch({
+    headless: true,
+    slowMo: 100
+  });
+});
+
+test('Logout', async () => {
+  const page = await browser.newPage();
+  await setupLogin(page)
+  await page.click(domSelectors.userProfile);
+  await page.waitForSelector(domSelectors.dropdownMenuItem);
+  await page.waitForSelector(domSelectors.logoutButton);
+  await page.click(domSelectors.logoutButton);
+  await page.waitForSelector(domSelectors.buttonLogin);
+  await page.close();
+}, 50000);
+
+afterAll(async () => {
+  await browser.close();
+});

Review comment:
       bad intention 

##########
File path: frontend/src/e2e/public.js
##########
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Review comment:
       Not a good filename, how about `service.js`? 

##########
File path: frontend/src/e2e/README.md
##########
@@ -0,0 +1,41 @@
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+### Writing test cases

Review comment:
       How about moving this part to `docs/develop.md`?

##########
File path: frontend/src/e2e/public.js
##########
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export const BASE_URL = `http://localhost:${process.env.PORT || 8000}`;
+
+const loginSuccessData = {
+    username: 'admin',
+    password: 'admin',
+  };
+
+const domSelectors = {
+    inputUsername: '#control-ref_username',
+    inputPassword: '#control-ref_password',
+    buttonLogin: '.ant-btn-lg',
+    loginSuccessIcon: '.ant-notification-notice-icon-success',
+  };
+
+export const setupLogin = async (page)=>{
+    await page.goto(BASE_URL);

Review comment:
       2 spaces

##########
File path: frontend/src/e2e/Logout.e2e.js
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* eslint-disable import/no-extraneous-dependencies */
+const puppeteer = require('puppeteer');
+
+const {
+  setupLogin
+} = require('./public')
+
+let browser
+const domSelectors = {
+  userProfile: '.ant-space-horizontal div:nth-child(2)',
+  dropdownMenuItem: '.ant-dropdown-menu-item',
+  buttonLogin:".ant-btn-lg",
+  logoutButton: '.ant-dropdown > ul > li:nth-child(3)',
+};
+
+describe('Logout', () => {
+
+beforeAll(async () => {
+  browser = await puppeteer.launch({
+    headless: true,
+    slowMo: 100
+  });
+});
+
+test('Logout', async () => {
+  const page = await browser.newPage();
+  await setupLogin(page)
+  await page.click(domSelectors.userProfile);
+  await page.waitForSelector(domSelectors.dropdownMenuItem);
+  await page.waitForSelector(domSelectors.logoutButton);
+  await page.click(domSelectors.logoutButton);
+  await page.waitForSelector(domSelectors.buttonLogin);
+  await page.close();
+}, 50000);
+
+afterAll(async () => {
+  await browser.close();
+});

Review comment:
       2 spaces

##########
File path: frontend/src/e2e/README.md
##########
@@ -0,0 +1,41 @@
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+### Writing test cases

Review comment:
       or add a link about how to have a frontend test in `develop.md` 

##########
File path: frontend/src/e2e/public.js
##########
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Review comment:
       A service file contains some reusable methods and COULD export some public variables, too.

##########
File path: docs/develop.zh-CN.md
##########
@@ -38,6 +38,8 @@ $ yarn install
 ```sh
 $ yarn start
 ```
+### 编写 e2e 测试案例
+请参考 [e2e 文档](../frontend/src/e2e/README.zh-CN.md)。

Review comment:
       ![image](https://user-images.githubusercontent.com/2106987/97853990-d3453d80-1d33-11eb-8336-685dfff4395c.png)
   

##########
File path: frontend/src/e2e/README.md
##########
@@ -0,0 +1,41 @@
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+### Writing test cases

Review comment:
       ![image](https://user-images.githubusercontent.com/2106987/97887925-7f534c80-1d65-11eb-9672-a2dc974a75c6.png)
   
   disharmony IMO

##########
File path: docs/develop.md
##########
@@ -35,6 +35,8 @@ $ yarn install
 ```sh
 $ yarn start
 ```
+### wirte e2e test case

Review comment:
       Typo!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org