<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: grusingh</title>
    <description>The latest articles on DEV Community by grusingh (@grusingh).</description>
    <link>https://dev.to/grusingh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F140336%2Fad4a339c-77e0-4978-baa5-25ca06057b96.png</url>
      <title>DEV Community: grusingh</title>
      <link>https://dev.to/grusingh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/grusingh"/>
    <language>en</language>
    <item>
      <title>Influence: The Psychology of Persuasion</title>
      <dc:creator>grusingh</dc:creator>
      <pubDate>Sat, 31 Jul 2021 10:33:09 +0000</pubDate>
      <link>https://dev.to/grusingh/influence-the-psychology-of-persuasion-32f8</link>
      <guid>https://dev.to/grusingh/influence-the-psychology-of-persuasion-32f8</guid>
      <description>&lt;p&gt;I came to know about this book while surfing twitter and reading an article about Shopify CEO Tobias &lt;a href="https://www.inc.com/jessica-stillman/shopify-tobias-lutke-andrew-grove.html"&gt;two books that made me billionaire&lt;/a&gt;. The first book &lt;a href="https://www.goodreads.com/book/show/28815.Influence"&gt;Influence: The Psychology of Persuasion by Robert B. Cialdini&lt;/a&gt; deals with science of persuasion. At first I thought of it as another self help book but it turned out be more of a science book describing various persuasion elements by providing references to various research studies that have been conducted around the world.&lt;/p&gt;

&lt;p&gt;Highly recommend reading this book. In case time is an issue this &lt;a href="https://entrepreneurshandbook.co/two-books-that-turned-a-26-year-old-programmer-into-a-billionaire-8990e52065b1"&gt;article by Alan Trapulionis&lt;/a&gt; does a good job of summarizing the core learnings of the book.&lt;/p&gt;

&lt;p&gt;There is an &lt;a href="https://www.amazon.ca/Influence-New-Expanded-Psychology-Persuasion-ebook/dp/B08HZ57WYN/ref=tmm_kin_swatch_0?_encoding=UTF8&amp;amp;qid=&amp;amp;sr="&gt;updated May 2021 version&lt;/a&gt; with a new principle Unity. I read the older version, can't wait to get my hands on the new one.  &lt;/p&gt;

</description>
      <category>book</category>
      <category>influence</category>
    </item>
    <item>
      <title>Working with legacy React apps</title>
      <dc:creator>grusingh</dc:creator>
      <pubDate>Tue, 20 Jul 2021 12:20:52 +0000</pubDate>
      <link>https://dev.to/grusingh/working-with-legacy-react-apps-3olp</link>
      <guid>https://dev.to/grusingh/working-with-legacy-react-apps-3olp</guid>
      <description>&lt;p&gt;Working with legacy code can be challenging especially when code is lacking in test coverage.  In his must read book &lt;a href="https://www.goodreads.com/book/show/44919.Working_Effectively_with_Legacy_Code"&gt;Working Effectively with Legacy Code&lt;/a&gt; author Michael Feathers talks about a refactoring technique Extract Method for tackling large methods. &lt;/p&gt;

&lt;p&gt;I have successfully used this technique many times to enhance or add features to complex React components and adding test coverage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;We are given a task to fix bug in a LoanCalculator component. It's a huge file with complex logic and no test coverage. We have identified the cause of bug and ready to make changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function LoanCalculator(props) {
  ...
  lots of lines of code
  ...

  if (someCondition) {
    // bug is here 
    // fix: props.x + props.y
    return props.x - props.y;
  }

  ...
  more code
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The recommended way is to create tests for LoanCalculator when possible before making any code changes. In our case we don't understand the logic enough to create tests for whole file.   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Start by extracting the lines for bug fix into a separate method. Notice that we are doing a named &lt;em&gt;export&lt;/em&gt; for someCalculation function. This refactoring enables us to start creating tests for our newly extracted method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bug is here 
// fix: props.x + props.y
export function someCalculation(x, y) {
  return x - y;
}

function LoanCalculator(props) {
  ...
  lots of lines of code
  ...

  if (someCondition) {
    return someCalculation(props.x, props.y);
  }

  ...
  more code
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Add tests to cover and set expectations for someCalculation function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* file: LoanCalculator.spec.js */
import {someCalculation} from './LoanComponent';

describe('LoanCalculator', () =&amp;gt; {
  it('someCalculation should return sum of x and y', () =&amp;gt; {
    const result = someCalculation(2,3);
    expect(result).toEqual(5);
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Now that we have a failing test we can apply the bug fix.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export function someCalculation(x, y) {
  return x + y;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: The test we created should we passing now. &lt;/p&gt;

&lt;p&gt;By using the Extract Method refactoring technique we were able to reduce complexity in LoanComponent component and add test to go along with our bug fix.&lt;/p&gt;

&lt;p&gt;Hope you find this article useful. Please share your feedback.   &lt;/p&gt;

</description>
      <category>react</category>
      <category>legacycode</category>
      <category>testing</category>
    </item>
    <item>
      <title>Testing navigation in react</title>
      <dc:creator>grusingh</dc:creator>
      <pubDate>Sun, 18 Jul 2021 21:02:37 +0000</pubDate>
      <link>https://dev.to/grusingh/testing-navigation-in-react-310m</link>
      <guid>https://dev.to/grusingh/testing-navigation-in-react-310m</guid>
      <description>&lt;p&gt;When testing navigation in a React component we can either check the final url or we can verify the updated DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test scenario 1&lt;/strong&gt;: Test that clicking the &lt;strong&gt;about&lt;/strong&gt; link will &lt;em&gt;redirect&lt;/em&gt; to About Us path. This could be useful in scenarios where you are computing query params and want to assert on their values. &lt;/p&gt;

&lt;p&gt;To make assertion on url possible we will have to use Router component (react-router-dom) with our own history object. Note that when using this approach the rendered markup won't get updated to reflect navigational changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test scenario 2&lt;/strong&gt;: Test that clicking the &lt;strong&gt;about&lt;/strong&gt; link will &lt;em&gt;render&lt;/em&gt; About Us path. This is preferred approach and useful in scenarios where DOM content changes after navigation.&lt;/p&gt;

&lt;p&gt;To make assertions on updated DOM we will use BrowserRouter component (react-router-dom). Note that when this approach history won't be available to the test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* file: index.js */
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import {BrowserRouter} from "react-router-dom";

ReactDOM.render(
    &amp;lt;React.StrictMode&amp;gt;
        &amp;lt;BrowserRouter&amp;gt;
            &amp;lt;App/&amp;gt;
        &amp;lt;/BrowserRouter&amp;gt;
    &amp;lt;/React.StrictMode&amp;gt;,
    document.getElementById('root')
);

/* App.js */
import {Link, Route} from 'react-router-dom';

function App() {
    return &amp;lt;div&amp;gt;
        &amp;lt;h1&amp;gt;MyApp&amp;lt;/h1&amp;gt;
        &amp;lt;nav&amp;gt;
            &amp;lt;ul&amp;gt;
                &amp;lt;li&amp;gt;&amp;lt;Link to="/"&amp;gt;Home&amp;lt;/Link&amp;gt;&amp;lt;/li&amp;gt;
                &amp;lt;li&amp;gt;&amp;lt;Link to="/about"&amp;gt;About&amp;lt;/Link&amp;gt;&amp;lt;/li&amp;gt;
            &amp;lt;/ul&amp;gt;
        &amp;lt;/nav&amp;gt;
        &amp;lt;div&amp;gt;
            &amp;lt;Route path="/" exact&amp;gt;
                &amp;lt;h2&amp;gt;Home page&amp;lt;/h2&amp;gt;
            &amp;lt;/Route&amp;gt;
            &amp;lt;Route path="/about"&amp;gt;
                &amp;lt;h2&amp;gt;About Us&amp;lt;/h2&amp;gt;
            &amp;lt;/Route&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
}

export default App;

/* App.spec.js */
import { render, screen} from '@testing-library/react';
import {BrowserRouter, Router} from 'react-router-dom';
import userEvent from "@testing-library/user-event";
import {createMemoryHistory} from 'history';
import App from './App';

test('should redirect and update history', () =&amp;gt; {
    const history = createMemoryHistory();

    render(&amp;lt;Router history={history}&amp;gt;&amp;lt;App/&amp;gt;&amp;lt;/Router&amp;gt;);

    userEvent.click(screen.getByText(/About/));

    expect(history.location.pathname).toEqual('/about');
});

test('should redirect and update dom', () =&amp;gt; {
    render(&amp;lt;BrowserRouter&amp;gt;&amp;lt;App/&amp;gt;&amp;lt;/BrowserRouter&amp;gt;);

    userEvent.click(screen.getByText(/About/));

    expect(screen.getByText(/About Us/i)).toBeInTheDocument();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>react</category>
      <category>testing</category>
      <category>reactrouter</category>
    </item>
    <item>
      <title>Is Team Lead role a fit for you? </title>
      <dc:creator>grusingh</dc:creator>
      <pubDate>Tue, 26 Feb 2019 00:23:53 +0000</pubDate>
      <link>https://dev.to/sarngru/is-team-lead-role-a-fit-for-you--26dj</link>
      <guid>https://dev.to/sarngru/is-team-lead-role-a-fit-for-you--26dj</guid>
      <description>

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1iVra3Ji--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ndwbwezw9vpz2nocv4z0.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1iVra3Ji--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ndwbwezw9vpz2nocv4z0.jpeg" alt="Is Team Lead role a fit for you?"&gt;&lt;/a&gt;&lt;br&gt;
Are you a developer transitioning into or considering a Team Lead role?&lt;/p&gt;

&lt;p&gt;Being a Team Lead is not an easy job. Although it might come with a job description, but responsibilities, opportunities and challenges are a lot more.&lt;/p&gt;

&lt;p&gt;Here are some points to ponder upon:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Team Lead is not the only career path for developers. Give consideration to specialising in a technical domain, architecture, test automation, devops and other possibilities.&lt;/li&gt;
&lt;li&gt;Team Lead is a supervisory role and &lt;strong&gt;not a managerial role&lt;/strong&gt;. You will likely be expected to provide technical leadership and also write code yourself. You won’t likely have any budget or any authority.&lt;/li&gt;
&lt;li&gt;Do you enjoy working with people? This includes handling difficult situations, giving constructive feedback, holding people accountable, performance reviews, hiring employees and in worst cases participating/leading employee termination process.&lt;/li&gt;
&lt;li&gt;Is your manager and organisation committed in supporting you in your new role? This might include one to one coaching, on going training and learning.
Compare possibly increased compensation vs additional responsibilities and commitments. If there is no salary increase then think again.
*Are you okay to step out of your comfort zone and acquire people skills? Not limited to communication, leadership, delegation and motivation skills.&lt;/li&gt;
&lt;li&gt;Number of people reporting to you? 1 to 4 is ideal.&lt;/li&gt;
&lt;li&gt;Understand that you won’t be able to code much. Longevity of this role is questionable. You need to be hands-on to stay up to speed with current trends but you will lose your technical skills over time due to lack of time available to code yourself.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A good Team Lead will show:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Leadership&lt;/strong&gt;: Be hands-on technically. Won’t preach. Will lead by example. Will walk the talk.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Empathy&lt;/strong&gt;: Have empathy for direct reports and for oneself. People can and will make mistakes. Its a lead’s responsibility to ensure that employees have proper training, clear directions and safe work environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integrity&lt;/strong&gt;: Have integrity and win trust. Likewise has trust in direct reports. Gives them autonomy and motivates them to step up and do their best. No one likes to be micro-managed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fairness&lt;/strong&gt;: Is fair to all direct reports and offers them fair chance to appreciation, opportunities, resources and his/her time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Professional Relationship&lt;/strong&gt;: Is not friends with selective individuals as that might give perception of favoritism. Keeps relationship strictly professional with all direct reports.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hiring&lt;/strong&gt;: Hires capable people and let them do their best. Lead is not be the smartest person on the team.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Team Lead is an important role. It demands a distinct skill set. Hope this article will help you in some way making into a good team lead.&lt;/p&gt;

&lt;p&gt;Thanks to &lt;a href="https://www.linkedin.com/in/fullstackphilipchan/"&gt;Philip Chan&lt;/a&gt; for reviewing this article.&lt;/p&gt;


</description>
      <category>teamlead</category>
      <category>careerpaths</category>
    </item>
  </channel>
</rss>
