def test_get_first_incomplete_location_in_survey_started_with_repeat(self):
        schema = load_schema_from_params('test', 'navigation')

        completed_blocks = [
            Location('property-details', 0, 'insurance-type'),
            Location('property-details', 0, 'insurance-address'),
            Location('multiple-questions-group', 0, 'household-composition'),
            Location('extra-cover', 1, 'extra-cover-block'),
            Location('repeating-group', 0, 'repeating-block-1'),
            Location('repeating-group', 1, 'repeating-block-1'),
            Location('repeating-group', 0, 'repeating-block-2'),
            Location('repeating-group', 1, 'repeating-block-2'),
            Location('extra-cover', 0, 'extra-cover-block'),
            Location('extra-cover-items-group', 0, 'extra-cover-items'),
            Location('extra-cover-items-group', 0, 'extra-cover-items-radio'),
        ]

        expected_location = Location('extra-cover-items-group', 1, 'extra-cover-items')
        routing_path = [
            Location('multiple-questions-group', 0, 'household-composition'),
            Location('repeating-group', 0, 'repeating-block-1'),
            Location('repeating-group', 1, 'repeating-block-1'),
            Location('repeating-group', 0, 'repeating-block-2'),
            Location('repeating-group', 1, 'repeating-block-2'),
            Location('extra-cover', 0, 'extra-cover-block'),
            Location('extra-cover-items-group', 0, 'extra-cover-items'),
            Location('extra-cover-items-group', 0, 'extra-cover-items-radio'),
            expected_location,
        ]

        answer_store = AnswerStore()
        answer_store.add(Answer(
            answer_instance=0,
            answer_id='first-name',
            value='Person1'
        ))
        answer_store.add(Answer(
            answer_instance=1,
            answer_id='first-name',
            value='Person2'
        ))
        answer_store.add(Answer(
            answer_instance=0,
            answer_id='extra-cover-answer',
            value=2
        ))

        progress = Completeness(
            schema, answer_store, completed_blocks, routing_path, metadata={})

        with patch('app.questionnaire.path_finder.evaluate_goto', return_value=True):
            invalid_location = progress.get_first_incomplete_location_in_survey()
        self.assertEqual(expected_location, invalid_location)
    def test_get_first_incomplete_location_in_survey_not_started(self):
        schema = load_schema_from_params('test', 'navigation_completeness')
        expected_location = Location('coffee-group', 0, 'coffee')
        routing_path = [
            expected_location,
            Location('coffee-group', 0, 'response-yes'),
        ]

        progress = Completeness(
            schema, AnswerStore(), [], routing_path, metadata={})

        invalid_location = progress.get_first_incomplete_location_in_survey()
        self.assertEqual(expected_location, invalid_location)
    def test_get_first_incomplete_location_in_survey_completed(self):
        schema = load_schema_from_params('test', 'navigation')

        # interstitial blocks have been removed
        completed_blocks = [
            Location('property-details', 0, 'insurance-type'),
            Location('property-details', 0, 'insurance-address'),
            Location('house-details', 0, 'house-type'),
            Location('multiple-questions-group', 0, 'household-composition'),
            Location('repeating-group', 0, 'repeating-block-1'),
            Location('repeating-group', 0, 'repeating-block-2'),
            Location('extra-cover', 0, 'extra-cover-block'),
            Location('payment-details', 0, 'credit-card'),
            Location('payment-details', 0, 'expiry-date'),
            Location('payment-details', 0, 'security-code'),
            Location('extra-cover-items-group', 0, 'extra-cover-items'),
            Location('extra-cover-items-group', 0, 'extra-cover-items-radio'),
            Location('skip-payment-group', 0, 'skip-payment'),
        ]

        routing_path = [
            Location('property-details', 0, 'insurance-type'),
            Location('property-details', 0, 'insurance-address'),
            Location('property-details', 0, 'property-interstitial'),
            Location('house-details', 0, 'house-type'),
            Location('multiple-questions-group', 0, 'household-composition'),
            Location('repeating-group', 0, 'repeating-block-1'),
            Location('repeating-group', 0, 'repeating-block-2'),
            Location('extra-cover', 0, 'extra-cover-block'),
            Location('extra-cover', 0, 'extra-cover-interstitial'),
            Location('payment-details', 0, 'credit-card'),
            Location('payment-details', 0, 'expiry-date'),
            Location('payment-details', 0, 'security-code'),
            Location('payment-details', 0, 'security-code-interstitial'),
            Location('extra-cover-items-group', 0, 'extra-cover-items'),
            Location('extra-cover-items-group', 0, 'extra-cover-items-radio'),
            Location('skip-payment-group', 0, 'skip-payment'),
            Location('confirmation-group', 0, 'confirmation'),
        ]
        progress = Completeness(
            schema, AnswerStore(), completed_blocks, routing_path, metadata={})
        with patch('app.questionnaire.path_finder.evaluate_goto', return_value=False):
            self.assertFalse(progress.get_first_incomplete_location_in_survey())