diff --git a/src/story_tests/create_bibtex.robot b/src/story_tests/create_bibtex.robot index 43d42f5..3b17ca1 100644 --- a/src/story_tests/create_bibtex.robot +++ b/src/story_tests/create_bibtex.robot @@ -9,6 +9,7 @@ When Get BibTeX Is Clicked The Generated BibTeX Is Shown Create Test Citation Author1 Title1 2024 Journal1 Go To Home Page Click Get Bibtex + Sleep 0.25 Wait Until Element Is Visible copy_bibtex_button Page Should Contain author = \{Author1\},\n\ttitle = \{Title1\},\n\tyear = \{2024\},\n\tjournal = \{Journal1\} diff --git a/src/story_tests/edit_citation.robot b/src/story_tests/edit_citation.robot index abe8837..3e913df 100644 --- a/src/story_tests/edit_citation.robot +++ b/src/story_tests/edit_citation.robot @@ -52,7 +52,7 @@ After removing an optional field and closing the edit without updating, the fiel Click Element //button[@name='exit-edit'] Reload Page Click Citation Row 1 - Sleep 0.25 + Sleep 0.5 Page Should Contain volume Page Should Contain 5050 diff --git a/src/tests/generate_citekey_test.py b/src/tests/generate_citekey_test.py index 94fbab9..76a8a94 100644 --- a/src/tests/generate_citekey_test.py +++ b/src/tests/generate_citekey_test.py @@ -22,3 +22,53 @@ def unique(key): key = generate_cite_key(self.fields) expected = "JouTo20" self.assertEqual(expected, key) + + @patch("util.unique_key") + @patch("secrets.token_hex") + def test_generate_cite_key_with_few_fields(self, mock_token_hex, mock_unique_key): + def unique(key): + return key not in ["Jou10", "Jou88"] + + mock_unique_key.side_effect = unique + mock_token_hex.return_value = "abcd" + fields = {"author": "Jo", "year": "2020"} + cite_key = generate_cite_key(fields) + expected = "Jo20abcd" + self.assertEqual(expected, cite_key) + + @patch("util.unique_key") + @patch("secrets.token_hex") + def test_generate_cite_key_with_short_fields(self, mock_token_hex, mock_unique_key): + def unique(key): + return key not in ["Jou10", "Jou88"] + + mock_unique_key.side_effect = unique + mock_token_hex.return_value = "abcd" + fields = {"author": "J", "edition": "5"} + cite_key = generate_cite_key(fields) + self.assertEqual(cite_key, "J5abcd") + + @patch("util.unique_key") + @patch("secrets.token_hex") + def test_generate_cite_key_with_empty_fields(self, mock_token_hex, mock_unique_key): + def unique(key): + return key not in ["Jou10", "Jou88"] + + mock_unique_key.side_effect = unique + mock_token_hex.return_value = "abcd" + fields = {} + cite_key = generate_cite_key(fields) + self.assertEqual(cite_key, "abcd") + + @patch("util.unique_key") + @patch("secrets.token_hex") + def test_generate_cite_key_not_unique_after_generating( + self, mock_token_hex, mock_unique_key + ): + def unique(key): + return key not in ["JouTo20", "Jou88"] + + mock_unique_key.side_effect = unique + mock_token_hex.return_value = "abcd" + cite_key = generate_cite_key(self.fields) + self.assertEqual(cite_key, "JouTo20abcd")