import { InMemoryStorage } from '../infrastructure/memory_storage' ; import { Surveys } from '../model/survey' ; import { OutlineSurveys } from './survey' ; describe ( 'Surveys' , ( ) => { it ( 'presents data limits surveys with the correct arguments' , async ( done ) => { const view = new FakeSurveyDialog ( ) ; const storage = new InMemoryStorage ( ) ; const surveys = new OutlineSurveys ( view , storage , 0 ) ; await surveys . presentDataLimitsEnabledSurvey ( ) ; expect ( view . title ) . toEqual ( 'survey-data-limits-title' ) ; expect ( view . surveyLink ) . toEqual ( 'https://docs.google.com/forms/d/e/1FAIpQLSeXQ5WUHXQHlF1Ul_ViX52GjTUPlrRB_7rhwbol3dKJfM4Kiw/viewform' ) ; await surveys . presentDataLimitsDisabledSurvey ( ) ; expect ( view . title ) . toEqual ( 'survey-data-limits-title' ) ; expect ( view . surveyLink ) . toEqual ( 'https://docs.google.com/forms/d/e/1FAIpQLSc2ZNx0C1a-alFlXLxhJ8jWk-WgcxqKilFoQ5ToI8HBOK9qRA/viewform' ) ; done ( ) ; } ) ; it ( 'presents data limits surveys after the default prompt impression delay' , async ( done ) => { const TEST_PROMPT_IMPRESSION_DELAY_MS = 750 ; const view = new FakeSurveyDialog ( ) ; const storage = new InMemoryStorage ( ) ; const surveys = new OutlineSurveys ( view , storage , TEST_PROMPT_IMPRESSION_DELAY_MS ) ; let start = Date . now ( ) ; await surveys . presentDataLimitsEnabledSurvey ( ) ; let delay = Date . now ( ) - start ; expect ( delay ) . toBeGreaterThanOrEqual ( TEST_PROMPT_IMPRESSION_DELAY_MS ) ; start = Date . now ( ) ; await surveys . presentDataLimitsDisabledSurvey ( ) ; delay = Date . now ( ) - start ; expect ( delay ) . toBeGreaterThanOrEqual ( TEST_PROMPT_IMPRESSION_DELAY_MS ) ; done ( ) ; } ) ; it ( 'presents data limits surveys once' , async ( done ) => { const view = new FakeSurveyDialog ( ) ; const storage = new InMemoryStorage ( ) ; const surveys = new OutlineSurveys ( view , storage , 0 ) ; await surveys . presentDataLimitsEnabledSurvey ( ) ; expect ( storage . getItem ( 'dataLimitsEnabledSurvey' ) ) . toEqual ( 'true' ) ; await surveys . presentDataLimitsDisabledSurvey ( ) ; expect ( storage . getItem ( 'dataLimitsDisabledSurvey' ) ) . toEqual ( 'true' ) ; spyOn ( view , 'open' ) ; await surveys . presentDataLimitsEnabledSurvey ( ) ; expect ( view . open ) . not . toHaveBeenCalled ( ) ; await surveys . presentDataLimitsDisabledSurvey ( ) ; expect ( view . open ) . not . toHaveBeenCalled ( ) ; done ( ) ; } ) ; it ( 'does not present data limits surveys after availability date' , async ( done ) => { const view = new FakeSurveyDialog ( ) ; const storage = new InMemoryStorage ( ) ; const yesterday = new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) - 1 ) ) ; const surveys = new OutlineSurveys ( view , storage , 0 , yesterday ) ; spyOn ( view , 'open' ) ; await surveys . presentDataLimitsEnabledSurvey ( ) ; expect ( view . open ) . not . toHaveBeenCalled ( ) ; await surveys . presentDataLimitsDisabledSurvey ( ) ; expect ( view . open ) . not . toHaveBeenCalled ( ) ; done ( ) ; } ) ; } ) ; class FakeSurveyDialog implements polymer . Base { title : string ; surveyLink : string ; is : 'fake-survey-dialog' ; localize ( messageId ) { return messageId ; } open ( title , surveyLink ) { this . title = title ; this . surveyLink = surveyLink ; } }