From 3ed4fb2b75e7586f0d1a9ea4d264332731a4ce28 Mon Sep 17 00:00:00 2001
From: pal-sig <88981777+pal-sig@users.noreply.github.com>
Date: Thu, 2 Dec 2021 18:47:40 +0530
Subject: [PATCH] FE(UI):Channels test (#417)
* bug(UI): default tab over setting is resolved
* feat(UI): channels test is updated
---
.../cypress/fixtures/defaultAllChannels.json | 21 ++++++++
.../integration/channels/index.spec.ts | 52 +++++++++++++++++++
.../src/container/SettingsWrapper/index.tsx | 4 +-
frontend/src/pages/AllAlertChannels/index.tsx | 19 ++++---
4 files changed, 85 insertions(+), 11 deletions(-)
create mode 100644 frontend/cypress/fixtures/defaultAllChannels.json
create mode 100644 frontend/cypress/integration/channels/index.spec.ts
diff --git a/frontend/cypress/fixtures/defaultAllChannels.json b/frontend/cypress/fixtures/defaultAllChannels.json
new file mode 100644
index 0000000000..c292bc1f2d
--- /dev/null
+++ b/frontend/cypress/fixtures/defaultAllChannels.json
@@ -0,0 +1,21 @@
+{
+ "data": [
+ {
+ "created_at": 1638083159246,
+ "data": "{}",
+ "id": 1,
+ "name": "First Channels",
+ "type": "slack",
+ "updated_at": 1638083159246
+ },
+ {
+ "created_at": 1638083159246,
+ "data": "{}",
+ "id": 2,
+ "name": "Second Channels",
+ "type": "Slack",
+ "updated_at": 1638083159246
+ }
+ ],
+ "message": "Success"
+}
diff --git a/frontend/cypress/integration/channels/index.spec.ts b/frontend/cypress/integration/channels/index.spec.ts
new file mode 100644
index 0000000000..e54ed4757f
--- /dev/null
+++ b/frontend/cypress/integration/channels/index.spec.ts
@@ -0,0 +1,52 @@
+///
+
+import ROUTES from 'constants/routes';
+
+import defaultAllChannels from '../../fixtures/defaultAllChannels.json';
+
+describe('Channels', () => {
+ beforeEach(() => {
+ window.localStorage.setItem('isLoggedIn', 'yes');
+
+ cy.visit(Cypress.env('baseUrl') + ROUTES.ALL_CHANNELS);
+ });
+
+ it('Channels', () => {
+ cy
+ .intercept('**channels**', {
+ statusCode: 200,
+ fixture: 'defaultAllChannels',
+ })
+ .as('All Channels');
+
+ cy.wait('@All Channels');
+
+ cy
+ .get('.ant-tabs-tab')
+ .children()
+ .then((e) => {
+ const child = e.get();
+
+ const secondChild = child[1];
+
+ expect(secondChild.outerText).to.be.equals('Alert Channels');
+
+ expect(secondChild.ariaSelected).to.be.equals('true');
+ });
+
+ cy
+ .get('tbody')
+ .should('be.visible')
+ .then((e) => {
+ const allChildren = e.children().get();
+ expect(allChildren.length).to.be.equals(defaultAllChannels.data.length);
+
+ allChildren.forEach((e, index) => {
+ expect(e.firstChild?.textContent).not.null;
+ expect(e.firstChild?.textContent).to.be.equals(
+ defaultAllChannels.data[index].name,
+ );
+ });
+ });
+ });
+});
diff --git a/frontend/src/container/SettingsWrapper/index.tsx b/frontend/src/container/SettingsWrapper/index.tsx
index e50f05337d..afe59fe7bd 100644
--- a/frontend/src/container/SettingsWrapper/index.tsx
+++ b/frontend/src/container/SettingsWrapper/index.tsx
@@ -15,6 +15,7 @@ const SettingsWrapper = ({
AlertChannels,
General,
toggleSettingsTab,
+ defaultRoute,
}: SettingsWrapperProps): JSX.Element => {
const { settingsActiveTab } = useSelector(
(state) => state.app,
@@ -38,7 +39,7 @@ const SettingsWrapper = ({
onChangeHandler(value as SettingTab)}
- activeKey={settingsActiveTab}
+ activeKey={defaultRoute || settingsActiveTab}
>
@@ -63,6 +64,7 @@ const mapDispatchToProps = (
interface SettingsWrapperProps extends DispatchProps {
General: () => JSX.Element;
AlertChannels: () => JSX.Element;
+ defaultRoute?: SettingTab;
}
export default connect(null, mapDispatchToProps)(SettingsWrapper);
diff --git a/frontend/src/pages/AllAlertChannels/index.tsx b/frontend/src/pages/AllAlertChannels/index.tsx
index 6f37019372..716795500c 100644
--- a/frontend/src/pages/AllAlertChannels/index.tsx
+++ b/frontend/src/pages/AllAlertChannels/index.tsx
@@ -3,15 +3,14 @@ import GeneralSettings from 'container/GeneralSettings';
import SettingsWrapper from 'container/SettingsWrapper';
import React from 'react';
-const AllAlertChannels = (): JSX.Element => {
- return (
-
- );
-};
+const AllAlertChannels = (): JSX.Element => (
+
+);
export default AllAlertChannels;