# Copyright 2022 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

from .image import Image
from .on_click import OnClick, OpenLink


class ImageTest(unittest.TestCase):
  def test_image_url_only(self) -> None:
    i = Image(
        image_url='https://www.karentaylorart.com/wp-content/uploads/2021/01/go_small.jpg')

    self.assertEqual(i._widget_tag, 'image')
    self.assertEqual(i.image_url,
                     'https://www.karentaylorart.com/wp-content/uploads/2021/01/go_small.jpg')
    self.assertIsNone(i.on_click)
    self.assertDictEqual({
        'imageUrl':
        'https://www.karentaylorart.com/wp-content/uploads/2021/01/go_small.jpg',
    },
        i.to_dict())

  def test_image_url_with_on_click(self) -> None:
    i = Image(
        image_url='https://www.karentaylorart.com/wp-content/uploads/2021/01/go_small.jpg')

    on_click = OnClick(open_link=OpenLink(url='https://www.karentaylorart.com'))
    i.on_click = on_click

    self.assertEqual(i.image_url,
                     'https://www.karentaylorart.com/wp-content/uploads/2021/01/go_small.jpg')
    self.assertEqual(i.on_click, on_click)
    self.assertEqual(
        i.to_dict(),
        {'imageUrl':
         'https://www.karentaylorart.com/wp-content/uploads/2021/01/go_small.jpg',
         'onClick': {'openLink': {'url': 'https://www.karentaylorart.com'}}})
