Skip to content

Commit

Permalink
Refactored code and written test case
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv036 committed Oct 10, 2023
1 parent 32fac4c commit a50c7b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
14 changes: 14 additions & 0 deletions __test__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const puppeteer = require('puppeteer');
const timeout = 25000;
const checkDialog = require('../js/index');

describe('Dummy Test ', () => {
beforeAll(async () => {
Expand All @@ -23,3 +24,16 @@ describe('Dummy Test ', () => {
timeout,
);
});

describe('index function test case', () => {
test('should show dialog if open in phone', () => {
const regexp = /android|iphone|kindle|ipad/i; // for Mobile phone
const result = checkDialog(regexp);
expect(result).toBe('true');
});
test(`don't show dialog if not open in phone`, () => {
const regexp = /Windows|macOS|/i; // for PC
const result = checkDialog(regexp);
expect(result).toBe('false');
});
});
15 changes: 9 additions & 6 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ const numOfMembers = 5;
let memberSection = document.getElementById('members');

let regexp = /android|iphone|kindle|ipad/i;
let details = navigator.userAgent;
let isMobileDevice = regexp.test(details);
window.onload = femo();
isOpenInPhone(regexp);

export function isOpenInPhone(type) {
let details = navigator.userAgent;
let isMobileDevice = type.test(details);

function femo() {
console.log('efd');
if (isMobileDevice) {
openDialog();
document.getElementById('okayBt').addEventListener('click', openApp);
document.getElementById('cancleBt').addEventListener('click', closeDialog);
return true;
} else {
closeDialog();
return false;
}
}

function openDialog() {
document.querySelectorAll('.appDialog')[0].style.display = 'block';
document.querySelectorAll('.mainDiv')[0].style.display = 'none';
Expand All @@ -36,7 +39,7 @@ function closeDialog() {
document.querySelectorAll('.appDialog')[0].style.display = 'none';
document.querySelectorAll('.mainDiv')[0].style.display = 'block';
}
function openApp() {
function openRDSApp() {
var flag = false;
var appScheme = 'app://realdevsquad.com';
var fallbackURL =
Expand Down

0 comments on commit a50c7b1

Please sign in to comment.