r/stackoverflow • • Sep 02 '24

Question ReactJS Testing (Help Needed): "display styling is not getting updated"

2 Upvotes

display styling is not getting updated

const [isHoveringSignedInJobs, setisHoveringSignedInJobs] = useState(false);


useEffect(() => {
      console.log("isHoveringSignedInJobs updated:", isHoveringSignedInJobs);
      console.log("Signed in jobsNormalButton should be", isHoveringSignedInJobs ? "hidden" : "visible");
      console.log("Signed in jobsHoverButton should be", isHoveringSignedInJobs ? "visible" : "hidden");
  }, [isHoveringSignedInJobs]);


 const handleSignedInJobsMouseEnter = () => {
      console.log("Mouse entered Jobs Button");
      setisHoveringSignedInJobs(true);
  };
  const handleSignedInJobsMouseLeave = () => {
      console.log("Mouse left Jobs Button");
      setisHoveringSignedInJobs(false);
  };


return (
    <div> 
      {userId === null ? (
        <>
        {console.log('userId is null / not logged in', userId)}
        <nav>
          <svg 
            data-testid="not-signed-in-jobs-button-normal" 
            style={{ display: isHoveringSignedInJobs ? 'none' : 'block' }} 
            onMouseEnter={handleSignedInJobsMouseEnter} 
            onMouseLeave={handleSignedInJobsMouseLeave}>
            <NotSignedInJobDescriptionPageJobsButtonNormalSVG />
          </svg>

          <svg 
            data-testid="not-signed-in-jobs-button-hover" 
            style={{ display: isHoveringSignedInJobs ? 'block' : 'none' }} 
            onClick={handleSignedInJobsClick}>
            <NotSignedInJobDescriptionPageJobsButtonHoverSVG />
          </svg>


test('shows normal buttons on mouse leave and hides hover button jobs, for signed in', () => {
    console.log('shows normal buttons on mouse leave and hides hover button jobs, for signed in: Starting test: shows normal buttons on mouse leave for signed in user'); // Log start of test
  
    // Arrange: Get the normal and hover buttons
    console.log('shows normal buttons on mouse leave and hides hover button jobs, for signed in: Rendering component with userId 123 to simulate signed in state'); // Log rendering with userId
    render(
      <UserProvider value={{ userId: 123, setUserId: setUserIdMock }}>
        <JobDescriptionNavigationMenu />
      </UserProvider>
    );
    
    const signedInJobsNormalButton = screen.getByTestId('signed-in-jobs-button-normal');
    const signedInJobsHoverButton = screen.getByTestId('signed-in-jobs-button-hover');

    fireEvent.mouseEnter(signedInJobsNormalButton);

      expect(screen.queryByTestId('signed-in-jobs-button-normal')).toHaveStyle('display: none'); // Hover button should be hidden initially
 
      expect(screen.queryByTestId('signed-in-jobs-button-hover')).toHaveStyle('display: block'); // Normal button should be visible initially
    

    fireEvent.mouseLeave(signedInJobsHoverButton);

 
      expect(screen.queryByTestId('signed-in-jobs-button-hover')).toHaveStyle('display: none'); // Normal button should be visible initially 
  
      expect(screen.queryByTestId('signed-in-jobs-button-normal')).toHaveStyle('display: block'); // Hover button should be hidden initially
    

    console.log('shows normal buttons on mouse leave and hides hover button jobs, for signed in: Test completed: shows normal buttons on mouse leave for signed in user'); // Log end of test
  
  });

The below error is generating, not suuure why

● JobDescriptionNavigationMenu Component › shows normal buttons on mouse leave and hides hover button jobs, for signed in

expect(element).toHaveStyle()

  • Expected

  • display: none;

  • display: block;

840 |

841 |

| ^

843 |

844 | expect(screen.getByTestId('signed-in-jobs-button-normal')).toHaveStyle('display: block'); // Hover button should be hidden initially

845 |

at Object.toHaveStyle (src/jesttests/NavigationTests/jobDescription.test.js:842:65)

So I did through an await around the expect in case the assertation was checking the display before it could turn to none and set it to 5000 (5 seconds) and it never came through, the request to change the state.

Thoughts?

Sandbox: https://codesandbox.io/p/sandbox/clever-water-ks87kg


r/stackoverflow • • Aug 18 '24

C# Displaying custom data in ComboBox from a XML

2 Upvotes

Im trying to load some data from a XML but I want to display it to the user the data in a specific format

I was trying this method but all I get is a "-" shown to the user

private void PopulateActividadEconomicaComboBox()
 {
     var actividad_economica = _xmlData.Descendants("ActividadEconomica")
                              .Select(x => new
                              {
                                  Name = (string)x.Element("Nombre"),
                                  ID = (string)x.Element("Codigo"),
                                  DisplayUser = $"{(string)x.Attribute("Codigo")} - {(string)x.Attribute("Nombre")}"
                              })
                              .OrderBy(x => x.ID)
                              .ToList();

     // Insert an empty item at the start if needed
     actividad_economica.Insert(0, new { Name = "", ID = "", DisplayUser = "" });

     ACTIVIDADECONOMICA_EMPRESA.DataSource = actividad_economica;
     ACTIVIDADECONOMICA_EMPRESA.DisplayMember = "DisplayUser";
     ACTIVIDADECONOMICA_EMPRESA.ValueMember = "ID";
 }

I dont know what Im missing here...

Any help is appreciated


r/stackoverflow • • Aug 13 '24

Backend auth and secure route NodeJS

Thumbnail reddit.com
2 Upvotes

r/stackoverflow • • Aug 07 '24

Javascript Redirect not working in Production build. NextJs14

2 Upvotes

[HEADS UP]: Thanks in advance.

Hello everyone. I'm triying to authenticate through the production build of my project. However, I found out that there's an issue with redirect().

I initially though it was a server error on my ExpressJS backend but I checked the logs and the POST request is succesful, however, the front end is not setting up cookies as it should and thus redirect fails.

The login page was made on the "server side" and is not using any React client hook.

import {
  fetchurl,
  setAuthTokenOnServer,
  setUserOnServer,
} from '@/helpers/setTokenOnServer'
import { redirect } from 'next/navigation'
import FormButtons from '@/components/global/formbuttons'

const Login = async ({ params, searchParams }) => {

  const loginAccount = async (formData) => {
    'use server'
    const rawFormData = {
      email: formData.get('email'),
      password: formData.get('password')
    }

    const res = await fetchurl(`/auth/login`, 'POST', 'no-cache', rawFormData);

    if (res?.data) {
      redirect(`/auth/validatetwofactorauth/${res?.data?._id}`)
    }

    // If not success, stop
    if (!res?.success) return;
    
    await setAuthTokenOnServer(res?.token); // Sets auth cookies on server
    const loadUser = await fetchurl(`/auth/me`, 'GET', 'no-cache'); // loads user based on auth
    await setUserOnServer(loadUser?.data); // then sets some user's values into cookies
    searchParams?.returnpage ? redirect(searchParams.returnpage) : redirect(`/auth/profile`);
  }

  return (
    <form action={loginAccount}>
      <label htmlFor="email" className="form-label">
        Email
      </label>
      <input
        id="email"
        name="email"
        type="email"
        className="form-control mb-3"
        placeholder="[email protected]"
      />
      <label htmlFor="password" className="form-label">
        Password
      </label>
      <input
        id="password"
        name="password"
        type="password"
        className="form-control mb-3"
        placeholder="******"
      />
      <br />
      <FormButtons />
    </form>
  )
}

export default Login

Has anyone dealt with something like this before?


r/stackoverflow • • Apr 15 '20

Thoughts on a paid version of stack overflow?

2 Upvotes

Simply, I use stack overflow for 1 line (or function) debugging.

Is their a way I can post on stack overflow and offer a paid incentive for someone to answer my question? If their isn’t, how would you feel if their was such a way for uses to offer a monetary reward for answering their questions?


r/stackoverflow • • Mar 21 '20

How to Download blob videos

2 Upvotes

Anyone knows how to download blob videos. Sinece there is no link to download those type videos, i have tried to record those videos with camtesia studio software. But the website won't allow for it. appears a black screen around the video.

Thanks


r/stackoverflow • • Feb 14 '20

I often have small questions about stack overflow answers that I would like to add as a comment, but I can't leave comments because I only have 43 rep when I need 50. Would anyone be willing to upvote one of my questions/answers so that I can get enough rep to ask a dang clarification question?

2 Upvotes

...or explain to me an easy way I could get a little bit more rep? I know I could write a question or answer, but I don't really have the time to be doing that unless I have a problem that I'm really stumped on.

My account:

https://stackoverflow.com/users/6095238/canderson156


r/stackoverflow • • Jan 22 '20

Scripting the Future of Stack Overflow - Stack Overflow Blog

Thumbnail
stackoverflow.blog
2 Upvotes

r/stackoverflow • • Dec 26 '19

I haven't gotten any answers on my question so far, if you could answer it would be greatly appreciated. (What is the most efficient way to provide relatively accurate collision detection between images in JavaScript? )

Thumbnail
stackoverflow.com
2 Upvotes

r/stackoverflow • • Dec 25 '19

(Bug?) via email, , or .

Post image
2 Upvotes

r/stackoverflow • • Dec 17 '19

The hate of men will pass, and dictators die, and the power they took from the people will return to the people (StackOverFlow)

2 Upvotes

Hi,

I really like this quote from "Charli Chaplin", it is like a universal law which holds in every situation. For example, look at Reddit and StackOverflow.com, while StackOverflow.com was nothing except a website to ask questions and share problems with others. When you look at it now, it is a completely strange place, it is not open source anymore the community is like a jail that everyone is controlling what you are asking. The approach is to make more money, while StackOverFlow was nothing without the help of programmers and now the same website is governing programmers to the extent to which in many articles I see they are citing to StackOverflow to prove what language is more powerful or better. In the last three months, I asked 4 questions which were really okay because I asked it here in Reddit and it took the attention of many people, but in StackOverFlow.com it got removed in 2 hours. I think wherever people help tp shape a democracy then that democracy will govern people, except in a few cases and that is why I still donate to reddit.com every month because reddit.com is one of those exceptions.

Thanks Reddit


r/stackoverflow • • Sep 23 '19

Need a recommendation for a message broker

2 Upvotes

I asked for a recommendation here:

https://softwarerecs.stackexchange.com/questions/69171/message-broker-for-low-volume-of-messages-behind-iis

I will also copy paste the question:

I am looking for a tool which will allow me to push messages from a server to server clients (using the pub/sub pattern). I have already looked at some `WebSockets` implementation, and if we go in that direction, it will be `SignalR`.

Now I am looking for another option - a message broker. The main reason I am also searching for a broker solution, is mainly requirement number 5 in the below points:

  1. clients are implemented with React. Server is implemented using .NET core - which means the broker should support the use of C#. All clients run the same app and there are no several different protocols to consider.

2. The message broker should work behind IIS, not Apache.

3. The clients needs to receive messages with data as it's ready. They shouldn't ask every time interval for new data (polling). Since the messages should only be sent once when the data is ready, avoiding message loss is important. Also because of that, the ability to receive ACK/NACK on messages is important.

4. clients should be grouped to different groups - about 5 different groups with about 50 clients in each group. Each group can send 2 messages per second. Each message size is about 1kb. Because of that I'm hoping to use a simpler broker, which is easy to use and configure.

5. If the broker server dies, another one should automatically be chosen in its place (not sure if that what is called clustering?)

For internal reasons, `RabbitMQ` can't be used. `Redis` at first sounded promising, but then I read there could be some message loss using it, so it's also off the table. `Kafka` is not right, because it must rely on `ZooKeeper`, which doesn't mix well with Windows and IIS.

What broker do you believe is best suited for these requirements?


r/stackoverflow • • Sep 19 '19

Please Help!! Trying to create keyboard layout for physical keyboards on android

Post image
2 Upvotes

r/stackoverflow • • Sep 16 '19

Is there useful data on SO about wether someone would be a good team-player?

2 Upvotes

I have been a regular on SO for about 1-2 years now, and most of the time I end up interacting with the same group of 20-30 users. Some of them are really nice and patient, while others are whiny, pushy or do not take to criticism very well.

I wonder if recruiters look at these human interactions on SO (rather than just your reputation) to gather info about a possible candidate. I am pretty sure they do not do that, but also I wonder if there is any useful data on SO about how a person would interact with future managers and co-workers.


r/stackoverflow • • Sep 08 '19

Unanswered Python3 & Matplotlib question: Help is greatly appreciated!

2 Upvotes

https://stackoverflow.com/q/57840758/7913301

I have implemented multivariate linear regression, where parameters theta0 (intersect), theta1, theta2 are optimized by minimizing MSE loss, chosen with line search in gradient descent. How do I visually illustrate the mathematical property that the direction of steepest descent (negative gradient) of successive steps are orthogonal? I'm trying to generate a contour map similar to this image: Plot, but with respect to 2 parameters instead of 1 (if it's not possible, 2 separate plots would also be great).

Also, I originally wanted to perform multivariate linear regression with 4 features, but ultimately decided to use only the 2 most strongly correlated ones (after comparing their PCC) in order to be able to plot a graph. Although I'm not aware of any way to plot 4-dimensional data, does anyone know if this is possible and how?


r/stackoverflow • • Jul 09 '19

Are there any precautions I need to take before uploading my project to stack overflow?

2 Upvotes

I have an issue with my code and need to upload it to ask for help. But the Project window has my email id (Apple ID) and idk if I should upload it with that showing? Also idk if there is any other information that needs to be hidden? First time!


r/stackoverflow • • Jun 23 '19

Why are my drop downs opening automatically when resizing to smaller screen size?

2 Upvotes

r/stackoverflow • • Jun 13 '19

how to insert this callrail javascript snippet into wordpress footer? (elementor)

2 Upvotes

I'm trying to insert the following javascript snippet into the footer of my wordpress site for call tracking in callrail (dynamic number insertion)

https://codepen.io/kps257/pen/ydNzPJ

for this website : www.tucsoncustomremodel.com

its telling me "Insert this code snippet immediately before the </body> tag on every page of your website." , I only have one page (a lead generation landing site) built with wordpress using elementor.

I've tried copying and pasting it directly into the index.php file and using about a half dozen plugins but callrail keeps telling me when testin it

"We've encountered an error with your code installation:

Your code snippet is in the wrong location. Please place your code snippet just before the closing tag on your web page."

heres the full site index.php

https://codepen.io/kps257/pen/vqOeeV

So i'm copying the javascript snippet

onto the line preceding "</body></html>" on line 42

but it continues to spit back " Please place your code snippet just before the closing tag on your web page."


r/stackoverflow • • May 28 '19

Reddit or stackoverflow vs quora

2 Upvotes

What is the difference among the three crowd content driven websitea ?


r/stackoverflow • • Apr 22 '19

One of the comments recommended I try r/stackoverflow so I just decided to crosspost my problem here.

Thumbnail
self.visualstudiocode
2 Upvotes

r/stackoverflow • • Apr 13 '19

Why only 1000+ subscriber?

2 Upvotes

Stackoverflow is the most popular site among developers. The irony is that reddit communuty for discussions related to stackoverflow has just 1000+ subscribers. Which to low for any subreddit community . Why? What can be done to remedy this situation?


r/stackoverflow • • Oct 01 '18

Jon Skeet is an AI !!

2 Upvotes

https://youtu.be/QwS1r1mc888

Where is Jon Skeet?

Ans. Jon Skeet is an AI !


r/stackoverflow • • Sep 25 '18

Suggest ways to improve question asking

2 Upvotes

So I've been question banned, and to my knowledge I ask questions following the guidelines pretty well. I'm going to leave a few questions, and I'd like to see if anyone can tell me what about them are negatively received. Of course this could be alleviated by simply commenting when you downvote, but hey.

https://stackoverflow.com/questions/51729303/leading-0-removed-from-argument-in-powershell

https://stackoverflow.com/questions/52397740/momentjs-only-showing-time-on-load

https://stackoverflow.com/questions/52394920/match-input-value-to-json-object-in-array


r/stackoverflow • • Sep 07 '18

Stack Overflow Salary Calculator 2018

2 Upvotes

Stackoverflow gave me a notification about the 2018 salary calculator.

While it is very informative in telling the range of the salaries for a particular role, I am confused how to make sense of their percentile brackets. I read their post about how they are calculating the salaries and the percentile info in that post did not make it clear for me.

Can anyone ELI5 what those 25, 50, 75 percentile brackets mean?


r/stackoverflow • • Sep 03 '18

Absolute beginner, trying to use BQ to find most common words in particular subreddits?

2 Upvotes

Using the data from https://pushshift.io, I am trying to take 10 subreddits (e.g. /r/funny) and find the ten most popular words in these subreddit comments, and then maybe look for some common trends. Later I would also like to find how many upvotes certain comments get.

Can anyone help me with this? If anyone has any tutorials that might help that would be great too.