from nose.tools import assert_equal, assert_true
from ...helpers import BaseApplicationTest


class TestApplication(BaseApplicationTest):
    def setup(self):
        super(TestApplication, self).setup()

    def test_analytics_code_should_be_in_javascript(self):
        res = self.client.get('/static/javascripts/application.js')
        assert_equal(200, res.status_code)
        assert_true(
            'GOVUK.analytics.trackPageview'
            in res.get_data(as_text=True))

from nose.tools import assert_equal, assert_true
from ...helpers import BaseApplicationTest


class TestApplication(BaseApplicationTest):
    def setup(self):
        super(TestApplication, self).setup()

    def test_analytics_code_should_be_in_javascript(self):
        res = self.client.get('/static/javascripts/application.js')
        assert_equal(200, res.status_code)
        assert_true(
            'trackPageview'
            in res.get_data(as_text=True))

Test for presence of analytics in minified JS
Test for presence of analytics in minified JS

Minifying the JS shortens variable names wherever their scope makes it possible.
This means that `GOVUK.analytics.trackPageView` gets shortened to something like
`e.t.trackPageView`, and not in a predicatable way. Because the `trackPageView`
method could be used by indeterminable other scripts the compiler can't minify
it, so testing for just the presence of its name is safe.

  from nose.tools import assert_equal, assert_true
  from ...helpers import BaseApplicationTest
  
  
  class TestApplication(BaseApplicationTest):
      def setup(self):
          super(TestApplication, self).setup()
  
      def test_analytics_code_should_be_in_javascript(self):
          res = self.client.get('/static/javascripts/application.js')
          assert_equal(200, res.status_code)
          assert_true(
-             'GOVUK.analytics.trackPageview'
+             'trackPageview'
              in res.get_data(as_text=True))
  
Test for presence of analytics in minified JS
## Code Before:
from nose.tools import assert_equal, assert_true
from ...helpers import BaseApplicationTest


class TestApplication(BaseApplicationTest):
    def setup(self):
        super(TestApplication, self).setup()

    def test_analytics_code_should_be_in_javascript(self):
        res = self.client.get('/static/javascripts/application.js')
        assert_equal(200, res.status_code)
        assert_true(
            'GOVUK.analytics.trackPageview'
            in res.get_data(as_text=True))

## Instruction:
Test for presence of analytics in minified JS
## Code After:
from nose.tools import assert_equal, assert_true
from ...helpers import BaseApplicationTest


class TestApplication(BaseApplicationTest):
    def setup(self):
        super(TestApplication, self).setup()

    def test_analytics_code_should_be_in_javascript(self):
        res = self.client.get('/static/javascripts/application.js')
        assert_equal(200, res.status_code)
        assert_true(
            'trackPageview'
            in res.get_data(as_text=True))
