Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unittest to test problems page before contset start #2756

Merged
merged 1 commit into from
Nov 2, 2024

Conversation

as6325400
Copy link
Contributor

issue

#2393

@as6325400 as6325400 changed the title add unittest to test that the problems page does not show page, state… add unittest to test problems page before contset start Oct 24, 2024
$timezone = substr($originalStartTime, $lastSpacePosition + 1);

$date = new \DateTime($datetime, new \DateTimeZone($timezone));
$date->modify('+1 hour');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do this with a Fixture like https://github.com/DOMjudge/domjudge/blob/main/webapp/src/DataFixtures/Test/DemoAboutToStartContestFixture.php? That makes it much easier to see what kind of state this test runs from.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the Fixture yet. Did you push the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've taken care of it. I just misunderstood you.

static::assertSelectorTextContains('.nav-item .nav-link.disabled', 'Problems');
static::assertSelectorTextContains('.alert.alert-secondary', 'No problem texts available at this point.');

$this->client->request('GET', '/team/problems/2/statement');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do a loop here? And I wonder if /team/problems/2 should also throw a 404 as it would disclose the number of problems already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I directly wrote a loop from one to three to test all three problems. Was this necessary, or is there somewhere that reveals the number of problems that I missed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could ask the ContestProblems from the Contest and loop over that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay for me to do this now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its really better to get the problems from the contest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dealt with it

@as6325400 as6325400 force-pushed the unittest_problem_page branch 2 times, most recently from f02f2db to c9fc4a4 Compare October 27, 2024 09:25
@as6325400 as6325400 force-pushed the unittest_problem_page branch 3 times, most recently from c8bfada to ae65428 Compare October 27, 2024 12:28
Comment on lines 5 to 12
use App\Entity\Problem;
use App\Entity\ContestProblem;
use App\Entity\Testcase;
use App\Entity\Contest;
use App\Tests\Unit\BaseTestCase;
use Doctrine\ORM\EntityManagerInterface;
use App\DataFixtures\Test\DemoAboutToStartContestFixture;
use Generator;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We sort here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 198 to 206
$em = self::getContainer()->get(EntityManagerInterface::class);
$problemCount = $em->createQueryBuilder()
->from(ContestProblem::class, 'cp')
->select('COUNT(cp.contest)')
->where('cp.contest = :contest')
->setParameter('contest', 1)
->getQuery()
->getSingleScalarResult();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get the contest by its name, not by the internal number which can change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

static::assertSelectorTextContains('.nav-item .nav-link.disabled', 'Problems');
static::assertSelectorTextContains('.alert.alert-secondary', 'No problem texts available at this point.');

for ($i = 1; $i <= $problemCount; $i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't hardcode the $i here as I think we use the global problemId and not the index in the contest, so when there are multiple problems in the database we might pick the wrong one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use contest_id to fetch pid from the problem.

Copy link
Member

@vmcj vmcj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if the rest has opinions and otherwise I'll merge next week.

@vmcj vmcj added this pull request to the merge queue Nov 2, 2024
Merged via the queue into DOMjudge:main with commit a829a31 Nov 2, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants