feat: Support dark mode in login pages (#7420)

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
Pranav Raj S
2023-06-30 19:19:52 -07:00
committed by GitHub
parent 022f4f899f
commit b57063a8b8
57 changed files with 1516 additions and 1483 deletions

View File

@@ -1,52 +1,17 @@
import 'expect-more-jest';
import {
validateAuthenticateRoutePermission,
validateRouteAccess,
} from './index';
import { validateAuthenticateRoutePermission } from './index';
jest.mock('./dashboard/dashboard.routes', () => ({
routes: [],
}));
jest.mock('./auth/auth.routes', () => ({
routes: [],
}));
jest.mock('./login/login.routes', () => ({
routes: [],
}));
window.roleWiseRoutes = {};
describe('#validateAuthenticateRoutePermission', () => {
describe(`when route is not protected`, () => {
it(`should go to the dashboard when user is logged in`, () => {
const to = { name: 'login', params: { accountId: 1 } };
const from = { name: '', params: { accountId: 1 } };
const next = jest.fn();
const getters = {
isLoggedIn: true,
getCurrentUser: {
account_id: 1,
id: 1,
accounts: [{ id: 1, role: 'admin', status: 'active' }],
},
};
validateAuthenticateRoutePermission(to, from, next, { getters });
expect(next).toHaveBeenCalledWith('/app/accounts/1/dashboard');
});
it(`should go there when user is not logged in`, () => {
const to = { name: 'login', params: {} };
const from = { name: '', params: {} };
const next = jest.fn();
const getters = { isLoggedIn: false };
validateAuthenticateRoutePermission(to, from, next, { getters });
expect(next).toHaveBeenCalledWith();
});
});
describe(`when route is protected`, () => {
describe(`when user not logged in`, () => {
it(`should redirect to login`, () => {
// Arrange
const to = { name: 'some-protected-route', params: { accountId: 1 } };
const from = { name: '' };
const next = jest.fn();
const getters = {
isLoggedIn: false,
@@ -56,8 +21,10 @@ describe('#validateAuthenticateRoutePermission', () => {
accounts: [],
},
};
validateAuthenticateRoutePermission(to, from, next, { getters });
expect(next).toHaveBeenCalledWith('/app/login');
expect(validateAuthenticateRoutePermission(to, next, { getters })).toBe(
'/app/login'
);
});
});
describe(`when user is logged in`, () => {
@@ -65,7 +32,6 @@ describe('#validateAuthenticateRoutePermission', () => {
it(`should redirect to dashboard`, () => {
window.roleWiseRoutes.agent = ['dashboard'];
const to = { name: 'admin', params: { accountId: 1 } };
const from = { name: '' };
const next = jest.fn();
const getters = {
isLoggedIn: true,
@@ -75,7 +41,7 @@ describe('#validateAuthenticateRoutePermission', () => {
accounts: [{ id: 1, role: 'agent', status: 'active' }],
},
};
validateAuthenticateRoutePermission(to, from, next, { getters });
validateAuthenticateRoutePermission(to, next, { getters });
expect(next).toHaveBeenCalledWith('/app/accounts/1/dashboard');
});
});
@@ -83,7 +49,6 @@ describe('#validateAuthenticateRoutePermission', () => {
it(`should go there`, () => {
window.roleWiseRoutes.agent = ['dashboard', 'admin'];
const to = { name: 'admin', params: { accountId: 1 } };
const from = { name: '' };
const next = jest.fn();
const getters = {
isLoggedIn: true,
@@ -93,39 +58,10 @@ describe('#validateAuthenticateRoutePermission', () => {
accounts: [{ id: 1, role: 'agent', status: 'active' }],
},
};
validateAuthenticateRoutePermission(to, from, next, { getters });
validateAuthenticateRoutePermission(to, next, { getters });
expect(next).toHaveBeenCalledWith();
});
});
});
});
});
describe('#validateRouteAccess', () => {
it('returns to login if signup is disabled', () => {
window.chatwootConfig = { signupEnabled: 'false' };
const to = { name: 'auth_signup', meta: { requireSignupEnabled: true } };
const from = { name: '' };
const next = jest.fn();
validateRouteAccess(to, from, next, {});
expect(next).toHaveBeenCalledWith('/app/login');
});
it('returns next for an auth ignore route ', () => {
const to = { name: 'auth_confirmation' };
const from = { name: '' };
const next = jest.fn();
validateRouteAccess(to, from, next, {});
expect(next).toHaveBeenCalledWith();
});
it('returns route validation for everything else ', () => {
const to = { name: 'login' };
const from = { name: '' };
const next = jest.fn();
validateRouteAccess(to, from, next, { getters: { isLoggedIn: false } });
expect(next).toHaveBeenCalledWith();
});
});